LAMP stands for Linux, Apache, MySQL and PHP. Its is used for hosting websites written with PHP programming language and using MySQL as backend database server. This article will help you to install LAMP stack (Apache 2.4, MySQL 5.6, and PHP 5.4) on CentOS 7 and RedHat 7 systems. You may also use video tutorial on Youtube for installation instruction’s.
Step 1 – Enable Yum Repository
The two most popular rpm repositories REMI and EPEL have most of the updated packages. They are also providing the latest packages for LAMP setup. Enable both repositories on your system using the following commands on your CentOS 7 system.
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Step 2 – Install Apache Server
Apache or HTTPD is the most popular web server used on Linux based systems. Let’s install Apache web server using the following command by enabling EPEL and REMI yum repositories.
yum --enablerepo= epel,remiinstall httpd
Now start httpd service and enable to start on boot using below commands.
systemctl starthttpd.service systemctl enablehttpd.service
Step 3 – Install MySQL Server
First add MySQL yum repository in your system using the following command. You may also visit repo.mysql.com to find repository rpms for other operating systems. The below command will work with CentOS and RedHat 7.
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Now install MySQL server and other dependency packages.
The installer generated a temporary password for MySQL root user and copied to log file. You can find this password using the below command.
# grep "A temporary password" /var/log/mysqld.log | tail -n1 2017-10-31T09:31:14.642207Z 1 [Note] A temporary password is generated for [email protected]:
Apply security on newly installed MySQL server. This will also prompt you to change the temporary password with new password.
systemctl startmysqld.service mysql_secure_installation
Now restart MySQL service and enable to start on system boot.
systemctl restartmysqld.service systemctl enablemysqld.service
Step 4 – Install PHP
Now install php packages with enabling epel and remi repositories using following command.
yum --enablerepo= epel,remi-php71install php
Now install required php modules. Use following command to list available modules and install it.
yum --enablerepo= epel,remi-php71list php-* yum installphp-mysql php-xml php-xmlrpc php-soap php-pgsql php-gd
After installing php and other php modules restart Apache service.
Step 5 – Allow Port in Firewall
Finally open firewall ports for HTTP (80) and HTTPS (443) services using the following command.
firewall-cmd --permanent --zone=public --add-service= http firewall-cmd --permanent --zone=public --add-service= https firewall-cmd --reload
Step 6 – Check Installed Version
Let’s check the installed versions of packages on the system using following commands one by one.
php -vPHP 7.1.11 (cli) (built: Oct 25 2017 10:24:28) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
httpd -vServer version: Apache/2.4.6 (CentOS) Server built: Oct 19 2017 20:39:16
mysql -Vmysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper
Now you have successfully configured LAMP setup on your CentOS or RedHat 7 system.