A LAMP Stack is a group of open-source software commonly used for hosting dynamic websites and web apps. LAMP is an acronym for Linux operating system, Apache web server, MySQL (or MariaDB relational database management system) and PHP.

This guide shows you how to install a LAMP stack on a Debian 9.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Note: The user you are logged in as must have sudo privileges to be able to install packages.

Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:

sudo apt-get update && sudo apt-get upgrade

Step 1: Install Apache
Apache is available in the Debian repositories by default, hence the installation is quite straightforward. Issue the command below:

sudo apt install apache2

Cloudwafer-Debian-Apache-1

To start the Apache service, issue the following commands below:

sudo systemctl start apache2

To check the Apache service run time status information, issue the following command.

sudo systemctl status apache2

Cloudwafer-Debian-Apache-1a

Cloudwafer-Debian-Apache-1b

Step 2: Install MariaDB
The next step is to install the MariaDB packages. MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. Issue the command below to install MariaDB:

sudo apt install mariadb-server

Cloudwafer-Debian-Apache-2

After installation, issue the command below to check the status of our MariaDB installation:

sudo systemctl status mariadb

Cloudwafer-Debian-Apache-3

Our MySQL database is now running so the next thing to do is to run a simple security script that will remove some dangerous defaults and lock down some default access to our database system. Start the script by issuing the command below:

sudo mysql_secure_installation

The script will ask a couple of questions including:

  • Current root password – Since this is a new installation of MySQL, you probably don’t have one so you can leave it blank and you will be asked if you want to set one. Type Y and proceed.
  • Remove anonymous users - Type Y or press the enter button to choose the default (which is Y).
  • Disable root login remotely - Type Y or press the enter button to choose the default (which is Y).
  • Remove test database - Type Y or press the enter button to choose the default (which is Y)
  • Reload privilege tables - Type Y or press the enter button to choose the default (which is Y)

Cloudwafer-Debian-Apache-4

Cloudwafer-Debian-Apache-5

At this point, our database system is now set up and we can move on to the next step in our installation.

Step 3: Install PHP
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. In this case, it will run scripts, connect to our MariaDB databases for information, and deliver processed content over to our web server to display. Debian 9 ships with PHP 7.0. To install PHP and most common PHP modules use the following command:

sudo apt install php libapache2-mod-php php-opcache php-cli php-gd php-curl php-mysql

Cloudwafer-Debian-Apache-6

After installation of PHP on the server, type the following command in order to see the current release version of PHP.

php -v

Cloudwafer-Debian-Apache-7

Once the PHP packages are installed restart the Apache service with:

sudo systemctl restart apache2

Step 4 – Test PHP Processing
To test our newly configured system properly for PHP, we can run a very basic PHP script called info.php. This file must be saved to the webroot directory (/var/www/html/) in order for Apache to find the file and serve it correctly. The command below will open a blank file where we will type the PHP code.

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

On opening the blank file, copy and paste the code below:

<?php 
phpinfo(); 
?>

Cloudwafer-Debian-Apache-8

Ensure to save the file before closing.

Restart the Apache service with:

sudo systemctl restart apache2

Visit your server's IP address or domain name followed by a forward slash and info.php on a browser. In this guide, we are using debian.cloudwaferlabs.com.ng/info.php. If everything works correctly, something similar to the below image should be shown:

Cloudwafer-Debian-Apache-9

Note: It is advisable to delete this info.php file as it contains vital information about your server that can be viewed by anyone on the web. You can do that with this command:

sudo rm /var/www/html/info.php