Apache

How to Install Apache and PHP 7 on CentOS, RHEL and Fedora Systems

If you are planning to setup a PHP application with Apache web server this article will help to install Apache web server and PHP on your CentOS, RHEL and Fedora systems.

In this article I will show how you can install PHP 7 and Apache on CentOS, RHEL and Fedora systems.

Install Apache and PHP 7

Follow the below steps to install Apache and PHP 7 on CentOS, RHEL and Fedora systems.

Step #1 : Install EPEL and REMI Repository

First of all install required repository to install apache and php 7.

On CentOS 7 and RHEL 7

# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

On CentOS 6 and 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.rpm

On Fedora 26

# 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-26.rpm

On Fedora 25
# 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-25.rpm

On Fedora 24

# 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-24.rpm

Step #2 : Install Apache and PHP 7

Once enabling the required repository on your system, now install apache and PHP 7 on your system. Follow the below command to install apache and php.

On CentOS and RHEL

$ sudo yum --enablerepo=remi,remi-php71 install httpd php php-common

On Fedora 26

$ sudo dnf --enablerepo=remi install httpd php php-common

On Fedora 25/24

# sudo dnf --enablerepo=remi --enablerepo=remi-php71 install httpd php php-common

Step #3 : Install PHP Modules

To setup a php application you will need to install required PHP modules for your application. Follow the below command to install php modules.

On CentOS and RHEL

# sudo yum --enablerepo=remi,remi-php71 install php-cli php-pear php-pdo php-mysqlnd php-pgsql php-gd php-mbstring php-mcrypt php-xml

On Fedora 26

# sudo dnf  --enablerepo=remi install php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml

On Fedora 25/24

# sudo dnf --enablerepo=remi --enablerepo=remi-php71 install php-cli php-pear php-pdo php-gd php-mbstring php-mcrypt php-xml

Step #4 : Restart Apache Service

After installing PHP, PHP modules and Apache web server now restart the apache web service and enable to auto start at boot time.

For CentOS/RHEL 7 and Fedora 26/25/24

# sudo systemctl start httpd.service 
# sudo systemctl enable httpd.service

For CentOS/RHEL 6

# service httpd start 
# chkconfig --levels 235 httpd on

Congratulation!, you have successfully configured php application on CentOS, RHEL and Fedora system.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment