This guide will show you how to install or upgrade latest release of PHP on Fedora, RHEL and CentOS.
Note: On CentOS/RHEL 8, yum command has been replaced with dnf and in near future yum package manager will be discontinued. It is now recommended to use dnf for installing packages on CentOS/RHEL 8 but if you still wish to use yum you can use it.
Adding EPEL/Remi Repository
If you are on Fedora, standards repositories are enough, you can directly install or upgrade PHP version. For (RHEL, CentOS) the Extra Packages for Enterprise Linux (EPEL) repository must be configured before proceeding to install, and on RHEL the optional channel must also be enabled.
For CentOS 8
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf config-manager --set-enabled PowerTools
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf config-manager --set-enabled remi
For RHEL 8
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
ARCH=$( /bin/arch )
sudo dnf config-manager --set-enabled PowerTools
subscription-manager repos --enable "codeready-builder-for-rhel-8-${ARCH}-rpms"
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf config-manager --set-enabled remi
For CentOS 7.6
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
For RHEL 7.6
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo subscription-manager repos --enable=rhel-7-server-optional-rpms
For CentOS 6.10
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-6.rpm
For RHEL 6.10
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-6.rpm
rhn-channel --add --channel=rhel-$(uname -i)-server-optional-6
For Fedora 29
sudo dnf -y install http://rpms.remirepo.net/fedora/remi-release-29.rpm
For Fedora 28
sudo dnf -y install http://rpms.remirepo.net/fedora/remi-release-28.rpm
Installing PHP
For CentOS/RHEL 8, you can install any version of php with below command:
sudo dnf -y install php70
sudo dnf -y install php71
sudo dnf -y install php72
sudo dnf -y install php73
sudo dnf -y install php74
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
For CentOS/RHEL 7, you can install any version of php with below command:
sudo yum -y install php70
sudo yum -y install php71
sudo yum -y install php72
sudo yum -y install php73
sudo yum -y install php74
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
For CentOS/RHEL 6, you can install any version of php with below command:
sudo yum -y install php70
sudo yum -y install php71
sudo yum -y install php72
sudo yum -y install php73
sudo yum -y install php74
service start php-fpm
For Fedora, you can install any version of php with below command:
sudo dnf -y install dnf-plugins-core
sudo dnf -y install php70
sudo dnf -y install php71
sudo dnf -y install php72
sudo dnf -y install php73
sudo dnf -y install php74
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
We hope this guide was helpful.