Knowledgebase Home / How to Install LAMP (Linux, Apache, MySQL, PHP) on CentOS 7
// View Comments //

How to Install LAMP (Linux, Apache, MySQL, PHP) on CentOS 7

In this guide we will walk through the steps for installing and configuring LAMP stack on a CentOS 7 VPS.

All commands – without sudo

yum update
yum install httpd -y
systemctl start httpd
systemctl enable httpd
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
systemctl mysql_secure_installation
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager --enable remi-php73
yum install php php-mysql -y
systemctl restart httpd

All commands – with sudo

sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl mysql_secure_installation
sudo yum install epel-release yum-utils -y
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum-config-manager --enable remi-php73
sudo yum install php php-mysql -y
sudo systemctl restart httpd

LAMP is a set of open source software packages that is used to create websites and web applications. LAMP is an acronym. It consists of Linux as the operating system, Apache as the Web server, MySQL/MariaDB as the relational database management system and PHP as the server-side scripting language. In this document, we will go through the steps necessary for installing the LAMP stack on a CentOS 7 server.

All you require for these operations is a VPS with CentOS 7 installed on it and root/root privileged user access to the server.

Prerequisites

  • A CentOS 7 VPS
  • Root access to the server
  • An SSH client (PuTTY for example)

Step 1: Update your system

Before we start, it is always good to update the system software on the server. This can be done by executing the command below.

 sudo yum update -y

Step 2: Install Apache

The installation of Apache is a simple step and this can be done using the Yum Package Manager.

sudo yum install httpd -y

Start and enable the Apache service with the following command.

sudo systemctl start httpd
sudo systemctl enable httpd

Check whether Apache is running by calling your IP/hostname in the browser. If Apache is running the default CentOS 7 Apache web page will be displayed.

LAMP Installation on CentOS 7 Server

Apache Test Page on CentOS 7 Server

Step 3: Install MariaDB Database

MariaDB is a drop-in replacement for MySQL. It is a reliable SQL server that comes with a rich set of enhancements and features. For dynamic websites, it is always necessary to store data. We can install MariaDB together with additional packages that are required by running the commands below:

sudo yum install mariadb-server mariadb -y

Now that the MariaDB has installed successfully, run the command below to start and enable the service.

sudo systemctl start mariadb
sudo systemctl enable mariadb

To prevent unauthorized access to your database and remove some dangerous defaults run the following command.

sudo mysql_secure_installation

You will be prompted with an option to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, remove test databases and reload privileges. It is recommended that you answer ‘yes’ to these options to secure the database server.

Step 4: Install PHP

PHP is a widely used scripting language suited for web development. It works with Apache to display the dynamic content for your website. By default, PHP 5.4 is available in the CentOS 7 Yum repositories. We recommend that you install the latest stable version of PHP 7.x as it has many improvements and new features.

To install the latest PHP version we need to add EPEL and REMI repositories. Let’s start by installing the package “yum-utils” for configuring yum repositories and enabling the EPEL repository.

yum install epel-release yum-utils -y

Now, download and install the REMI repository.

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

Configure the repository for installing PHP 7.3 (or the latest stable version) using the following command. If there is a later version then simply modify the command by changing the version numbers in the command to match the release you wish to install.

yum-config-manager --enable remi-php73

We can now install PHP 7.3 along with its SQL dependency using the command below.

yum install php php-mysql -y

After installing PHP, restart the Apache service.

sudo systemctl restart httpd

Conclusion

That’s it. You’ve successfully installed the LAMP platform on your CentOS 7 system which can now run dynamic website and software applications. Depending on your web hosting needs, you might also need to install additional Apache modules and PHP extensions.

We highly recommend checking out OpenLiteSpeed web server as an open-source drop-in replacement for Apache. There can be significant speed increases by running OpenLiteSpeed. We have an article on how to install OpenLiteSpeed to help guide you.


If you have any web hosting questions please feel free to reach out to us. We're happy to help.
Shared Hosting | Reseller Hosting | Managed WordPress Hosting | Fully Managed VPS Hosting

Our Guiding Principles

  • Provide consistent, stable, and reliable web hosting services.
  • Ensure rapid ticket response and quick resolutions to issues.
  • Never saturate or over-provision servers to ensure stability and speed for our customers.
  • Use only high-quality enterprise-class hardware to ensure minimal downtime from hardware failures.
  • Provide clear pricing with no hidden fees or gotchas.
Subscribe to comment notifications
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments