Install LAMP Server on Debian 9

Hello everyone, today we will show you how to install LAMP Server on Debian 9. LAMP (Linux Apache MySQL PHP) is a powerful web server and database stack needed to built a robust web server and web applications. Installing LAMP Server on Debian 9 is pretty easy. On this tutorial, we will work mostly via command line. You can either log in to the Debian server physically or via SSH.

Steps to install LAMP Server on Debian 9

The following commands must be run with root privileges. You can also use sudo user to execute these commands.

Step 1. Update system

apt update && apt upgrade

Step 2. Install Apache Web Server

apt install apache2

Output example:

root@debian:/home/dhani# apt install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
Suggested packages:
  www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 2123 kB of archives.
After this operation, 7073 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

Run and enable Apache on startup

systemctl start apache2
systemctl enable apache2

Now check if the web server is correctly installed

Step 3. Install MySQL Server

apt install mysql-server

Output example:

root@debian:/home/dhani# apt install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  default-mysql-server galera-3 gawk libaio1 libarchive13 libcgi-fast-perl libcgi-pm-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl
  libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
  liblwp-mediatypes-perl libmpfr4 libsigsegv2 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.1 mariadb-client-core-10.1
  mariadb-common mariadb-server-10.1 mariadb-server-core-10.1 rsync socat
Suggested packages:
  gawk-doc lrzip libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libdata-dump-perl libipc-sharedcache-perl libwww-perl
  mariadb-test netcat-openbsd tinyca
The following NEW packages will be installed:
  default-mysql-server galera-3 gawk libaio1 libarchive13 libcgi-fast-perl libcgi-pm-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl
  libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
  liblwp-mediatypes-perl libmpfr4 libsigsegv2 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.1 mariadb-client-core-10.1
  mariadb-common mariadb-server-10.1 mariadb-server-core-10.1 mysql-server rsync socat
0 upgraded, 32 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.2 MB of archives.
After this operation, 190 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

The default mysql-server command will actually install mariadb-server instead of MySQL Server. But don’t worry its as good as MySQL Server.

Secure MySQL Installation

mysql_secure_installation

Output example:

root@debian:/home/dhani# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Step 4. Install PHP

The command below will install the latest version of PHP 7 on Debian 9.

apt-get install php php-pear php-mysql

Output example:

root@debian:/home/dhani# apt install php php-pear php-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.0 libxslt1.1 php-common php-xml php7.0 php7.0-cli php7.0-common php7.0-json php7.0-mysql php7.0-opcache php7.0-readline
  php7.0-xml
The following NEW packages will be installed:
  libapache2-mod-php7.0 libxslt1.1 php php-common php-mysql php-pear php-xml php7.0 php7.0-cli php7.0-common php7.0-json php7.0-mysql php7.0-opcache
  php7.0-readline php7.0-xml
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 4324 kB of archives.
After this operation, 17.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

Optionally check PHP version using PHP script.

nano /var/www/html/info.php

Paste these lines into it

<?php
phpinfo();
?>

Close and save it. Now type the server IP address and add info.php at the end. For example in my case:

http://10.34.0.156/info.php

You should see something like this

At this point, our LAMP Server is ready. We can now install any other web applications such as Pydio, WordPress, Owncloud, Nextcloud and many others.

Admin

One Comment

Leave a Reply

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