The PHP team has released upgrade version 7.2. Which has a number of changes and improvements than over version 5.X. This article will help you to install PHP 7 Apache 2.4 and MySQL 5.6 on CentOS/RHEL 7 & 6 operating systems. This tutorial has been tested with CentOS 7.4, so all the services command are used with systemctl. The CentOS 6 users change all systemctl command correspondence service command.
Step 1 – Setup Yum Repository
In the first step install all the required yum repositories in your system used in the remaining tutorial for various installations. You are adding REMI, EPEL, Webtatic & MySQL community server repositories in your system.
CentOS / RHEL 7
yum install epel-release rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-7.noarch.rpm
CentOS / RHEL 6
yum install epel-release rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Step 2 – Install PHP 7.2
Now install php 7 packages from webtatic rpm repository using following command.
yum --enablerepo=remi-php72 install php
Now install required php modules. Use following command to list available modules in yum repositories.
yum --enablerepo=remi-php72 search php
Now check all listed modules in above command and install required modules like below.
yum --enablerepo=remi-php72 install php-mysql php-xml \ php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
Step 3 – Install Apache 2.4
Apache (HTTPD) is the most popular web server used on Linux systems. Let’s install Apache web server using following command with 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 4 – Install MySQL 5.6
In step 1 we already have installed required yum repository in your system. Let’s use the following command to install MySQL server on your system. If you want to install MySQL 5.7 visit this tutorial.
Apply security on mysql and also set root user 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 5 – Open 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 system using following commands one by one.
php -vPHP 7.2.0 (cli) (built: Nov 28 2017 20:22:21) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies httpd -vServer version: Apache/2.4.6(CentOS) Server built: Nov 19 2015 21:43:13 mysql -Vmysql Ver 14.14 Distrib 5.6.28, for Linux (x86_64) using EditLine wrapper
Now you have successfully configured LAMP setup on your CentOS / RHEL 7.4 & 6.9 systems.
I am getting below error:
Can you help me.
checking for APR… configure: WARNING: APR version 1.4.0 or later is required, found 1.3.9
configure: WARNING: skipped APR at apr-1-config, version not acceptable
Absolutely does not work on Centos/RHEL version 6.x unless you compile php from source. All the repos I’ve found compile php7.x against Apache2.2 and when you try to run with 2.4 it fails because it calls unixd in the php module, which is deprecated in 2.4
thanks Rahul K great work
Should I add any config to httpd.conf?
Apache downloads php files instead of displaying it!
Hello! thanks you how-to!
on topic 3 ( # systemctl enabel httpd.service ) enabled is typed wrong!
Thanks you very much.
This won’t work for Centos 6, just as it’s never worked before.
Neither remi or epel offer a php-package without forcing the installation of apache 2.2 from base.
Anyone know of a repo that offers both apache 2.4 and a php >= 5.6 for Centos 6?
yum –enablerepo=epel,remi install httpd
the above installed Apache 2.2 for me. I could get 2.4 to install via epel’s httpd24 package, however the php70w package is compiled for 2.2 and therefore errors out when php tries to hit the old apache apis.
Same issue as you described here!
A bit late but you can use the ius-release.rpm or centos-release-scl repositories. (Google them for rpm/install commands) SCL allows for both Apache 2.2 and 2.4 to be installed without conflict, while IUS will conflict with the core binary dependencies.