Initially my intention was to cover installation of MySQL only, but with phpMyAdmin being most popular MySQL administration tool, and overall interconnectedness between all the components of AMP (Apache, MySQL, and PHP) stack, I’ve realized that we normally need to install entire AMP stack in most of the cases and I’d better cover installation of all components. This article intended to give step by step walkthrough of installing Apache, PHP and MySQL on Ubuntu Server 18.04.2 (current LTS release). I will also cover installation of MySQL Workbench and phpMyAdmin. I will be using Ubuntu Server with GUI installed (you can read up about setting up Hyper-V VM with Ubuntu Server 18.04.2 in blog post I’ve wrote earlier).
Let’s start with Apache. To install Apache on Ubuntu we will be using package manager. We first need update package manager, for that we just open Terminal, like that:
Once you clicked on Applications button you can either type in “Terminal” or scroll down to 2nd page and click on Terminal icon:
Once Terminal window opened you can add its icon to favorites for quick access:
We now can update package manager starting our command from sudo (which stands for super user do) and typing apt-get update:
You will get password prompt and once password is typed correctly package lists update process will be started:
Once it completes, we have an up-to-date list of available packages for our Ubuntu installation. We can now start Apache installation by means of typing in sudo apt-get install apache2:
Installation process will first build a list of everything that needs to be installed and inform you about additional disk space required to install Apache:
Type Y and hit Enter to continue. For me entire process took about 1 minute to complete (your timing can vary):
Once this process completes Apache is completely installed and started up. We can test this by typing in http://localhost into browser address bar:
You will see Apache default page which demonstrates that Apache is installed and running. To stop and start Apache you can use sudo apachectl stop and sudo apachectl start commands respectively:
We can adjust Apache configuration files by locating them under root/etc/apache2 with apache2.conf being primary configuration file:
You can easily open apache2.cong in gedit to view it in read-only mode by simply double-clicking on it:
To edit this file, we can use nano editor like that:
For example, you can add ServerName setting to the very end of that file to suppress warning AH00558 on Apache service stop operation:
Another important file/directory to be aware of is /var/www/html where you can find default Apache index.html file:
Now when we have Apache installed, lets move on to PHP Installation.
PHP installation. We can install PHP by typing in sudo apt-get install php, but we also need to include additional modules to connect Apache to PHP and MySQL so we will also specify those modules (libapache2-mod-php, mcry, php-mysql):
Type in command as shown above, enter your password and hit enter after reviewing packages list and drive space requirements. Once installation completes we can do a quick check to confirm that PHP is up and running. For that we can create test PHP script in our Apache web root directoty like that:
Into that file we just adding one-line PHP script which will output PHP version and PHP configuration information for us:
Once this file is saved just navigate to http://localhost/phptest.php in your browser to see script output – if that works for you, it means that PHP was successfully installed and running. Here is an example of how this script output looks like:
We can now proceed with MySQL installation. Once again, we start this process opening Terminal and typing in sudo apt-get install mysql-server, you will be prompted for password, and once packages list is built you will need to confirm installation:
After MySQL 5.7 installation completes, we need to set root password – for that you can follow these steps:
1) Connect to MySQL from Terminal by means of typing in the following command:
1 2 3 |
sudo mysql -u root -p Use blanc password to connect. |
2) Use SQL query to set password you want (I’m using “P@ssw0rd” in example below):
1 |
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'P@ssw0rd'; |
Here you have sample screenshot illustrating execution of these steps:
From this moment on you can connect to MySQL only specifying password you configured.
As promised in the beginning of this article, we will also cover MySQL Workbench and phpMyAdmin installation.
Let’s install MySQL Workbench first. MySQL Workbench is analog of SSMS for those who comes from Microsoft SQL Server world 😊 or, employing other terminology, graphical IDE for MySQL. To install MySQL Workbench we type in sudo apt-get install mysql-workbench in Terminal window:
As usual we confirm that we want to proceed with installation once packages list is built, and after installation completes, we can run MySQL Workbench by typing in mysql-workbench in the same Terminal window or locating its icon amongst Installed Applications in GUI. Once MySQL Workbench started, we can try to connect to MySQL instance typing in password we configured earlier (you can save it so that you don’t need to enter it all the time):
Once correct password provided you will be connected to your instance and will be able to work with it through MySQL Workbench UI:
phpMyAdmin installation. One last component installation of which I want to cover here is phpMyAdmin – very popular MySQL administration tool written primarily in PHP. To install it we once again switch into terminal to type in sudo apt-get install phpmyadmin (alternatively you can specify -y key to suppress confirmation promt like that: sudo apt-get install -y phpmyadmin):
Accept use of Apache as a web server:
Further on you will need to accept configuring phpmyadmin database with dbconfig-common:
And next you will need to specify your database password and confirm it:
Once installation completes you need to edit apache2.conf using nano editor (the same way as it was shown in the beginning of this article) and add Include /etc/phpmyadmin/apache.conf in the end of this file as shown below:
Once you edited and saved this file, restart Apache using sudo systemctl restart apache2 command. After performing these steps, you should be able to navigate to http://localhost/phpmyadmin and see its logon page:
Type in your root password and you will be presented with (probably quite familiar to you) phpMyAdmin UI:
This concludes my LAMP stack installation walkthrough. Of course, there is much more things to configure and adjust in terms of security settings and customization, and you may also encounter some unique glitches and errors during your installation process (feel free to ask about those in comments section below), but purpose of this blog post was to cover basic installation process of all LAMP stack components on Ubuntu server 18.04 which we covered completely.