How To Install Linux, Apache, MariaDB, PHP (LAMP Stack) on Ubuntu 18.04
LAMP stack (Linux, Apache, MySQL, and PHP) is the widely used stack to host a simple to large websites. If you think the above combination will only be installed on servers where the hosting is made, then that is wrong you can setup LAMP stamp on your PC which has Linux.
The installation procedure of the LAMP stack on Ubuntu is quite simple when compared to other Linux environment.
In other Linux environment, you need to install packages separately, one by one. But in Ubuntu, you can install the whole stack in the single command.
Here, we will see both ways of installing LAMP stack on Ubuntu 18.04.
- Install LAMP stack on Ubuntu 18.04 – Single Command
- Install LAMP stack on Ubuntu 18.04 – Manual (One by one)
Install Linux
Here is the guide about the Step by Step installation of Ubuntu 18.04 and Upgrading Ubuntu 16.04 LTS to Ubuntu 18.04 LTS.
Install LAMP Stack on Ubuntu 18.04 – Manual (One by one)
Now, we will proceed to install AMP (Apache version 2.4, PHP version 7.2, MariaDB version 10.1) on Ubuntu 18.04.
Install Apache HTTP server
Update the package repository index.
sudo apt update
Install apache2 package using the apt command.
sudo apt -y install apache2
Testing Apache HTTP server:
We will now test the Apache web server to confirm whether it is working correctly. Open up any web browser and then navigate it to the following URL.
OR
You will get the “Apache2 Ubuntu Default Page“, and this default page confirms you that the Apache HTTP server is working fine.

Apache web server’s default document root is /var/www/html/ on Ubuntu and the main configuration file is /etc/apache2/apache2.conf. Additional configuration files can be found in the /etc/apache2/*.enabled directory.
The directory hierarchy as follows.
/etc/apache2/ |-- apache2.conf | `-- ports.conf |-- mods-enabled | |-- *.load | `-- *.conf |-- conf-enabled | `-- *.conf `-- sites-enabled `-- *.conf
Install MariaDB Server
MariaDB has replaced MySQL as a default database server in Linux distribution. To install MariaDB, run the following command
sudo apt -y install mariadb-server
Install PHP
By default Apache server supports the .html only, not PHP. To get a PHP supprt, you would need to install PHP and the PHP extension package for MariaDB.
Here, we will install PHP 7.2 on Ubuntu 18.04.
sudo apt -y install php php-mysql
Restart the Apache HTTP server after the installation of the PHP package.
sudo systemctl restart apache2
Now, skip to Testing LAMP Stack.
Install LAMP Stack on Ubuntu 18.04 – Single Command
Now, we will proceed to install AMP (Apache version 2.4, PHP version 7.2, MySQL 5.7) on Ubuntu 18.04.
Update the repository cache using the apt command.
sudo apt update
Paste below the line in the terminal and hit enter.
sudo apt install lamp-server^
The above command will search and install the required packages for LAMP server. You should see messages something like below.

Wait for 10 to 15 minutes to let the installation LAMP stack complete. Then, check the status of the Apache and MySQL service.
Apache:
sudo systemctl status apache2
Output:
● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Tue 2018-07-13 23:58:21 IST; 23min ago Docs: man:systemd-sysv-generator(8) Process: 5823 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS) Process: 5845 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS) CGroup: /system.slice/apache2.service ├─5862 /usr/sbin/apache2 -k start ├─5865 /usr/sbin/apache2 -k start ├─5866 /usr/sbin/apache2 -k start ├─5867 /usr/sbin/apache2 -k start ├─5868 /usr/sbin/apache2 -k start ├─5869 /usr/sbin/apache2 -k start └─5889 /usr/sbin/apache2 -k start Jul 23 13:58:20 server.itzgeek.local systemd[1]: Stopped LSB: Apache2 web server. Jul 23 13:58:20 server.itzgeek.local systemd[1]: Starting LSB: Apache2 web server... Jul 23 13:58:20 server.itzgeek.local apache2[5845]: * Starting Apache httpd web server apache2 Jul 23 13:58:21 server.itzgeek.local apache2[5845]: * Jul 23 13:58:21 server.itzgeek.local systemd[1]: Started LSB: Apache2 web server.
MySQL:
sudo systemctl status mysql
Output:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2018-07-23 14:17:20 IST; 4min 11s ago Process: 6184 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/ Process: 6175 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SU Main PID: 6183 (mysqld) CGroup: /system.slice/mysql.service └─6183 /usr/sbin/mysqld Jul 23 14:17:19 server.itzgeek.local systemd[1]: Stopped MySQL Community Server. Jul 23 14:17:19 server.itzgeek.local systemd[1]: Starting MySQL Community Server... Jul 23 14:17:20 server.itzgeek.local systemd[1]: Started MySQL Community Server.
Test Apache
Before testing Apache, restart the Apache service.
sudo systemctl restart apache2
Open up any web browser and then go to the following web address.
OR
You should get the following page, and this confirms that Apache web server is working fine.

Apache’s default document root is /var/www/html on Ubuntu, and the main configuration file is /etc/apache2/apache2.conf.
Additional configurations like Virtual hosts and modules can be found in /etc/apache2/*-enabled directory
Test LAMP Stack
For testing the PHP, we will place one PHP file on to the default document root of Apache.
sudo nano /var/www/html/info.php
Paste the below line into the info file:
<?php phpinfo(); ?>
Now open a web browser and type the following into the web address:
OR
The page will look like below.

Scroll the page down to see the PHP extensions information including MySQL.

That’s All.