How to Install and Configure LAMP on Debian 9

To Install and Configure LAMP on Debian 9

LAMP Stack, which comprises a group of open source applications such as Linux, Apache, MySQL and PHP, is used for getting the servers up and running. In this tutorial, you will be briefed about the method to install and configure these programs on Debian 9.

Installing LAMP

Since we are installing the Stack in Debian which is a Linux distribution, the Linux part is already taken care, but the rest of the Stack elements are to be installed and configured, so let us see about them in the following segments.

To Install Apache

In order to install the Apache package, you ought to run the apt-get command since it is the default package manager for Debian.

root@debian:~# apt-get install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libjavascriptcoregtk-3.0-0 libwebkitgtk-3.0-0
.
.
.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service &rarr  /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service &rarr  /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for systemd (232-25) ...

Once installed, start and enable the Apache service with the help of the following commands.

root@debian:~# systemctl enable apache2
root@debian:~# systemctl start apache2

Once it is done, verify if it is installed properly through the browser.

Installing MariaDB

You should add the dependency package to install MariaDB. Run the following command for the same purpose.

root@debian:~# apt-get install software-properties-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
software-properties-common is already the newest version (0.96.20.2-1).
software-properties-common set to manually installed.
The following packages were automatically installed and are no longer required:
  libjavascriptcoregtk-3.0-0 libwebkitgtk-3.0-0
Use ' apt autoremove'  to remove them.
0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.

Now you should add the repository key as follows.

root@debian:~# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
Executing: /tmp/apt-key-gpghome.4k8FrmwNwq/gpg.1.sh --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
gpg: failed to start the dirmngr ' /usr/bin/dirmngr' : No such file or directory
gpg: connecting dirmngr at ' /tmp/apt-key-gpghome.4k8FrmwNwq/S.dirmngr'  failed: No such file or directory
gpg: keyserver receive failed: No dirmngr

Once it is done, you need to add the MariaDB repository, which can be done by running the following command.

root@debian:~# add-apt-repository ' deb [arch=amd64,i386] http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian sid main' 

Enable the following line from source.list file.

root@debian:~# vim /etc/apt/sources.list


After that, upgrade the machine by using the following command.

root@debian:~# apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  libjavascriptcoregtk-3.0-0 libwebkitgtk-3.0-0
.
.
.
Processing triggers for libc-bin (2.24-11+deb9u1) ...
Processing triggers for systemd (234-3~bpo9+1) ...
Processing triggers for initramfs-tools (0.130) ...
update-initramfs: Generating /boot/initrd.img-4.9.0-3-amd64

After that update the machine.

root@debian:~# apt-get update
Hit:1 http://deb.debian.org/debian stable-updates InRelease                                          
Ign:2 http://ftp.us.debian.org/debian stretch InRelease                                                        
Ign:3 http://ftp.us.debian.org/debian squeeze InRelease                                                        
.
.
.
.
Hit:6 http://deb.debian.org/debian-security stable/updates InRelease     
Ign:4 http://www.ftp.saix.net/DB/mariadb/repo/10.1/debian sid InRelease
Fetched 3,125 B in 1s (2,152 B/s)
Reading package lists... Done

Now all is set for the installation of the MariaDB package. Trigger its installation by running the following command.

root@debian:~# apt-get install mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libjavascriptcoregtk-3.0-0 libwebkitgtk-3.0-0
.
.
.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service &rarr  /lib/systemd/system/mariadb.service.
Setting up mariadb-server (10.1.26+maria-1~stretch) ...
Processing triggers for libc-bin (2.24-11+deb9u1) ...
Processing triggers for systemd (234-3~bpo9+1) ...


All that is left with respect to MariaDB is to start and configure its service, for that you need to run the following commands.

root@debian:~# systemctl start mariadb
root@debian:~# mysql_secure_installation


Installing PHP package
PHP is the only remaining element from the LAMP Stack that still needs to be installed. Run the following command for a secure installation of PHP in your Debian machine.

root@debian:~# apt-get install php php-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libjavascriptcoregtk-3.0-0 libwebkitgtk-3.0-0
.
.
.
apache2_invoke: Enable module php7.0
Setting up php7.0 (7.0.19-1) ...
Setting up php (1:7.0+49) ...

Once you' ve installed PHP, you can check its version with the help of the following command.

root@debian:~# php -v
PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.19-1, Copyright (c) 1999-2017, by Zend Technologies

With this, the installation of LAMP Stack is over.

Tag : LAMP debian
FAQ
Q
Is PhpMyAdmin is required?
A
You can have a graphical interface for accessing and managing the database for the MySQL query.
Q
What LAMP setup is maintained in cPanel?
A
cPanel uses Easy apache, Mysql and PHP.
Q
Is LAMP can have Perl?
A
The LAMP can have Perl,php, and python.
Q
Wanna I know the idea about the difference between LAMP and LEMP stack?
A
Please refer the link as follow "https://forumweb.hosting/13713-what-is-the-difference-between-lamp-stack-and-lemp-stack.html"
Q
Wanna I make an installation of LAMP stack on Manjaro?
A
Please refer the link as follow "https://www.linuxhelp.com/how-to-install-lamp-stack-on-manjaro-17-0-5/"