Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Installing AMP stack on Ubuntu Server 18.04.2

  • April 18, 2019
  • 13 min read
Mikhail is IT engineer focusing on applications and infrastructure support domains. He works closely with K2 platform and Microsoft technology stack and holds number of certifications from these software vendors.
Mikhail is IT engineer focusing on applications and infrastructure support domains. He works closely with K2 platform and Microsoft technology stack and holds number of certifications from these software vendors.

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:

update package manager, for that we just open Terminal

Once you clicked on Applications button you can either type in “Terminal” or scroll down to 2nd page and click on Terminal icon:

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:

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:

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:

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:

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:

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):

Type Y and hit Enter to continue

Once this process completes Apache is completely installed and started up. We can test this by typing in http://localhost into browser address bar:

test http://localhost

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:

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:

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:

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:

To edit this file, we can use nano editor like that

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:

 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:

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):

 install PHP by typing in sudo apt-get install php

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:

quick check to confirm that PHP is up and running

Into that file we just adding one-line PHP script which will output PHP version and PHP configuration information for us:

output PHP version and PHP configuration information

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:

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:

 proceed with MySQL 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:

2) Use SQL query to set password you want (I’m using “P@ssw0rd” in example below):

Here you have sample screenshot illustrating execution of these steps:

After MySQL 5.7 installation completes, we need to set root password – for that you can follow 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:

install MySQL Workbench

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 MySQL Workbench started, we can try to connect to MySQL instance typing in password we configured earlier

Once correct password provided you will be connected to your instance and will be able to work with it through MySQL Workbench UI:

correct password provided you will be connected to your instance

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):

phpMyAdmin – very popular MySQL administration tool written primarily in PHP

Accept use of Apache as a web server:

Accept use of Apache as a web server

Further on you will need to accept configuring phpmyadmin database with dbconfig-common:

 you will need to accept configuring phpmyadmin database with dbconfig-common

And next you will need to specify your database password and confirm it:

edit apache2.conf using nano editor

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:

restart Apache using sudo systemctl restart apache2 command

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:

ocalhost/phpmyadmin

 

Type in your root password and you will be presented with (probably quite familiar to you) phpMyAdmin UI:

Type in your root password and you will be presented with 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.

Found Mikhail’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!