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 Apache 2.4, MySQL 8 and PHP 7.3 on CentOS 7 and RedHat 7 systems. You may also use video tutorial on Youtube for installation instruction’s.
Step 1 – Prerequsitis
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 HTTP 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,remi install httpd
Now start httpd service and enable to start on boot using commands.
systemctl enable httpd.service systemctl start httpd.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 https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
The default MySQL 8 repository is enabled for installation. To change edit repository configuration file (/etc/yum.repos.d/mysql-community.repo) and enable/disable repositories as per requirements.
Then install the MySQL server and other dependency packages.
yum install mysql-server
After installation enable MySQL service and start it.
systemctl enable mysqld.service systemctl start mysqld.service
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 [Some text hidden] A temporary password is generated for root@localhost: Eif;=YpBy2h#
Apply security on newly installed MySQL server. This will also prompt you to change the temporary password with a new password.
Enter password for user root: [Enter password here found in log file]
The existing password for the user account root has expired. Please set a new password.New password: [Enter new password] Re-enter new password: [Re-enter new password] Change the password for root? - n Remove anonymous users? - y Disallow root login remotely? - y Remove test database and access to it? - y Reload privilege tables now? - y
MySQL has been installed on your system. After this install PHP.
Step 4 – Install PHP
Now, install PHP packages with enabling EPEL and REMI repositories using the following command.
yum --enablerepo=epel,remi-php74 install php
Then install required PHP modules. Use the following command to list available modules and install it.
yum --enablerepo=remi-php74 list php-* yum --enablerepo=remi-php74 install php-mysql php-xml php-xmlrpc php-soap php-gd
After installing php and other php modules restart Apache service.
systemctl restart httpd.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 -v PHP 7.4.5 (cli) (built: Apr 14 2020 12:54:33) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies
httpd -v Server version: Apache/2.4.6 (CentOS) Server built: Aug 8 2019 11:41:18
mysql -V mysql Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
Now you have successfully configured LAMP setup on your CentOS or RedHat 7 system.