The LAMP server is the cornerstone of Linux web hosting. In the early days of dynamic web content LAMP was what won Linux the crown in the web space, and it still is responsible for powering a very large portion of the Internet's sites.
If you're looking to set up a LAMP stack to host your website, it'd be hard to find a better option to build it on than Debian Stretch. Debian is, after all, well known for its stability, security, and massive package repositories, and Stretch is certainly no exception. MariaDB(MySQL) To get started, install and setup the database portion of the stack, MariaDB. Traditionally, the “M” in LAMP stands for MySQL. However, MariaDB is a drop-in replacement that isn't controlled by Oracle, so it tends to be a better option.
To install MaridaDB on Stretch, just use apt to install the packages.
apt install mariadb-client mariadb-server
During the install process, you will be prompted to create a root password for MariaDB. Make sure to choose something as secure as possible, since it will determine, in part, the security of your databases.
Now that the MariaDB server is installed, you can log in as your root user and set up a regular user and a database. mysql -u root -p MariaDB will then prompt you for the root password that you just set up.
Creating a database is fairly simple. Just run the following.
CREATE DATABASE newdb;
You need to create a regular user now to use the database. It is an absolutely terrible idea to use the root user for anything other than managing MariaDB as a whole.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'userpassword';
That command creates a regular user that can sign in locally and set that user's password.
In order for that user to be able to use the database that you just created, you need to grant them privileges on it. Since this is a general purpose user for managing everything on this database, it will be given all privileges. GRANT ALL PRIVILEGES ON newdb.* to 'username'@'localhost'; Once that's done, flush all privileges from the console and exit.
That's all for the database. Certainly, you can customize any portion +of this as you need.
The next step in getting the LAMP server set up is installing PHP. In the LAMP stack, PHP powers the web content and interacts with the database. To install PHP on Debian Stretch, run the following line.
apt install php7.0 php7.0-mysql
That's really all that you need. PHP is now ready to use. Apache The Apache web server is extremely powerful and can be extremely easy to set up or ridiculously difficult, depending how in-depth you wan to go. Because this is just a simple guide, it's going to follow the quickest path for getting a basic server set up.
So, install both the Apache server and the module for PHP support.
apt install apache2 apache2-mod-php7.0
Testing Your Server By default, Apache will server the contents of /var/www/html and will look first for a file called index.php or index.html. Create that file, and place the following line of code in it.
<?php phpinfo(); ?>
Open up your browser and type in localhost in your address bar. If you aren't doing this locally, type your domain name or IP. You should see a long table containing information about your PHP install. At this point, your sever is officially working.
If you want an easy way to manage your database through a graphical web interface, you can install an application called, phpmyadmin. It allows you to manage your database using PHP through your LAMP server. To install it on Stretch, just pull it with apt.
apt install phpmyadmin