Install PHP 7 on CentOS 7 using REMI repo
Install PHP 7 on CentOS 7 using REMI repository is our next short tutorial where we will show you briefly how to install PHP 7 (php-fpm) on CentOS 7. It is true that by using container technologies like Docker for this particular task would be indeed more easy and handy for most of us but maybe from time to time we have to install PHP manually, maybe for a specific project on one of our servers or maybe just for fun. No worries we will be covering PHP 7 (php-fpm) setup on Docker in another tutorial shortly but for now we will guide you how to install it on a classic VM machine and we promise that we will keep this as short as possible without missing anything essential in terms of installation steps that may lead you into confusion.
Table of contents
Install packages
Enable remi repo and update
Install PHP 7 (php73-php-fpm)
Check PHP-FPM service
Enable and start PHP-FPM service
Check PHP version
Troubleshooting
Install packages
On our very first step with this PHP 7 setup tutorial we have to install epel-release
repository and also yum-utils
utilities package, both these so called base-packages in our tutorial will be later used within our setup steps for PHP 7.
$ yum install -y epel-release yum-utils
Once epel-release
repository and yum-utils
package installation is completed then we may proceed with remi
repository installation like shown in the example below:
$ yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Enable remi repo and update
In this step we need to enable remi-php73
but you may change this to reflect your desired PHP version:
$ yum-config-manager --enable remi-php73
Best practice says that we should always update our system software, making sure this way that we are using latest packages available, features and security patches:
$ yum update
Install PHP 7 (php73-php-fpm)
Now that we have everything in place we can start installing php73-php-fpm
package like shown below, so please use this command on your terminal window and wait for the entire process to finish the installation for you:
$ yum install php73-php-fpm
PHP 7 installation on CentOS 7 using REMI repository is now completed, lets move to our next step where we need to check and start php-fpm
service.
Check PHP-FPM service
Let’s check if php73-php-fpm
is indeed installed onto our VM by using the next command:
$ systemctl status php73-php-fpm
If you get a similar output then we can say that the installation was successful even though it says that its status is Active: inactive (dead)
, that is expected as it hasn’t been started yet but is present:
● php73-php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php73-php-fpm.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Enable and start PHP-FPM service
With a single command line within our terminal window we will now enable and start the service:
$ systemctl enable php73-php-fpm && systemctl start php73-php-fpm
Let’s run again the status
command:
$ systemctl status php73-php-fpm
If you see Status: "Ready to handle connections"
on your terminal window like shown below then we can say that our PHP 7 installation is not only successful but we have an active service.
● php73-php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php73-php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-05-14 14:18:06 UTC; 9s ago
Main PID: 16205 (php-fpm)
Status: "Ready to handle connections"
CGroup: /system.slice/php73-php-fpm.service
├─16205 php-fpm: master process (/etc/opt/remi/php73/php-fpm.conf)
├─16206 php-fpm: pool www
├─16207 php-fpm: pool www
├─16208 php-fpm: pool www
├─16209 php-fpm: pool www
└─16210 php-fpm: pool www
May 14 14:18:06 mny-aws-euw1-pvm-app001 systemd[1]: Starting The PHP FastCGI Process Manager...
May 14 14:18:06 mny-aws-euw1-pvm-app001 systemd[1]: Started The PHP FastCGI Process Manager.
Check PHP version
Let’s check PHP version via CLI using this command:
$ php -v
We can clearly see in the output below that PHP that is running on our VM machine is 7.3.5
.
PHP 7.3.5 (cli) (built: Apr 30 2019 08:37:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
We are now done, PHP has been installed using REMI repository and is ready to use.
Troubleshooting
If we don’t get the right output when using php -v
command like for example:
-bash: php: command not found
An easy fix for this issue when using CentOS 7 is to place a symlink between default installation folder for PHP and /usr/bin
like this:
$ ln -s /opt/remi/php73/root/sbin/php-fpm /usr/bin/php
Now let’s try again:
$ php -v
There it is, our fix worked like a charm:
PHP 7.3.5 (fpm-fcgi) (built: Apr 30 2019 08:37:17)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies