This tutorial will walk you through the process of how to setup LAMP stack, which includes the set up of the components such as Apache 2, PHP , MySql 5 on Debian 8 Jessie.

This comprehensive linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has sudo access and that you precede each of the privileged commands with sudo

Install Apache

In this particular guide, we will show how Apache2 is configured. First Apache server will be setup and installed.

apt-get update
apt-get install apache2
service apache2 start 

/etc/apache2/apache2.conf 

This is the location of the apache file.

If the ufw firewall is running, we will need to allow the port 80 to take traffic. We can enable this port by following command.

ufw allow in “WWW Full”

first, quickly test that apache web server if it is setup and running fine by accessing http://localhost

Note: The local ip address of the ubuntu machine can replace localhost

Install MySQL or MariaDB

There is an option in between installing MySQL or MariaDB, which can be seen as a drop in replacement for MySQL. in MariaDB there all the enterprise features present but without all the corporate structuring.It is managed by the MariaDB Foundation as opposed to being managed by Oracle which manages MySQL. That said, they are both good choices.

Don’t install both, only one needs to be installed.

Install MySQL

After this, it is time to install MySQL 5.7. For this, both the server and client are needed. The database is run by the server while the interaction with the server is done by the client.

apt-get install -y mysql-server mysql-client php5-mysql

We will be asked to enter the password for the MySQL root account, since
we haven’t set this yet, so just hit ENTER . Then we will be asked to set that password. we should type Y to set a root password.

To rest of all the questions, the script asks, you should press Y, followed by the ENTER key at each prompt. During this process we will remove anonymous users and the test database, disable remote root logins, and load these new rules MySQL.

mysql_secure_installation

Install MariaDB

Since MariaDB is also an option, as mentioned earlier, and this means it can be installed just like MySql without any further steps. We will be installing MariaDB

But we need to set up repository for installing MariaDB, since MariaDB is not native in Debian 8 Jessie.

apt-get install software-properties-common dirmngr

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db

add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.zol.co.zw/mariadb/repo/10.3/debian jessie main'
apt-get install -y mariadb-server mariadb-client

Similar to MySQL server, a server needs to be setup as well.

mysql_secure_installation

Install PHP

Now to generate dynamic content, we need to install PHP ,
we will be installing the following modules.

 apt-get install php5 php-pear php5-mysql

we need to create a test PHP file in our document root. We will create a codesposts.php file in the document root to test our configuration

vi /var/www/html/codesposts.php
/var/www/html/codesposts.php
<?php phpinfo(); ?>      

After pasting the above code to our codesposts.php file, save and close the file.

Restart the httpd service and we can visit this web page in a web browser from the below shown URL.

service apache2 restart
http://<Your_serverIP>/codesposts.php

we should see a web page that has been generated by PHP with information about your server. We have successfully completed the installation process of LAMP stack on Debian 8.

Thanks for being with us, hope this help you in gaining knowledge and we are always ready to help you. For furthers queries or suggestions, kindly drop a comment below.