How to Install Apache/PHP 7 on CentOS/RHEL 7.6/6.9 and Fedora 31/30
Abstract: Step 2 – Install Apache/PHP After enabling the required yum repositories on your system. Now install the Apache and PHP packages on your system. This
Are you planning to deploy a PHP application with the Apache webserver? This tutorial will help you with installing Apache web server and PHP on your CentOS, Redhat, and Fedora systems.
Recommended Article:
First of all, you need to add some required rpm repositories on your system. Use one of the below commands as per your operating systems.
On CentOS/RHEL 7rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpmOn CentOS/RHEL 6
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpmOn Fedora 31
sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm sudo dnf install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm sudo dnf install http://rpms.famillecollet.com/fedora/remi-release-31.rpmOn Fedora 30
sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm sudo dnf install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm sudo dnf install http://rpms.famillecollet.com/fedora/remi-release-30.rpmOn Fedora 29
sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm sudo dnf install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm sudo dnf install http://rpms.famillecollet.com/fedora/remi-release-29.rpmStep 2 – Install Apache/PHP
After enabling the required yum repositories on your system. Now install the Apache and PHP packages on your system. This will install the latest available packages on your system.
For CentOS and RHEL 7/6
sudo yum --enablerepo=remi,remi-php71 install httpd php php-common
For Fedora 31/30/29/28/27/26
sudo dnf --enablerepo=remi install httpd php php-commonStep 3 – Install PHP Modules
You also required installing PHP modules required for your application. The below command will install some frequently used PHP modules on your system. You may install any other modules with the same command.
For CentOS and RHEL 7/6
sudo yum --enablerepo=remi,remi-php71 install php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml
For Fedora 31/30/29/28/27/26
sudo dnf --enablerepo=remi install php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xmlStep 4 – Manage Apache Service
At this point, your system has installed the Apache web server, PHP, and modules. Now start the Apache server and also enable them to autostart on system boot.
For CentOS/RHEL 7 and Fedora
sudo systemctl start httpd.service sudo systemctl enable httpd.service
For CentOS/RHEL 6
service httpd start chkconfig --levels 235 httpd on
As a result of this tutorial, you have successfully configured a web hosting environment on your Red Hat-based system.
Recommended Article: