Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Install PHP 7 on CentOS 7

Rumi, May 24, 2020

Enabling Remi repository

PHP 7.x packages are available in several different repositories. We’ll use the Remi repository which provides newer versions of various software packages including PHP.

The Remi repository depends on the EPEL repository. Run the following commands to enable both EPEL and Remi repositories:

sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Yum may prompt you to import the repository GPG key. Type y and hit Enter.

In the following sections, we will be covering how to install PHP 7.x by enabling the appropriate Remi repository. If you already have PHP 5.4 installed on your system yum will update the PHP packages.

Installing PHP 7.3 on CentOS 7

PHP 7.3 is the latest stable release of PHP. Most modern PHP frameworks and applications including WordPress, Drupal, Joomla, and Laravel are fully supporting PHP 7.3.

Perform the steps below to install PHP 7.3 on CentOS 7.

Start by enabling the PHP 7.3 Remi repository:

sudo yum-config-manager --enable remi-php73

Install PHP 7.3 and some of the most common PHP modules:

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

Verify the PHP installation, by typing the following command which will print the PHP version:

php -v
PHP 7.3.1 (cli) (built: Jan 8 2019 13:55:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies

Installing PHP 7.2 on CentOS 7

Use PHP 7.2 only if you’re going to install applications such as Magento 2 that is not compatible with PHP 7.2.

The following steps describe how to install PHP 7.2 CentOS 7.

First enable the PHP 7.2 Remi repository by running the following command:

sudo yum-config-manager --enable remi-php72

Once the repository is enabled install PHP 7.2 and few most common PHP modules:

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

Verify the PHP installation:

php -v
PHP 7.2.9 (cli) (built: Aug 15 2018 09:19:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.9, Copyright (c) 1999-2018, by Zend Technologies

Installing PHP 7.1 on CentOS 7

Follow the steps below to install PHP 7.1.

Enable the PHP 7.1 repository by typing:

sudo yum-config-manager --enable remi-php71

Install PHP 7.1 and few most common PHP modules:

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql

To verify the installation, run the following command which will print the PHP version:

php -v
PHP 7.1.21 (cli) (built: Aug 15 2018 17:56:55) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.21, Copyright (c) 1999-2018, by Zend Technologies

Configuring PHP 7.x to work with Apache

If you are using Apache as your web server then just restart the Apache service using the following command and you are good to go:

sudo systemctl restart httpd

Configuring PHP 7.x to work with Nginx

Unlike Apache, Nginx doesn’t have built-in support for processing PHP files so we need to install a separate application such as PHP FPM which will handle the PHP files.

To install the PHP FPM package run the following command:

sudo yum install php-fpm

By default PHP FPM will run as user apache on port 9000. We’ll change the user to nginx and switch from TCP socket to Unix socket. To do so edit the lines highlighted in yellow:

/etc/php-fpm.d/www.conf
...
user = nginx
...
group = nginx
...
listen = /run/php-fpm/www.sock
...
listen.owner = nginx
listen.group = nginx

Make sure the /var/lib/php directory has the correct ownership:

chown -R root:nginx /var/lib/php

Once you made the changes, enable and start the PHP FPM service:

sudo systemctl enable php-fpmsudo systemctl start php-fpm

Next, edit the Nginx virtual host directive and add the following location block so that Nginx can process PHP files:

server {

# . . . other code

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

For the new configuration to take effect, restart the Nginx service:

sudo systemctl restart nginx

Conclusion

You have learned how to install PHP 7 on your CentOS server and how to configure your web server to be able to handle PHP files.

Src: https://linuxize.com/post/install-php-7-on-centos-7/

Administrations Collected Articles Configurations (Linux) CentOS 7PHP 7.1PHP 7.2PHP 7.3

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

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

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes