LAMP stack on Debian 9 Distro: A LAMP stack is a group of open source software and typically combined to run a dynamically as a web app or website. The LAMP is a acronym of Linux, Apache, Maria DB & PHP. Linux is an Operating System, Apache is the Web Server, MariaDB is the Database & PHP is the programming language and the dynamic content is processed by PHP. In this article, we are going to provide the information about installing LAMP stack in Debian 9 Distros.
- Installing Apache Web Server
- Installing MariaDB
- Installing PHP
- Testing the PHP processing
In order to complete the steps and you need a Debian 9 server with sudo enabled user account. We suggest you use the DigitalOcean server to create Debian 9 server block.
Installing Apache Web Server:
The Apache server is the most commonly used server in the world. It is highly secured and having many documentations and so it is the best choice for using as the web server for your web app or dynamic content.
You can install the Apache Server using Debian APT Package:
The above command will update your packages to the current system.
The above command will install the Apache web server, You need to execute this command with sudo and so the command will execute with root user privileges. Enter your password and complete the installation.
Once the installation process initiated, you will be asked to execute the installation process, Enter “Y” & hit the Enter button and the installation process will be resumed.
Assign Incoming & Outgoing Request to Apache Server:
Once the installation process got completed, you need to assign the Incoming & Outgoing request to the Apache server. The Apache will process the request and send it to your host. Now the host processes the request and sends the output to the Apache, The Apache server will process the request from the host and send the request to the client.
If you want to know detailed information about reset firewall of Apache Server.
We need to enable the UFW firewall, make sure that your firewall allows HTTP and HTTPS traffic. To view all the application profiles of UFW list installed in the Debian 9.
The following output will appear on the screen.
If you inspect the “WWW Full” application shows that the command enables traffic to the port 80 and port 443
You will receive the following output,
If you want to allow all the incoming and outgoing traffic to your web server and then follow the below command.
The above command will allow all the incoming and outgoing traffic to your server. It means that you can access the Debian server through its IP Address.
Replace your IP address of the server and enter your IP address in any browser. You will see the Debian 9 Apache web page.
If you see the above page, Then you have done correctly and we can move to the next steps.
Installing MariaDB Database:
Now you have your web server up and running and now it is the time to install the Database. In this article, We are going to show the installation methods of the MariaDB database with your server. MariaDB is a community-built fork of MySQL. In Debian 9, the Default MySQL server is the MariaDB 10.1 version. You can install the MariaDB through the mysql-server package, but it is recommended to install the MariaDB through its official package “mariadb-server“.
The above command will start the installation process of the MariaDB in your server. Enter “Y” to confirm and resume the installation process. When the installation process completed you need to run a security check for your MariaDB. Follow the below command,
The above command will run a simple security script comes with pre-installed with MariaDB. Which will remove the insecure default settings and lock down access to your database system.
MariaDB installation’s security options prompt will appear on your screen. The first question will prompt to enter the current root password of your current database. By accessing the database with sudo privileges will make the MariaDB more secure.
The next prompt will ask you about setup a new password for your Database. You need to enter “N” and execute it. In Debian, the root account for MariaDB is tied closely to automated system maintenance and so we should not change the configured authentication methods for that account. We need to do and make it possible for a package that updates to break the DB system by removing the access to the administrative account.
And then, Enter “Y” and hit the “Enter” button to continue all the prompt. This will remove if any users other than admin and the test admin will be blocked by accessing the database through remote logins.
After changing the new rules and complete the configurations, The MariaDB will immediately update to the new rules.
With all these settings, the server access the MariaDB with root privileges. The server will use the root account for simple tasks like log creation. it is best not to change the root account’s authentication details. It is recommended that you need a separate administrator account if you need a new admin account with password-based access.
To create the new MariaDB admin account follow the below command:
We need to create a administrator account with same user privileges as root account. Now you need to create a new root user account with password credentials.
After executing the above command, you need to flush the privileges.
Then exit the MariaDB database,
You can access your new administrator account with a defined password using the following command.
Installing PHP to your Web Server:
PHP is a programming language of setup which will display the dynamic content of your website or webs app. This PHP have the compatibility to run with the MariaDB database and work with Debian OS. You can install the php by using the command below:
The above command will install the PHP to your server. But default, the Apache server will look for the “Index.html” file only, here we using PHP to display the contents and so we need to change the “index.html to index.php”. We want to tell the web server to prefer PHP files over others, so make Apache look for an index.php file first. You need to follow the below command to do this.
The following output will appear on your screen:
You need to replace the index.html with index.php to its consecutive places. After replacing, it will appear like this.
Then save the file and exit. Now the Apache will look for Index.php initially. After this, you need to restart your apache server by using the following command.
You will receive output as “OK“. Now it is the time to verify the installation of PHP.
Verify the Installation of PHP:
In order to verify the installation of the PHP, You just need to create a file named as “info.php“. This file must be saved in the correct root directory and then only it will be read by Apache server. The default web root folder and path of Debian 9 is /home/s1/html/. To create the info.php file in the web root and then follow the below command,
A blank screen will appear on your windows and now you need to paste the below code and save the file.
When you finished, save the file and exit the file. Now open any browser and enter the below command,
The following image will appear on your screen.
If you see the above image on your screen and then you have done it successfully without any error. Now you can host any type of dynamic content in your webs server. Your web server is all set and good to go.
That’s it, We explained the clear steps in installing LAMP stack on Debian 9 OS. The LAMP stack is an acronym of Linux, Apache, MariaDB & Php. If you have any queries and then comment us below. If you like this article and then you can give an upvote to this article and encourage us. If you want to know how to install the LAMP stack on Ubuntu 18.04? Then we suggest you take a look at this article.
For more article, kindly visit our Homepage