While I was performing an audit on the articles I have posted and checking to see if they still work after more than a year, I noticed that in the installation of a WordPress article that I made an error where users may face the error of below-supported version of PHP. It means, WordPress throws an error stating to install at least above PHP 5.6 version which isn’t covered in the article.
So we decided to make a separate article on how to install latest PHP version in CentOS 7. Don’t worry, you do not need to reinstall your operating system to install the latest version. We will also cover how to upgrade the lower versions of PHP in this article. So let’s get started.
- This article is tested on CentOS 7.6. It should also work on CentOS 7.3.
- Atleast 512 MB of RAM for a fast and seamless installation.
- Atleast 10 GB of disk space to avoid any lag or unnecessary system crash due to insufficient space.
- Root access to the server/machine
Step 1 – Installing necessary packages to begin with
The latest PHP version at the time of writing this article is 8.0. But this article is dedicated to PHP 7.4, which is PHP 7’s current stable version. We will cover the article on PHP 8 in the future. The article will be linked in Conclusion at the bottom of this article. To install PHP 7.x, we need to install Remi and the latest Epel release of CentOS. Use the following command to install those two.
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Step 2 – Installing yum-utils.
The ‘yum-utils’ package is very useful to manage yum’s repos and extends beyond standard yum’s functionality. To install yum-utils, use the following commands.
yum install yum-utils -y
Step 3 – Setting up yum to install PHP 7.4
Now it’s time to setup yum to set to install 7.4. To do so, run the following commands.
yum-config-manager --enable remi-php74
The argument value “remi-php74” indicates that we will be installing PHP 7.4. If you wish to install PHP version like 7.3 or 7.2, you can change it respectively like 73 or 72. Don’t put the dot in between the version numbers.
Step 4 – Installing PHP 7.4
Now it’s time to install. Everytime you mention “php” in ‘yum install’, it will assume the version you’ve configured in above command of step 3. For this article, we used 74, which means it will install 7.4 by default. We have changed the default.
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo phpmyadmin -y
Upgrading PHP from lower version
If you’re upgrading the PHP version, first remove all php stuff you installed previously of old version and replace it with above command. To do so, use the following command.
yum remove php* -y
Note – This above command will remove everything that starts with “php” name, including phpmyadmin. If you have installed anything other than what we’re going to install, please reinstall it accordingly. For example, it’s php-cgi. You just need to do ‘yum install php-cgi’. Now let’s reinstall what we’ve removed of old php version into new php version.
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo -y
To test the php installation, use this command.
This will show your currently installed PHP version in effect.
If you’re running a webserver, make sure to restart it to reflect the installed packages.
service httpd restart
Thank you for reading my article. If you found this article useful, please leave a comment, or even if you have any questions, you can comment and I will be pleased to help you.
All the above commands and stuff that we did can take up to 30 minutes or even longer install on a standard VPS server. To get it all installed easily without any hassle within less than 10 minutes, you would need a powerful VPS. At Shadow Hosting, we provide powerful VPS hosting powered by AMD Ryzen 9 CPU and fully NVMe powered SSD to boost your overall performance. While writing this article, I tested all the commands on Shadow Hosting’s Power VPS Hosting Diamond plan which indeed took less than 10 minutes to run all commands and get this completed. And sorry for the poor thumbnail :3.