Install Apache HTTP server and PHP
4 minute read
Install dependencies from RedHat Software Collections (RHSCL) on RHEL 7
On a Red Hat Enterprise Linux (RHEL7) installation, the default PHP version available in the official repository is 5.4. However, API Portal only supports PHP 7.1+. You can use RedHat Software Collections (RHSCL) to install PHP 7.1+.
Enable RedHat Software Collections
Before installing Apache HTTP server and PHP you must first enable RHSCL:
sudo subscription-manager repos --enable rhel-server-rhscl-7-rpms
sudo yum clean all
Install Apache HTTP server on RHEL7
-
Install Apache from RHSCL:
sudo yum install httpd24-httpd httpd24-httpd-tools httpd24-mod_ssl
-
Make Apache available in any bash session by default:
echo "source scl_source enable httpd24" | sudo tee -a /etc/profile.d/scl-httpd24.sh source /etc/profile.d/scl-httpd24.sh sudo ln -s $(which httpd) /usr/bin/httpd
-
Verify Apache is now available:
httpd -v
-
Enable and start Apache service:
sudo systemctl enable --now httpd24-httpd
-
Verify that Apache service is active and running:
systemctl status httpd24-httpd
Install PHP on RHEL7
You must install the latest PHP version provided by the RHSCL.
-
Install all required PHP packages:
sudo yum install rh-php73 rh-php73-php rh-php73-php-cli rh-php73-php-common rh-php73-php-gd rh-php73-php-json rh-php73-php-intl rh-php73-php-mbstring rh-php73-php-mysqlnd rh-php73-php-pdo rh-php73-php-xml rh-php73-php-zip
-
Enable PHP in bash:
echo "source scl_source enable rh-php73" | sudo tee -a /etc/profile.d/scl-rh-php73.sh source /etc/profile.d/scl-rh-php73.sh sudo ln -s $(which php) /usr/bin/php
-
Verify that PHP is available:
php -v
-
Verify that
php7_module
is enabled in Apache:httpd -M | grep php7
-
Restart Apache and verify it is running:
sudo systemctl restart httpd24-httpd systemctl status httpd24-httpd
Upgrade PHP
If you already have PHP 5.4 or earlier and API Portal 7.7 or earlier installed, you cannot uninstall the old PHP version due to a dependency in API Portal. Perform the steps in Install PHP on RHEL7 and leave the old PHP version installed. If there is already a symbolic link to the old PHP version, update it with the new location of PHP (for example, using ln -sf
instead of ln -s
).
Install dependencies from community repository EPEL with Remi for RHEL 8 and CentOS 7/8
RHEL 8 and CentOS do not offer the latest PHP version in the default repositories. To install the latest PHP, we recommend using the Extra Packages for Enterprise Linux (EPEL) repository.
Enable EPEL with Remi
To install and enable EPEL with Remi:
# for CentOS 7
sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-$(rpm -E '%{rhel}').rpm
# for CentOS 8
sudo dnf install epel-release yum-utils
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-$(rpm -E '%{rhel}').rpm
sudo dnf update
# for RHEL 8
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm
sudo subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E '%{rhel}').rpm
sudo dnf install dnf-utils
Install Apache HTTP server on CentOS/RHEL 8
-
Install Apache HTTP Server and its SSL module:
# for CentOS 7 sudo yum install httpd mod_ssl
# for CentOS 8 / RHEL 8 sudo dnf install httpd mod_ssl
-
Enable and start the Apache service:
# for CentOS 7/8 and RHEL 8 sudo systemctl enable --now httpd
If you get the error message:
SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty
you can resolve it by generating a self-signed certificate:openssl req -newkey rsa:4096 -x509 -sha256 -days 3600 -nodes \ -out "/etc/pki/tls/certs/localhost.crt" \ -keyout "/etc/pki/tls/private/localhost.key"
Then, run
sudo systemctl enable --now httpd
again. -
Verify that Apache service is active and running:
# for CentOS 7/8 and RHEL 8 systemctl status httpd
-
Open the TCP port 80 and 443 in the local firewall
# for CentOS 7/8 and RHEL 8 sudo firewall-cmd --permanent --add-port=80/tcp sudo firewall-cmd --permanent --add-port=443/tcp sudo firewall-cmd --reload
Install PHP on CentOS and RHEL 8
-
Install PHP:
# for CentOS 7 sudo yum-config-manager --enable remi-php74 sudo yum install php php-cli php-common php-gd php-json php-intl php-mbstring php-mysqlnd php-pdo php-xml php-pecl-zip
# for CentOS 8 sudo dnf module reset php sudo dnf module install php:remi-7.4 sudo dnf install php php-cli php-common php-gd php-json php-intl php-mbstring php-mysqlnd php-pdo php-xml php-pecl-zip
# for RHEL 8 sudo dnf module reset php sudo dnf module install php:remi-7.4 sudo dnf install php php-cli php-common php-gd php-json php-intl php-mbstring php-mysqli php-openssl php-pdo php-xml php-zip
-
Verify that PHP was installed. If the command fails, restart the bash session:
# for CentOS 7/8 and RHEL 8 php -v
-
Locate the
mpm
configuration file and make sure that lineLoadModule mpm_prefork_module modules/mod_mpm_prefork.so
is uncommented and all the other lines are commented out.# for CentOS 7/8 and RHEL 8 find /etc/httpd -name '*-mpm.conf'
-
Verify that
php7_module
of Apache is enabled:# for CentOS 7/8 and RHEL 8 httpd -M | grep php7
-
Restart Apache and verify that it is working:
# for CentOS 7/8 and RHEL 8 sudo systemctl restart httpd systemctl status httpd
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.