In the previous LAMP stack installation article, we learned how to install the stack in a CentOS 7 machine. Looks like we’ve got enough of CentOS covered. It’s time to go for Debian. So let’s begin installing LAMP Stack on Debian 9.
LAMP, which means, Linux-Apache-MySQL-PHP is a collection of tools essential for hosting a website on a server.
What Are The Requirements For LAMP Stack?
Requirements technically are based on what you’re going to host. But for a simple WordPress website, we’d take the following specs.
- Debian 9 as OS(Of course!)
- 512 MB of RAM
- 20 GB of minimum space
- 1 vCore
Time to head for installation.
Installing LAMP Stack on Debian 9 Server
Before we begin the installation, we should note that our machine is in the fresh installation phase. To do all this, you need access to the terminal. Access the terminal of your server by learning how to connect to a server using putty.
Step 1 – Updating The Packages
There might be many packages pending updates. To update them, run the following command in your terminal.
apt update && apt upgrade && apt dist-upgrade
This will upgrade the machine to bring in the latest update of the packages.
Step 2 – Installing Apache
Now it’s time to install the webserver, Apache. Along with the package, we will also install a few of the very essential tools that we will need in the future. To do so, run the following commands.
apt install apache2 wget nano
Press Y if asked and follow the instructions until the installation is completed.
Step 3 – Installing the “M”ySQL system called MariaDB
To run a website, you would need a database to see, input, edit, delete and other actions for data. To do so, you need a database and we’ll do it by installing MariaDB. Run the following command to install MariaDB.
apt install mariadb-server
Press Y and follow the steps accordingly.
Step 4 – Setting up MariaDB
Now since MariaDB is downloaded and installed, we would need to set up the database. To do so, let’s type the setup command.
Now it will ask for a few things. Firstly, it will ask you for entering the MySQL root password. But since it is a fresh installation, press Enter without entering the password and we’ll go on the next step.
Enter current password for root (enter for none):
Now the next step would ask if you want to set up a MySQL root password. Press “Y” for it. Enter the new password.
Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables... ... Success!
Now it will ask for the next few questions. They don’t need much explanation so just follow the instructions as mentioned below.
Remove anonymous users? [Y/n] Y ... Success! Disallow root login remotely? [Y/n] Y ... Success! Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reload privilege tables now? [Y/n] Y
We’re now done setting up MySQL. Let’s make a separate user for MySQL so that we can differ it from the root. To do so, let’s get into MariaDB. To do so, type the following command.
We’ll create a user named “master” and grant it full root access.
MariaDB [(none)]> GRANT ALL ON *.* TO 'master'@'localhost' IDENTIFIED BY '[email protected]' WITH GRANT OPTION;
Copy the part from “GRANT …” . Now let’s flush the privileges that are saved in the current login session.
Exit the session as we’re done with it by using the following commands.
Now to access the database next time, let’s use the following command.
mariadb -u master -p
We’ve come this far and successfully installed Apache & MariaDB. Let’s now head towards installing PHP.
Step 5 – Installing PHP
PHP is a part of your setup that processes dynamic code and runs stuff in the background. It can be used to connect to the MariaDB database to process data into information and display it to the web page.
Let’s install PHP using the following command.
apt install php libapache2-mod-php php-mysql
Press “Y” and then Enter. Continue the steps to finish installing PHP.
Step 6 – Testing PHP
Let’s test the PHP as we’re done installing it. To do so, we’ll first have to restart the webserver as we didn’t do it after post-installation. To do so, run the following command.
service apache2 restart
We’ve successfully restarted Apache. Now let’s test PHP. To do so, we’d need to go to the directory where the website files would be located. Type the following command to head there.
We’re in the directory. Let’s type
and see what files are here. In a fresh installation, we’d find a default html file named
Let’s remove it by doing
rm -rf info.php
Now the directory is clean. Type the following command to make a new file as index.php.
Enter the below code and paste it into nano.
Now CTRL + X then press Y then Enter again. For security reasons, you cannot copy the code from here. Just type it.
Now open your browser and enter your server’s IP in the URL box.
You will see something like this. If you see that, it means we’re done installing LAMP Stack.
We’re done installing LAMP Stack on Debian 9. For doing all above stuff, you’d definitely need a VPS. To get a cheap VPS, why not try Shadow Hosting’s VPS Hosting? With affordable prices, you can get heavy machines to get your resource-hungry projects running.
Check out our new cyber-intelligence project at ShadowCrypt.