Easy Steps To Install PHP 7.4 on Rocky Linux 8

In this article on the Orcacore website, we want to teach you to Install PHP 7.4 on Rocky Linux 8. PHP is a programming and scripting language to create dynamic interactive websites.

PHP is a server-side language, which means that it runs on your web hosting server. Whenever someone visits your website, their browser contacts your server to request the page. The PHP code runs on the server and generates an HTML page to send to the visitor. The visitor then sees the HTML page in their browser. They can’t see the PHP script because it’s only on the hosting server.

Steps To Install PHP 7.4 on Rocky Linux 8

To complete this guide on PHP 7.4 Rocky Linux 8, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.

Set up PHP 7.4 Rocky Linux 8

First, you need to update your local package index with the following command:

sudo dnf update -y

Remove Old Versions of PHP

Then, you need to remove the PHP and PHP-FPM previous versions if you have them installed on your server. To do this run the following command:

sudo dnf remove php php-fpm -y

Then remove the rest of the package extensions with the command below:

sudo dnf remove php* -y

List Available PHP Modules

To reset the PHP module list on Rocky Linux 8, you can use the following command:

sudo dnf module list reset php -y
List Available PHP Modules Rocky Linux 8

As you can see above, the (d) tag is next to PHP 7.2, which you will need to reset and change to install PHP 7.4.

Enable and Install PHP 7.4

Now you need to enable PHP 7.4 on Rocky Linux 8 with the command below:

sudo dnf module enable php:7.4 -y

At this point, you have enabled PHP 7.4 to be the default version on your system, you can install PHP 7.4 with the following command:

sudo dnf install php -y

If you would like to install the most commonly used extensions for PHP 7.4, use the following command:

sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache

Finally, you can use the following command for anyone interested in installing the development branch:

sudo dnf install php-devel -y

To verify your PHP 7.4 installation on Rocky Linux 8, you can check its version:

php -v
php 7.4 Rocky Linux 8

Configure PHP-FPM To Run as Nginx User

By default on Rocky Linux 8, the PHP-FPM service is designed to be run by (Apache) user. If you are using Nginx you need to make configuration changes at (www.conf).

You can open the file with your favorite text editor, here we use vi:

sudo vi /etc/php-fpm.d/www.conf

Find the user and group directives and change them to Nginx as shown below:

user = nginx
group = nginx

When you are done, save and close the file.

Reload the PHP-FPM service to apply the changes:

sudo systemctl restart php-fpm

The Nginx server block needs the following example below for Nginx to process the PHP files.

Below is an example for all server {} blocks that process PHP files that need the location ~ .php$ added.

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

For more information, you can visit the PHP Documentation page.

Conclusion

At this point, you have learned to Install PHP 7.4 on Rocky Linux 8. You should consider that PHP 7.4 reached the end of life on November 28, 2022. However, PHP 7.4 Rocky Linux 8 is still in widespread use in web applications.

Hope you enjoy it. You may also like these articles:

Set up Anaconda on Rocky Linux 8

Install DotNet on Rocky Linux 8

How to count lines in a file in Linux?

fasd quick access to files and directories

How do I change the version of phpMyAdmin?

Download and Install Virtualmin GPL on Linux

Set up Lighttpd Web Server Rocky Linux 8

CSF Firewall Rocky Linux 8

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!