How to Install the LAMP Stack on Your CentOS 7 VPS or Dedicated Server

How to Install the LAMP Stack on Your CentOS 7 VPS or Dedicated Server

LAMP represents a group of software applications that are used together to run a dynamic website. It represents Linux, Apache, MySQL, and PHP.

[openingText]Linux is an open source Operating System while Apache is a web server. MySQL/MariaDB is a relational database management system and PHP is a server-side scripting language. All these software must be installed on your Virtual Private Server (VPS) if you want to run most dynamic websites like WordPress.[/openingText]

In this guide, we will cover the steps needed to install a LAMP stack on your VPS server running CentOs 7.

Consult with Hostadvice’s Best Linux Hosting Services page to find the top Linux hosting services.

Prerequisites

  • [tool]A VPS plan running CentOs 7[/tool]
  • [tool]A non-root user with sudo privileges[/tool]

Step 1:
[stepName]Update your system[/stepName]

[step]

Before you install the applications, make sure your CentOs 7 server is up to date by running the command below:

$ sudo yum update

[/step]

Step 2:
[stepName]Install Apache[/stepName]

[step]

[howToDirection]

We are going to use the Yum package manager to install any software applications on CentOs 7. To install Apache web server, run the command below:

$ sudo yum install httpd

[/howToDirection]

[howToDirection]When prompted to confirm the installation, press Y and Enter to proceed.[/howToDirection]

[howToDirection]We are installing the software using sudo command so that we can temporarily get administrative privileges.[/howToDirection]

[howToDirection]

Next, we need to start Apache service by running the command below:

$ sudo systemctl start httpd.service

[/howToDirection]

[howToDirection]

At this point, you can enter your public IP address on a browser to confirm the installation. You should get the default Apache page as shown below:

[stepImage][/stepImage]

[/howToDirection]

The page above indicates that Apache was installed successfully on your CentOs 7 server.

[howToDirection]

Next, you need to activate Apache to start during system boot using the command below:

$ sudo systemctl enable httpd.service

[/howToDirection]

[/step]

Step 3:
[stepName]Install MariaDB Database[/stepName]

[step]

[howToDirection]MariaDB is a forked version of MySQL. It is an open source software application developed by a community that wants it to remain free for everyone.[/howToDirection]

[howToDirection]

We will need MariaDB to store information for our dynamic websites. We can install MariaDB together with additional packages that we require on our CentOs server by running the commands below:

$ sudo yum install mariadb-server mariadb

Confirm the installation, by pressing Y and Enter.

[/howToDirection]

[howToDirection]

Now that the MariaDB installation was completed successfully, we can run the command below to start the service.

$ sudo systemctl start mariadb

[/howToDirection]

[/step]

Step 4:
[stepName]Securing MariaDB[/stepName]

[step]

[howToDirection]

By default, our MariaDB is not secure by default, we need to remove the anonymous user and test database and configure other settings by running the command below:

$ sudo mysql_secure_installation

[/howToDirection]

[howToDirection]You will be prompted to enter your MariaDB root password, just press Enter because you haven’t set any password yet. Please note that this should not be confused by the root password of your server.[/howToDirection]

[howToDirection]

Once you have done this, you will be asked a series of questions. We have provided the answers below for simplicity:

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

[/howToDirection]

[howToDirection]

Finally, you will get a success message as shown below:

 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB Installation should now be secure.

[/howToDirection]

[howToDirection]

Your MariaDB server is now secure. Type the command below to enable it during boot:

$ sudo systemctl enable mariadb.service

[/howToDirection]

[/step]

Step 5:
[stepName]Install PHP[/stepName]

[step]

PHP is a general-purpose server-side scripting language. PHP works together with HTML to display dynamic content on your website. It also has the correct drivers for connecting to the MariaDB database management system that we have installed above.

[howToDirection]

We can install PHP and MySQL extension using the yum package installer by typing the command below:

$ sudo yum install php php-mysql

[/howToDirection]

[howToDirection]Confirm the installation, by pressing Y and Enter.[/howToDirection]

[howToDirection]

We need to restart Apache web server one more time for it to work with PHP by typing:

$ sudo systemctl restart httpd.service

[/howToDirection]

[/step]

Test PHP

Apache installs a default website on the directory ‘/var/www/html/’. So to test PHP on our CentOs 7 Server, we need to create a file there using a nano editor.

First, let’s install nano by running the command below:

$ sudo yum install nano

Next, create our ‘info.php’ file by typing the command below:

$ sudo nano /var/www/html/info.php

A blank text file should be displayed, just copy paste the content below on the page:

<?php 
phpinfo(); 
?>

Then press CTRL + X, Y and Enter to save the changes

You need to visit the following URL on your browser to check whether PHP is working:

http://ip_address/info.php

Remember to replace the ‘ip_address’ part with your CentOs 7 server’s public IP address.

If the installation was completed without a problem, you should see the below page on the browser:

Test PHP

Conclusion

Your LAMP stack is now complete and you can run any type of dynamic website/software application provided it works on the Apache, MariaDB and PHP environment. You might also need to install or enable additional PHP extensions and Apache modules depending on your web hosting needs. We hope this guide will be a great starting point for installation the most common software applications required to run your website.

 

Check out the top 3 VPS services:

Hostinger
$1.59 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.9
  • Support
    4.9
  • Features
    4.8
  • Reliability
    4.7
  • Pricing
    4.5
Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hosting.com
$2.99 /mo
Starting price
Visit Hosting.com
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, usernam
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Setup a Docker Swarm Cluster on a CentOS 7 VPS or Dedicated Server

This how-to article will help you install and configure Docker Swarm on CentOS 7
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install and Configure Linux Malware Detect on CentOS 7

This tutorial will help you install and configure Linux Malware Detect (LMD) on
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install Redis on a CentOS 7 Dedicated Server or VPS

This tutorial provides a step-by-step guide for installing, configuring, managin
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
Click to go to the top of the page
Go To Top
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.