How to install PHP 5.6 and Apache in Redhat 7.2

The Apache is an free and open-source cross-platform HTTP Server, Apache web servers are used to serve Web pages requested by client browser, Developed and maintained by Apache Software Foundation.

PHP is a serverside programming language and PHP designed for web development, Developer by The PHP Development Team, Zend Technologies, Click here for more details.

Step 1: Need to enable the RHSCL repo as a source and install the php5.6 packages with httpd  by using the following commands:

[root@localhost ~]# yum update

[root@localhost ~]# yum-config-manager –enable rhui-REGION-rhel-server-rhscl

[root@localhost ~]# yum -y install httpd rh-php56 rh-php56-php rh-php56-php-fpm

Step 2: To install another module like php-mysql module, need to search and install them by using  the following commands:

[root@localhost ~]# yum search rh-php56 && yum install rh-php56-php-mysql -y

Step 3: Now need to start and enable  rh-php56-php-fpm by  using the following commands:

[root@localhost ~]# systemctl start rh-php56-php-fpm && systemctl status rh-php56-php-fpm

Step 4: Need to modify httpd conf to enable mod_proxy_fcgi to work with php-fpm by using the following command:

[root@localhost ~]# nano /etc/httpd/conf/httpd.conf

Add the following before IncludeOptional conf.d/*.conf:

<IfModule proxy_module>

ProxyPassMatch ^/(.*.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1

</IfModule>

Save and exit from nano editor

PHP-FPM runs under 127.0.0.1:9000 by default. To process all php files in your root web folder, use an address similar to the following:

fcgi://127.0.0.1:9000/<root folder of your website application>/$1

Step 5: Restart httpd and check its status by using the following commands:

[root@localhost ~]# systemctl restart httpd && systemctl status httpd

Now need to test PHP is working or not to get complete information about PHP, need to create a file with PHP extension.

[root@localhost ~]# echo “<?php phpinfo(); ?>” > /var/www/html/info.php

To verify PHP version browser again URL ( http://server_IP/info.php )

After that need to delete info.php file from /var/www/html

after test PHP web page, need to remove that file by using the following commands:

[root@localhost ~]# rm -rf /var/www/html/info.php

Step 6: When you have verified it is working, you can enable httpd and php-fpm to start on boot by using the following commands:

[root@localhost ~]# systemctl enable rh-php56-php-fpm.service && systemctl enable httpd

Now PHP 5.6 installation is completed.

How to install PHP 5.6 and Apache in Redhat 7.2

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top