How do I install PHP 5.6 and Apache in RHEL 7.2?

By default, RHEL 7.2 includes only php5.4 and php5.5. In order to use php5.6, use the RHSCL repos and manually configure httpd.conf to use them.

Because RHEL does not support mod_php with php5.6, you must use php-fpm and run it though mod_proxy_fcgi.

sudo yum update rh-amazon-rhui-client.noarch

sudo yum-config-manager --enable rhui-REGION-rhel-server-rhscl

sudo yum install httpd rh-php56 rh-php56-php rh-php56-php-fpm

To install other modules (for example, the php-mysql module), you can search and install them by using commands similar to the following:

sudo yum search rh-php56

sudo yum install rh-php56-php-mysql

sudo systemctl start rh-php56-php-fpm.service

sudo systemctl status rh-php56-php-fpm.service

sudo vi /etc/httpd/conf/httpd.conf

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

<IfModule proxy_module>

  ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://$1


Use the :wq command to save your configuration.

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

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

sudo systemctl restart httpd.service

sudo systemctl status httpd.service

sudo vi /var/www/html/info.php

Add the following content to the new file:

<?php phpinfo(); ?>

Use the :wq command to save your configuration.

To verify that your configuration was loaded successfully, locate your instance’s public IP address in the EC2 management console. Open a browser on the instance, and navigate to http://<public ip address of the instance>/info.php.

Note: If the page fails to load, make sure that the security group associated with the instance allows inbound traffic on port 80.

When you’ve verified it is working, you can set Apache and php-fpm to start on boot by running the following commands:

sudo systemctl enable httpd.service

sudo systemctl enable rh-php56-php-fpm.service

PHP, RHEL, Apache, php56, httpd, RHSCL, RHEL7

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2016-09-09