
LAMP Stack represents a group of software used in making a website on a fresh dedicated server/virtual private server. The full-form “LAMP” represents “Linux, Apache, MySQL, and PHP”. As we all know, all these software are essential to run a fully functional website.
Linux is an open-source operating system while Apache is a web server application to host web pages, MySQL is a database structure management system whose operation runs on server-side queries. And last, not least, “P” stands for PHP which is one of the most essential web programming languages used in making websites like WordPress, MyBB, Magento and etc.
In this article, we’re going to learn how to install LAMP on your CentOS 7 VPS. So before we begin, let’s list down the basic system requirements needed.
Table of Contents
System Requirements
Minimum
- Minimum Memory of 512 MB(RAM)
- At least 2 GB of free disk space
- 100 Mbps speed connection
- CentOS 7 OS
Recommended
- At least memory of 1 GB(RAM)
- At least 5 GB of free disk space
- 250 Mbps speed connection
- CentOS 7 OS
There might be more requirements needed but for the most basic ones, we’ve listed above. So let’s begin installing LAMP Stack on your VPS.
Installing LAMP Stack on CentOS 7
Starting with the first step, we have to connect to your VPS using SSH client, Putty(if you’re using Windows).
Step 1 – Updating system packages to the latest version
Before you install the applications, make sure your CentOs 7 server is up to date by running the command below:
sudo yum update -y
Step 2 – Installing “A”pache or Apache on the system and installing essential tools needed
We’re going to use Yum package manager to install Apache on your VPS. To install, use the command below:
sudo yum install httpd wget nano -y
Now after installation, we have to turn on the Apache to test if it is working well. To do so, make sure your port 80 is enabled. To see if it is working, copy your VPS’s IP and paste it into the web browser and visit the IP. If you see the page displayed below, it means it is working well!
Now to enable the Apache service on boot use the command below:
systemctl enable httpd.service
Now whenever your server reboots, Apache will be started at the boot so you don’t have to always connect to your VPS and turn it on after every restart. This will be more beneficial if you’re running a test environment where you require a lot of reboots.
Step 3 – Installing MariaDB
Now it’s time to install the database management system MariaDB on your VPS. To do that, we’ll use the Yum package manager once again. To do so, use the command below:
sudo yum install mariadb-server mariadb -y
Confirm the installation by pressing Y and the enter/return button.
Now since MariaDB is installed on your system, we will turn it on. To do that, use the command mentioned below:
systemctl start mariadb
Step 4 – Securing MariaDB
By default, MariaDB isn’t secure because the anonymous user is enabled on installation and the password is not yet set up. To begin setting up the installation, use the command mentioned below:
sudo mysql_secure_installation
You will be prompted to enter your MariaDB password. Since we’re doing a fresh installation, we do not need to enter the MariaDB password. Just press Enter to continue. Now you will be asked if you want to set up a MariaDB admin/root password. For security reasons, you should press “Y” and then press Enter to set the password. Do not confuse between your MariaDB password and your server’s root password. They both are different.
For your easy, we have written down questions that will be asked to you with answers you’ve to insert accordingly.
- Set root password? [Y/n] Y
- New password: Enter your password here
- Re-enter new password: repeat your password
- Remove anonymous users? [Y/n] Y
- Disallow root login remotely? [Y/n] Y
- Remove test database and access to it? [Y/n] Y
- Reload privilege tables now? [Y/n] Y
At the last after every setup of MariaDB, you will see the below-written message which means it is installed correctly
.... Success! Cleaning up...
All done! If you’ve completed all of the above steps, your MariaDB installation should now be secure.
Everything is set up for MariaDB. Now we’ll have to enable it for boot. To do that, we will use the below-mentioned command:
sudo systemctl enable mariadb.service
Step 5 – Installing PHP
PHP is one of the most used web programming languages on the Internet. It is a server-side web page programming language that works well with HTML and other basic web languages. It is also used to integrate the web page with the MariaDB server to store data from your web page to the database and to even fetch it. So let’s begin installing PHP on your CentOS 7 server.
To install PHP 7.4, we need to install EPEL Release and Remi repository. Along with that, we need a few more things to allow PHP 5.6 installation to take place. To do that, use the below-mentioned commands.
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-config-manager --enable remi-php74
So let’s install PHP and it’s MySQL extension. To do that, use the command mentioned below:
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo -y
Confirm the installation process by pressing the Y and then the Enter button.
Now since we’ve installed PHP, we will have to make it go into effect with the webserver. To do that, we would have to reboot. Use the command mentioned below to reboot your web server Apache.
sudo systemctl restart httpd.service
Now PHP is installed on the webserver. If you wish to read a detailed installation article on PHP 7.4 installation, read our article on how to install or upgrade to PHP 7.4 on CentOS 7.
Testing PHP
Now even PHP is installed. Let’s test if it is working properly. To do that, you have to write the commands mentioned below:
cd /var/www/html
Now we’re in the public directory where your website’s file is updated. The command “cd” is used to navigate to the directory you wanted to visit ie “/var/www/html”. Now we will have to make a test PHP file to see if it is working properly through a web browser. To do that, we would need a command-line text editor. Since we’ve already installed “nano” in the first step, we will directly use it to make a new file. We will name the file as “test.php”.
nano test.php
Now paste the code as mentioned below.
<?php phpinfo(); ?>
The above code is a parameter in PHP used to check all modules and everything in detail about the current PHP installation in your server. To save the file, press “CTRL + X” and press Y, and then Enter to save it.
To test if it is working, copy the IP address of the server and enter it into the browser. You will see something like below on the screen. If you see so, it works well and everything went fine.
Now it is showing all PHP information. Everything now works fine.
Now for security reasons, you might wanna delete this phpinfo file because it can be used to exploit your webserver if left like this.
rm -rf test.php
Installing PHPMyAdmin
We have a separate article on how to install PHPMyAdmin in your CentOS 7 system.
Conclusion
We’ve successfully installed LAMP Stack on your CentOS 7 server. Now you can use it to host a web application on your server. We’ll be coming back soon with a new tutorial on something amazing! Till then, enjoy your own new webserver environment!
Affordable VPS you can use to enjoy your web server environment!
Shadow Hosting brings you a secure and one of the most affordable VPS in the market! Starting from just $8.00. Check out the plans on our website to know more!
Also, check out ShadowCrypt.club for web tools that you might need in your project in the future.
Leave a Reply