How to install LAMP Server on Debian 9

This tutorial is going to show you how to install LAMP Server on Debian 9 Stretch. LAMP is a combination between Linux, Apache, MySQL/MariaDB and PHP. With this LAMP we can built a powerful, rock solid web server to host web apps and many other stuffs. There are several steps to install LAMP on Debian 9. Please have a look at my other post on how to install Debian 9 Stretch. On this tutorial, I will guide you to install LAMP Server on a headless Debian 9 server. So, no GUI is available on my case. If you have Debian 8, please visit this page to watch how to install LAMP on Debian 8.8.

System Configuration

  • OS: Debian 9 Stretch
  • IP address: 10.34.0.202
  • Domain name: debian.manjaro.lan

Steps to install LAMP Server on Debian 9

Open Terminal (if you have GUI) or simply ssh to the Debian 9 Server and login as root.

Step 1. Install Apache web server

apt install apache2

Output sample:

root@debian:~# apt install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libglib2.0-0 libglib2.0-data shared-mime-info xdg-user-dirs
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
  liblua5.2-0 ssl-cert
Suggested packages:
  www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap liblua5.2-0 ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,144 kB of archives.
After this operation, 7,137 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Start and enable Apache on boot

systemctl start apache2
systemctl enable apache2

Now verify the web server. Open a web browser and type the Debian IP address. You should see similar to this one below.

Step 2. Install MariaDB Server

Use the following command to install MariaDB Server. FYI, MariaDB is the default database for MySQL package on Debian 9.

apt install mysql-server

Output sample

root@debian:~# apt install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libglib2.0-0 libglib2.0-data shared-mime-info xdg-user-dirs
Use 'apt autoremove' to remove them.
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 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 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 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 socat
0 upgraded, 30 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.3 MB of archives.
After this operation, 188 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Now start MariaDB and enable it on boot

systemctl start mariadb
systemctl enable mariadb

Check the status of mariadb service

root@debian:~# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2017-06-24 09:43:39 WITA; 20s ago
 Main PID: 9622 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─9622 /usr/sbin/mysqld

Jun 24 09:43:38 debian systemd[1]: Starting MariaDB database server...
Jun 24 09:43:39 debian mysqld[9622]: 2017-06-24  9:43:39 140594638725696 [Note] /usr/sbin/mysqld (mysqld 10.
Jun 24 09:43:39 debian systemd[1]: Started MariaDB database server.

Secure MariaDB installation

mysql_secure_installation

Follow on screen wizard to harden the MariaDB installation. Congratulation, you have successfully installed MariaDB Server on Debian 9.

Step 3. Install PHP

Now we will install PHP on Debian 9. Use the following command

apt install php php-mysql

Output sample

oot@debian:~# apt 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:
  libglib2.0-0 libglib2.0-data shared-mime-info xdg-user-dirs
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libapache2-mod-php7.0 php-common php7.0 php7.0-cli php7.0-common php7.0-json php7.0-mysql php7.0-opcache
  php7.0-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php7.0 php php-common php-mysql php7.0 php7.0-cli php7.0-common php7.0-json php7.0-mysql
  php7.0-opcache php7.0-readline
0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,691 kB of archives.
After this operation, 14.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Now check PHP version installed

root@debian:~# php --version
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

At this point we have successfully installed LAMP Server on Debian 9 Stretch. Thank you for reading this post. Please share this article if you found useful.

3 Comments

8 Trackbacks / Pingbacks

  1. How to install Nextcloud 12.0 on Debian 9 - Free Linux Tutorials
  2. Debian Tutorial - How to install Owncloud 10 on Debian 9
  3. Arch Linux Tutorial to install LAMP Server on Arch Linux 2017 Server
  4. Debian Tutorial - How to install Wordpress on Debian 9
  5. Debian Tutorial - How to install PHPMyAdmin on Debian 9 Stretch
  6. Migrate Wordpress Site Manually - NO PLUGINS NEEDED
  7. Complete Guide to Install Nextcloud 13.0 on Debian 9 | Manjaro dot site
  8. Formular mit MySQL-Anbindung (Teil 2) – Thelarion

Leave a Reply