How To Install LAMP Server on Debian 9

0

ADVERTISEMENT

THIS DOCUMENT IS ALSO AVAILABLE FOR

LAMP (a server stack) stands for Linux, Apache, MySQL, and PHP. These four popular open source software components are used by most of the web hosting companies, web developers, blogs and others to run their websites.

Here is the small guide about installing LAMP Stack on Debian 9.

Install LAMP Stack

Install Linux

Here is the article about Step by Step installation of Debian 9 and Upgrading Debian 8 Jessie to Debian 9 Stretch.

Now, we will proceed to the installation of AMP (Apache v2.4, PHP version 7.3, MariaDB v10.3) on Debian 9. So, let’s install one by one.

Install Apache

To start off, we will install the Apache web server.

Update the package repository index.

sudo apt-get update

The package name of the Apache web server is apache2. Install the apache2 package using the apt-get command

sudo apt-get -y install apache2-data apache2-utils

Check the status of Apache web server service.

sudo systemctl status apache2

We will now test the Apache web server to confirm whether it is working correctly or not.

Open up any web browser and then navigate it to the following URL.

http://localhost/

OR

http://your-ip-add-ress/

You will get the “Apache2 Debian Default Page“, this default page confirms you that the Apache HTTP server is working fine.

Install LAMP Server on Debian 9 Stretch - Apache2 Default Page
Install LAMP Server on Debian 9 Stretch – Apache2 Default Page

Apache HTTP server’s default document root is /var/www/html/ on Debian and the main configuration file is /etc/apache2/apache2.conf. Additional configuration files are found in the /etc/apache2 directory and the directory hireacrchy as follows.

       /etc/apache2/
       |-- apache2.conf
       |       `--  ports.conf
       |-- mods-enabled
       |       |-- *.load
       |       `-- *.conf
       |-- conf-enabled
       |       `-- *.conf
       `-- sites-enabled
               `-- *.conf

Install MariaDB

MariaDB is the drop in replacement of MySQL server, developed by the original developers of MySQL to stay and have open source RDBMS. MariaDB is now one of the most popular database servers in the world.

To install MariaDB, run the following command

ADVERTISEMENT

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

Secure, MariaDB server using “mysql_secure_installation” command.

READ: How to Secure MariaDB installation using mysql_secure_installation.

This command enables you to improve the security of your MariaDB installation in the following ways:

  • You can set a password for DB root account.
  • You can restrict root accounts to the local host.
  • You can remove anonymous user accounts.
  • You can remove the test database and privileges that permit anyone to access databases with names that start with test_.

Install PHP

By default Apache server supports the .html only not PHP, for that you need to install PHP and the php extension package for the MariaDB server.

Here, we will install PHP 7 on Debian 9.

sudo apt-get -y install php libapache2-mod-php php-mysql

You would need to restart the Apache HTTP server after the installation of the PHP package.

sudo systemctl restart apache2

Test LAMP Stack

To test a PHP 7, we need to place a .php file on the default document root of Apache HTTP server. The document root of the default site is /var/www/html. S, we will now create a PHP file (info.php) in that directory and call it in a browser. The output will display lots of useful details about our PHP installation, such as the installed PHP version.

Use a VI editor to create the info.php file.

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

This vi command will open up a file called info.php. Copy/Paste below lines into the info.php file:

<?php phpinfo(); ?>

Save and close the file using Esc + :wq.

Now open up your internet web browser and type the following URL into the web address.

http://localhost/info.php

OR

http://your-ip-add-ress/info.php

The page will look like below,

Install LAMP Server on Debian 9 Stretch - PHPInfo Page
Install LAMP Server on Debian 9 Stretch – PHPInfo Page

Conclusion

That’s All. You have successfully installed the LAMP Stack on Debian 9.

You might also like