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 will help you to install LAMP stack (Apache 2.4, MySQL 8 and PHP 7.1/7.2/7.3) on CentOS 7
Step 1 – Prerequisites
Adding EPEL repo here to install required packages
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
# yum -y install epel-release
Step 2 – Install Apache
# yum -y install httpd*
Now start httpd service and enable on boot using below commands.
# systemctl start httpd
# systemctl enable httpd
Step 3 – Install MySQL Server
First we need to add mysql community repository to install mysql.For reference visit repo.mysql.com repository to download latest rpms for any other OS.
# rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
Default mysql repository is enabled and ready for installation.
# yum -y install mysql-server
===============================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================
Installing:
mysql-community-server x86_64 8.0.16-2.el7 mysql80-community 403 M
Installing for dependencies:
mysql-community-client x86_64 8.0.16-2.el7 mysql80-community 32 M
mysql-community-common x86_64 8.0.16-2.el7 mysql80-community 575 k
mysql-community-libs x86_64 8.0.16-2.el7 mysql80-community 3.0 M
Transaction Summary
===============================================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
once it is installed start and enable mysql service with below commands.
# systemctl start mysqld
# systemctl enable mysqld
Apply security on newly installed MySQL server. This will also prompt you to change the temporary password with a new password.
# grep "A temporary password" /var/log/mysqld.log
# mysql_secure_installation
Change the password for root? - y
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.Next we will install php
Step 4 – Install PHP
The PHP version that comes with CentOS as default is quite old (PHP 5.4).Here we will install latest versions using Remi repository.
Add the Remi CentOS repository as below
# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install yum-utils as we need the yum-config-manager utility.
# yum -y install yum-utils
For php 7.0
# yum-config-manager --enable remi-php70
For php 7.1
# yum-config-manager --enable remi-php71
For php 7.2
# yum-config-manager --enable remi-php72
For php 7.3
# yum-config-manager --enable remi-php73
select one of the version from above and enable remi repo and install php
# yum -y install php php-devel php-gd php-bcmath php-pdo php-mcrypt php-tidy php-mysql php-xml php-soap php-imap php-pgsql php-mbstring
After installing php along with modules you must restart Apache service
# systemctl restart httpd
Step 5 - Testing PHP
The document root of the default website is /var/www/html. We will create a small PHP file (info.php) in that directory and call it in a browser to test the PHP installation.
# vi /var/www/html/info.php
Now we call that file in a browser (e.g. 192.168.0.20/info.php):