A new version of PHP has come out and it’s time to install it on our servers. So in this post, you will learn how to install PHP 7.4 on CentOS 8. Having this version, you will be able to take better advantage of running websites.
As we know, PHP is a programming language widely used all over the world. In fact, most of the web sites and applications use it. Therefore, it is to be assumed that most servers need it.
By default, CentOS 8 includes version 7.2 in its official repositories. It’s actually a good version that will be supported for a while longer, but the language is advancing more and more every day. So, it is a good idea to install recent versions.
So, let us start.
Install PHP 7.4 on CentOS 8
Installing Apache web server on CentOS 8
Open a terminal session and run the following:
:~$ su :~# dnf install httpd
After the installation is completed, the apache service must be started. We can also enable it to start together with the system:
:~# systemctl enable httpd :~# systemctl start httpd
Then, you have to open the ports where the server works. Without this, we won’t have access to the documents on the server.
:~# firewall-cmd --add-port=80/tcp --permanent --zone=public success :~# firewall-cmd --add-port=443/tcp --permanent --zone=public success :~# firewall-cmd --reload success
Now, we can install PHP 7.4 on CentOS 8.
To install PHP 7.4 we will use the REMI repository. It is quite stable and has a long history of use. But, first, we will have to enable the EPEL repository. We can do this with the following command:
:~# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Next, we proceed to add the REMI repository for CentOS 8.
:~# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
The REMI repository contains a large number of packages. By default, only those belonging to REMI-Safe are enabled. So, you have to enable REMI-7.4.
:~# dnf module enable php:remi-7.4
And now we can install PHP 7.4 and its modules without problems.
:~# dnf install php php-common php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-gd php-mbstring php-xml
Now we are going to prove that it all worked out. The best way to do this is to run PHP.
So, I am going to create a file called
test.php in the apache root folder and add the phpinfo method to it.
:~# nano /var/www/html/test.php
Save the changes and close the editor.
Then, restart the apache service:
:~# systemctl restart httpd
Now open your web browser and go to
http://your-server/test.php and you will see the following:
So, enjoy it.
Also, you can read all the features of this version in this link.
Finally, you can read these related posts: