How to Install the LAMP Stack on Your Fresh CentOS 7 VPS

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 who’s operation run on server-side queries. And last, not the least, “P” stands for PHP which is one of the most essential web programming language 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 basic system requirements needed.

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 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

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

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 in the web browser and visit the IP. If you see the page like displayed below, it means it is working well!

HTTPD Test Page - LAMP Stack

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

Confirm the installation by pressing Y and 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 of 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 MariaDB admin/root password. For security reason, 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.

  1. Set root password? [Y/n] Y
  2. New password: Enter your password here
  3. Re-enter new password: repeat your password
  4. Remove anonymous users? [Y/n] Y
  5. Disallow root login remotely? [Y/n] Y
  6. Remove test database and access to it? [Y/n] Y
  7. 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 which works well with HTML and other basic web languages. It is also used to integrate the web page with 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 5.6, we need to install EPEL Release and Remi repository. Along with that, we need few more things to allow PHP 5.6 installation to take place. To do that, use 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-php56

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

Confirm the installation process by pressing Y and then Enter button.

Now since we’ve installed PHP, we will have to make it go in 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.

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.

Testing PHP - Installing LAMP

Now it is showing all PHP information. Everything now works fine.


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 $4.27 for the first month. Check out the plans mentioned below and choose anyone!

Screw Driver – 4 GB RAM – 80 GB HDD Space – 1 Core – 2 TB Bandwidth – $8.00/month – $4.27! – Checkout!

Hammer – 6 GB RAM – 150 GB HDD Space – 2 Cores – Unlimited Bandwidth – $12.00/month – $6.07! – Checkout!

Chainsaw – 8 GB RAM – 300 GB HDD Space – 4 Cores – Unlimited Bandwidth – $15.00/month – $7.42! – Checkout!

(Note:- Use the coupon “JULY55” to enable the discount. The discount is valid till the end of July, till 31st July 11:59 PM). Use the VPS to run your website using the tutorial to install LAMP Stack on your brand new VPS you’ll(or already have bought) buy!

Also, check out ShadowCrypt.club for web tools which you might need in your project in future.

About Manal Shaikh 17 Articles
Manal Shaikh, the Founder of Shadow Networks International and CEO/Chairman of Shadow Hosting International. A cybersecurity analyst, network analyst and a web administrator.

1 Trackback / Pingback

  1. How To Install phpMyAdmin on a Fresh CentOS 7 Server

Leave a Reply

Your email address will not be published.


*


CommentLuv badge