In this tutorial, we will show you how to install LAMP Stack on a Debian 9 VPS.
A LAMP (Linux, Apache, MySQL, PHP) stack is a combination of open-source software, typically installed on a server used for hosting dynamic websites and web applications. It includes the Linux operating system, the Apache web server, MySQL or MariaDB for data storage and management, and PHP for handling any dynamic content.
Installing LAMP on Debian 9 is a straightforward task and should not take more than 10 minutes. Let’s start with the installation.
Table of Contents
Prerequisites:
- A Debian 9 VPS
- Access to a system user with sudo privileges, or to the root account.
Step 1: Update the system
Before continuing with the next steps, update your Debian system by issuing the following commands:
Always keep your system updated. You can also set up automatic updates.
Step 2: Install Apache
Apache is the most widely used web server in the world. It is fast, secure, reliable, easy-to-use, and can be easily customized depending on your needs.
To install Apache on your Debian 9 server, type the following command:
Once the installation is complete, enable the Apache service to start automatically upon system boot. You can do that with the following command:
To verify that Apache is successfully installed, open your web browser, enter your server IP address, (e.g. http://12.12.12.12) and you should see a message saying “It works!”.
Step 3: Install MariaDB
The next step is to install MariaDB. It is one of the most popular database management systems.
To install MariaDB on your system, type the following command and enter ‘Y’ when prompted:
Once the installation is complete, it is recommended to run the following command to improve the security of your MariaDB server:
First, you will be asked to set the root password:
Type Y and enter the new MariaDB root password:
Next, you will be asked to change the root password, but since we already created it during the MariaDB installation, we can skip this step by pressing [Enter].
After this, you will get asked a couple of more questions and it is recommended that you answer ‘Y’ to all of them to confirm:
Once that is done, make sure to set the MariaDB service to start on boot with the following command:
That’s it – MySQL has been installed and secured.
Step 4: Install PHP
The last step in this tutorial is to install PHP.
PHP is a programming language mostly used for developing dynamic websites. Debian 9 comes with PHP 7.0 by default.
At the time of writing this article the latest PHP version is PHP 7.3 which is available in the DEB.SURY.ORG repository.
To enable the repository, run these commands:
You can now install PHP 7.3 along with some of the most common PHP modules by running the following command:
To test whether the PHP is working correctly we will create a file called info.php. Place this file inside the web server root directory.
Open your text editor and create a new file like this:
Enter the following lines and save the file:
After that, restart the Apache server by typing:
Now, if you navigate to this page: http://your_server_ip_address/info.php
in your web browser, you will see the following page showing your current PHP configuration:
This means PHP is working properly.
With this, you have completed the LAMP installation on Debian 9. Congratulations!
Of course, if you are one of our Lamp Stack Hosting customers, you don’t have to install LAMP on Debian 9, or to know how to install a LAMP stack on Debian 9, simply ask our admins, sit back and relax. Our admins will install LAMP on Debian 9 for you immediately.
PS. If you liked this post, on how to install a LAMP stack on Debian 9, please share it with your friends on the social networks using the buttons below, or simply leave a comment in the comments section. Thanks.