In this tutorial, you will learn, how to install LAMP on CentOS 7 or other Red hat based Linux distros. #centlinux #linux #mysql
Table of Contents
LAMP is an archetypal model of web service solution stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP server, the MySQL relational database management system (RDBMS), and the PHP programming language. As a solution stack, LAMP is suitable for building dynamic web sites and web applications.
LAMP stack components are largely interchangeable and not limited to the original selection. This results in evolution of many other stacks like LEMP, LEPP, etc.
In this article, we will install LAMP stack on CentOS 7 server. We will install each of four LAMP stack components separately on our CentOS 7 server.

System Specification:
CPU: | 3.4 Ghz (2 cores) |
Memory: | 2 GB |
Storage: | 60 GB |
Swap: | 4 GB |
Hostname: | lampserver.mydomain.com |
IP Address: | 170.172.0.30/16 |
Gateway: | 170.172.0.1 |
DNS Server: | 170.172.0.3 |
PINSPARK Men’s Quarter Zip Up Pullover Mock Neck Sweatshirts Warm Midweight Long Sleeve Polo Shirt with Pockets Casual
20% OffInstall CentOS 7:
As the Linux component of LAMP stack, we will install CentOS 7 on our machine.
Detailed guide of CentOS 7 installation is available here. Please follow it to install and configure CentOS 7.
In this article, we are using yum for installation on the Server, therefore, make sure that either you have accessed to CentOS 7 public yum repository by using CNTLM proxy or you have configured a local yum repository for your Linux server.
Install Apache Server on CentOS 7:
Apache server is the preferred choice for the web server on a LAMP stack.
Connect to lampserver.mydomain.com using ssh as root user and execute following commands to install Apache HTTP Server on CentOS 7.
yum install -y httpd
Start and enable Apache HTTP service.
systemctl enable httpd.service
systemctl start httpd.service
Allow Apache HTTP service port in Linux firewall.
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
Browse URL http://170.172.0.30 to see the Apache HTTP Server’s default webpage.

Apache HTTP server has been installed on our Linux server.
ASUS ROG Strix G16 (2025) Gaming Laptop, 16” FHD+ 16:10 165Hz/3ms Display, NVIDIA® GeForce RTX™ 5060 Laptop GPU, Intel® Core™ i7 Processor 14650HX, 16GB DDR5, 1TB Gen 4 SSD, Wi-Fi 7, Windows 11 Home
15% OffInstall MySQL Database Server on Linux:
For database component of LAMP stack, we have many choices like MySQL, MariaDB or PerconaDB. Here, we will install MySQL database server.
Go to MySQL:: Download MySQL Yum Repository to download and install the MySQL official yum repository.
cd /soft
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
rpm -Uvh mysql57-community-release-el7-7.noarch.rpm
yum clean all
yum makecache
Install the latest version of mysql-community-server. In our case, it installed mysql-community-server 5.7, which is latest at the time of this writeup.
yum install -y mysql-server
Start and enable the mysqld service.
systemctl enable mysqld.service
systemctl start mysqld.service
When mysqld service starts for the first time, it generates a random password for root@localhost user in /var/log/mysqld.log file. Use the following command to get it.
grep 'temporary password' /var/log/mysqld.log
Configure the mysql security using following command.
/usr/bin/mysql_secure_installation
and select the following options.
set a password for root remove anonymous users: Y Disallow remote Root Login: Y Remove Test Database and access to it: Y Reload Privilege tables: Y
MySQL database server has been installed and configured on our Linux server.
Philips Norelco OneBlade Anti Friction Blade, Genuine Replacement Blade for OneBlade Electric Shaver and Trimmer, Durable Stainless Steel, Trim, Edge and Shave, 2 Pack, QP225/80
$24.96 ($12.48 / Count) (as of August 30, 2025 19:58 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Install PHP on CentOS 7:
PHP is the hypertext preprocessor and it adds the application functionality in our LAMP server.
Use the following command to install PHP from CentOS yum Repository. In our case, it installed PHP 5.4. Although, stable version 7 of PHP is available at this time. If you want to use a latest version than you can download it from http://www.php.net
yum install -y php
Depends upon your web application, you may required to install specific php modules on the server. To see the compatible modules for your php server use the following command:
yum search php-
Install required php modules as follows:
yum install -y php-mysql
Restart the httpd Service to load the php modules.
systemctl restart httpd.service
Create the test page for php at document root of Apache Server.
cat >> /var/www/html/info.php << EOF
<?php phpinfo(); ?>
EOF
Browse URL http://170.172.0.30/info.php. It will show you a very long page with useful information that may be helpful during troubleshooting of your LAMP server.

Master Apache Web Server from scratch and boost your web hosting skills with our comprehensive online course!

Conclusion – Install LAMP on CentOS 7:
In conclusion, to install LAMP stack on CentOS 7 is a vital step in setting up a robust environment for hosting dynamic websites and applications. By configuring Apache, MySQL, and PHP, you create a powerful foundation for web development. With proper setup and optimization, your CentOS 7 server can efficiently handle web applications, ensuring stability, security, and performance.
From setting up scalable AWS solutions to managing complex Linux environments, I’ve got you covered. Visit my Freelancer profile to get started.
Leave a Reply
Please log in to post a comment.