Install a LAMP server with PHP 7 and Apache 2.4 on Ubuntu

What is a LAMP server?

LAMP server is probably the best known server installation, as it is set up with with Linux, Apache, MySQL and PHP – the ideal starting situation for the most widespread CMS systems, such as WordPressDrupal or Typo3.

Before you can start the installation, you have to create a cloud server with Ubuntu 16.04.

First you create a server with at least one public IP address and usually 2 CPUs and 4 GB of RAM (our recommendation). We are using the gridscale environment to demonstrate.

gridscale Server erstellen

Parallel to this, you create another storage. You should set the size here so that your project has enough space. But in case you need more space later, gridscale lets you adjust the size of the hard drive at any time.

gridscale Storage erstellen

As a template you select our gridscale Ubuntu 16.04 template. Here you can optionally assign a root password or use an SSH key. Once you have made your settings, you can create the storage and connect it directly to the server using drag & drop.

gridscale Dashboard

Updating the Ubuntu Server

Your server should start within a few seconds. You can connect to the server via SSH and, if you have a password, log in as root:

ssh root@185.102.XX.XXX

Make sure that all installed packages are updated and upgraded with:

apt-get update
apt-get upgrade

Installing an Apache Web Server

First we install the web server. We can also do this with a command:

apt-get -y install apache2

The -y stands for confirming all options directly, since we want a standard installation.

Once the installation is finished after a few seconds / minutes, you can test it directly by entering the IP address of the server in the browser.

Installing a MariaDB Database

Instead of MySQL, we install MariaDB in this guide. MariaDB is a MySQL-Fork managed by the original MySQL developer team, which is compatible with MySQL and has some interesting new features.

The server and client can be installed using the following commands:

apt-get -y install mariadb-server mariadb-client

As soon as the installation is finished, we should directly assign a root password for the database and make a few security settings. You can do this with the following command:


You are now asked a few questions. It starts with the password and ends with the question, if you want to load the currently used settings directly. Here are our answers to the individual questions:

Enter current password for root (enter for none): <== Your Root Password
Set root password? [Y/n] <== y (yes)
New password: <== Here you have to enter your new password
Re-enter new password: <== Confirm Password
Remove anonymous users? [Y/n] <== Yes, delete
Disallow root login remotely? [Y/n] <==Yes, prohibit
Remove test database and access to it? [Y/n] <== Yes, we do not need the test table
Reload privilege tables now? [Y/n] <== Yes, reload

If you want to test briefly whether everything has worked out, you can do this with the following command:

mysql -u root -p

With exit you can leave the MySQL client again

Installing PHP 7

You can also install PHP 7 with the command:

apt-get -y install php7.0 libapache2-mod-php7.0

Now restart the web server and then everything should work:

systemctl restart apache2

However, in order to check whether PHP 7 is actually installed and working, create an info.php file and display the current PHP settings.

To do this, go to the Apache Standard Web Root folder:

cd /var/www/html/
nano info.php

Write the following in the info.php file:

<?php phpinfo(); ?>

Use Ctrl + X to save and close the file.

If you now add /info.php to our IP address in the browser, you can see if PHP 7 has been installed and if everything has worked out.

PHP installed

What is still missing is the MariaDB / MySQL package for PHP. We can also install this with a command:

apt-get -y install php7.0-mysql

When the installation is finished, you should restart the web server again:

systemctl restart apache2

Now the MySQL package should also appear in the info.php file. Search for„mysql“ in the /info.php page.

Finished! Wasn’t that a quick LAMP server install? 🙂

PS: If you often use LAMP servers, at gridscale you can save the installation as a template by first creating a snapshot from the storage and then converting it to a template.

gridscale create Snapshot