How to Install a LAMP Server on Debian 9 Stretch

To install MaridaDB on Stretch.

apt install mariadb-client mariadb-server

output:

root@vps:~# apt install mariadb-client mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:

you can log in as your root user and set up a regular user and a database.

mysql -u root -p

output:

root@vps:~# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.37-MariaDB-0+deb9u1 Debian 9.6

Creating a database.

CREATE DATABASE newdb;

output:

MariaDB [(none)]> CREATE DATABASE newdb;
Query OK, 1 row affected (0.00 sec)

You need to create a regular user now to use the database.

CREATE USER 'lamp'@'localhost' IDENTIFIED BY 'password';

output:

MariaDB [(none)]> CREATE USER 'lamp'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

you need to grant them privileges on it.

GRANT ALL PRIVILEGES ON newdb.* to 'lamp'@'localhost';

output:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON newdb.* to 'lamp'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Once that's done, flush all privileges from the console and exit.

FLUSH PRIVILEGES;
quit

output:

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

The next step in getting the LAMP server set up is installing PHP.

apt install php7.0 php7.0-mysql

output:

root@vps:~# apt install php7.0 php7.0-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:

Install both the Apache server and the module for PHP support.

apt install apache2 libapache2-mod-php7.0

output:

root@vps:~# apt install apache2 libapache2-mod-php7.0
Reading package lists... Done 
Building dependency tree       
Reading state information... Done
apache2 is already the newest version (2.4.25-3+deb9u6)

To start Apache on your server

service apache2 start

output:

root@vps:~# service apache2 start

And to enable on boot

service apache2 enable

output:

root@vps:~# service apache2 enable

To test the working of PHP after installing, Create a file in /var/www/html/index.php

nano /var/www/html/index.php

<?php phpinfo(); ?>

To view the PHP info on your browser, http://IP_address/index.php

If you want an easy way to manage your database through a graphical web interface, you can install an application called, phpmyadmin.

apt install phpmyadmin

output:

root@vps:~# apt install phpmyadmin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:

Open the web interface using, http://IP_address/phpmyadmin

This concludes the installation of LAMP on Debian 9.