In this article, we are going to see how to install PHP 7.4 on CentOS/RHEL 8. PHP is the most popular server-side scripting language. This is also common for developing dynamic websites. As per now, the latest PHP version is 7.4.
Preconditions for installation of PHP
- A VPS or a local server on which CentOS 8 or RHEL 8 is running.
- You must log-in with a root user or a non-root user with sudo privilege.
- Internet connection
Step 1: Enabling EPEL and Remi repository
If you look at the default CentOS and RHEL 8 repository, there are only 7.2 and 7.3 PHP versions available.
And to install the latest version of PHP that is PHP 7.4, you have to enable EPEL and Remi repositories. Use the below command to install it.
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
After completing the installation, run the below command to view the available PHP version.
dnf module list php
For example, you can also see the below picture to verify it.
As you can see in the picture, PHP 7.2 and 7.3 are available in the default repository and PHP 7.4 is available in the Remi repository. So, we are going to enable the default PHP 7.4. Now it will install the latest version.
Step 2: Enabling the latest PHP Module
In step 2, we are going to enable the latest PHP module. Use the below command to perform this task.
sudo dnf module enable php:remi-7.4
Step 3: Installation of PHP 7.4
In this step, we are installing PHP version 7.4. Use the below command to install it.
sudo dnf install php php-cli php-common
It will ask your permission, press y to install it.
Step 4: Verify the PHP version
As per now, we have successfully installed the php 7.4. So, this is the time to verify the php version, you can use the below command to verify it.
Step 5: Installing php-fpm
After installation of PHP, you also need to install php-fpm as its dependency, it will be work as FastCGI Server, so use below command to start and enable FPM service,
sudo systemctl enable --now php-fpm
Step 4: Updating PHP parameters
When you use PHP for different CMS, for example, WordPress, Drupal, Jumla, or any other then you have to modify the configuration file. So, you can find the configuration file in /etc/php.ini. If you want to change any configuration then you can use the vim or any other file editors as per your choice.
For example, I’m using here vim editors to make the changes in the php.ini file. However, you can use vi, nano, pico, or any other editors.
sudo vim /etc/php.ini
After making any changes in this file, restart the service of httpd or Nginx as per you are using the webserver.
For Apache server
sudo systemctl restart httpd
sudo systemctl restart nginx
In this article, we learn how to install PHP 7.4 on CentOS 8 or RHEL 8. In conclusion, you can install php 7.4. So, I hope, you understand but if you have any questions, you can ask in the comment section.
You can read about How to install MariaDB Server on RHEL 8 / CentOS 8.
Also, you can read about PHP from its home page More about PHP