How to Install PHP 7.x on CentOS 7

Updated on March 9, 2017
How to Install PHP 7.x on CentOS 7 header image

In this article, we will outline the process of installing PHP 7.x on CentOS 7 Server.


Step 1: Setup the Webtatic YUM repo

Precompiled PHP 7.x binaries are available for CentOS 7 from the Webtatic, IUS, or Remi's RPM repositories.

Below are instructions on installing PHP 7.x using the Webtatic YUM repo.

Setup the Webtatic YUM repo:

sudo rpm -Uvh
sudo rpm -Uvh

Step 2: Install PHP 7.1 and necessary extensions

Install PHP 7.1 and some of the most commonly used extensions:

sudo yum install -y mod_php71w php71w-cli php71w-common php71w-gd php71w-mbstring php71w-mcrypt php71w-mysqlnd php71w-xml

Note: The above packages are for general purpose use and may not suit your specific requirements. You should confirm the packages to be installed referring to the Webtatic PHP 7.1 introduction page.

Alternatively, if you want to install PHP 7.0, you should refer to Webtatic PHP 7.0 introduction page.

Step 3: configure PHP 7.x

After the installation, the PHP 7.x configuration file will be saved as /etc/php.ini. If necessary, you can use the vi text editor to modify it:

sudo cp /etc/php.ini /etc/php.ini.bak
sudo vi /etc/php.ini

Remember to restart your web server after modifying the /etc/php.ini file.

For Apache:

sudo systemctl restart httpd.service

For Nginx:

sudo systemctl restart nginx.service php-fpm.service

That's it. Thanks for reading.