in

LinuxLinux

How To Install LAMP Stack On Debian 9 Distro {Detailed Steps}

Multiple ways to install LAMP stack on Debian 9 Distros

LAMP Stack on Debian 9

L

AMP 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.

Jump To:

Prerequisites:

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:

$sudo apt update

The above command will update your packages to the current system.

$sudo apt install apache2

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.

$sudo ufw app list

The following output will appear on the screen.

Output

Available applications:
. . .
WWW
WWW Cache
WWW Full
WWW Secure
. . .

Check this too  How To Reset the Firewall on Ubuntu 16.04 & 18.04 LTS Server

If you inspect the “WWW Full” application shows that the command enables traffic to the port 80 and port 443

$sudo ufw app info "WWW Full"

You will receive the following output,

Output

Profile: WWW Full
Title: Web Server (HTTP,HTTPS)
Description: Web Server (HTTP,HTTPS)

Ports:
80,443/tcp

If you want to allow all the incoming and outgoing traffic to your web server and then follow the below command.

$sudo ufw allow in “WWW Full”

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.

$http://your_server_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.

Apache Server on Debian 9
Apache Server on Debian 9

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“.

$sudo apt install 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,

$sudo mysql_secure_installation

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.

Check this too  How To Install WordPress With LAMP Stack on Ubuntu 18.04 DigitalOcean Server!

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:

$sudo mariadb

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.

Command:
GRANT ALL ON *.* TO ‘administrator‘@’localhost’ IDENTIFIED BY ‘new-password‘ WITH GRANT OPTION;

After executing the above command, you need to flush the privileges.

MariaDB [(none)]>FLUSH PRIVILEGES;

Then exit the MariaDB database,

MariaDB [(none)]>exit

You can access your new administrator account with a defined password using the following command.

$mariadb -u administrator -p

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:

$sudo apt install php libapache2-mod-php php-mysql

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.

$sudo nano /etc/apache2/mods-enabled/dir.conf

The following output will appear on your screen:

Output:

<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Check this too  Doctl Ubuntu- How to Install DigitalOcean Command Line Tool on Ubuntu 18.04 LTS/ 19.04

You need to replace the index.html with index.php to its consecutive places. After replacing, it will appear like this.

Output:

<IfModule mod_dir.c>
DirectoryIndex index.php index.cgi index.pl index.html index.xhtml index.htm
</IfModule>

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.

If you don’t know how to restart apache server and we suggest you take a look at this article.

$sudo systemctl restart apache2

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,

$sudo nano /home/s1/html/info.php

A blank screen will appear on your windows and now you need to paste the below code and save the file.

/home/s1/html/info.php
<?php phpinfo(); ?>

When you finished, save the file and exit the file. Now open any browser and enter the below command,

http://your_server_ip_address/info.php

The following image will appear on your screen.

PHP info Debian 9
PHP info Debian 9

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.

Verdict:

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.

Article Review
  • Content Explanation
  • Command Working
  • Content Clarity
  • Methods Working
4.7

Summary

For more article, kindly visit our Homepage

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by Jim Moriarty

Hello, Am Jim from Arizona, Big Fan of Holmes. Server-side handler, Network Engineer & currently working for Tec Robust. I write a server-based article.

Contact me:
tecrobust [@] gmail.com
Sub: Message to Jim.

Transform HTML to Markdown

HTML to Markdown Converter- Transform HTML Codes to Markdown- Online

HTML to Jade Converter

HTML to Jade Converter- Convert HTML Codes to Jade Online- Instant