How to install PHP, Apache and MySQL on Ubuntu

This article will show you step by step how to install PHP, Apache, and Mysql on your Ubuntu machine.

In this demonstration, I will be installing everything on my VM that has Ubuntu installed. These steps should work for any version of Ubuntu.

Ubuntu Background

While most of the Linux systems look scary at a first glance, Ubuntu manages to offer a good, if not great, user experience overall. Allowing users from any background to quickly understand how it works. That’s mostly because of the UI.

The UI (user interface) is user-friendly, allowing any user to just click on icons or press a key to perform an action, very similar to Windows and MacOS.

Ubuntu is great as an operating system for very low-level machines. It can be installed on anything and will work just fine on every old computer that only has some storage and a few hundred megabytes.

Ubuntu is really easy to use by running commands in the terminal.


sudo (superuser do) – this allows you to run a command as the root user. The root user has all the privileges in the system and is allowed to basically do whatever he wants.  When running a command using sudo, the terminal will ask for your password.

sudo apt-get update

cd (changing directory) – this is one of the commands that gets used a lot. You will see that it’s just easier to go from one directory/folder to another using cd in the terminal.

/home $ cd myproject

/home/myproject $

mkdir (make new directory) – whenever you need to create a new directory/folder just use this command

mkdir folderName

apt-get (Advanced Packaging Tool (APT) package manager) – a powerful command that can perform installations, upgrades or remove your software. Just run apt-get in the terminal and a list with commands will show up.

apt-get [command]

rm (remove) – this can remove a file or even a directory. You can force a removal by doing rm -f. Always be careful before using rm -f.

rm nameofthefile.something

ls (list) – will list all the files and directories

/myprojectdirectory ls

Good references:


Install PHP

  1. Make sure your package manager is up to date:
    • sudo apt-get update -y
  2. Installing PHP:
    • sudo apt-get install php -y
  3. Install the common/the ones you want extensions:
    • sudo apt-get install -y php-{bcmath,bz2,intl,gd,mbstring,mcrypt,mysql,zip} && sudo apt-get install libapache2-mod-php
  4. Check that the installation worked correctly by running php -v. This will show you the version of the PHP installed and some other informations.
PHP -V Output
PHP -V Output


Install Apache

  1. Installing Apache:
    • sudo apt-get install apache2 -y
  2. Start Apache:
    • sudo systemctl start apache2.service
  3. Check if Apache was installed correctly without errors and it works.
    1. Run the following command to see your hostname:
      • hostname -i
    2. Open your browser and go to http://yourhostname/. A page should load with the title “Apache2 Ubuntu Default Page
Apache Works
Apache Works

HOW TO: install PHP 7.2 on Windows

Install MySQL

  1. Installing MySQL
    • sudo apt-get install mysql-server -y
  2. Running that command will trigger the terminal to ask you for the root password first, then will ask you to set a password for the MySQL root user. Remember this password as you will need to use it in the future. Also, press Y (Yes) for any other questions in the terminal.
  3. Optionally, you can run sudo service mysql status to check if mysql is installed.
Check if mysql installed output
Check if mysql installed output



In conclusion, that’s all you need to do to install PHP, Apache and MySQL. You are now able to start working a PHP project that is connected to a database.

As always, if you have any questions I will answer them in the comments sections.


You might also be interested in:

How to install Ubuntu on VirtualBox

Top 3 free coding editors

Guide To Student Life in Manchester

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.