The process of installing PHP 8 with Apache2 on Rocky Linux 8 involves a few steps, and it is important to follow each step carefully to ensure a successful installation. In this article, we will walk through the process of installing PHP 8 and Apache2 on Rocky Linux 8, and provide some helpful tips along the way.
First, we need to ensure that our Rocky Linux 8 system is up to date. To do this, we will run the following command:
sudo dnf update
This will update all of the packages on our system to the latest version.
Next, we need to install Apache2. To do this, we will run the following command:
sudo dnf install httpd
This will install the Apache2 web server on our system.
Once Apache2 is installed, we need to enable it to start automatically at boot time. We can do this by running the following command:
sudo systemctl enable httpd
Now that Apache2 is installed and enabled, we can proceed to install PHP 8. To do this, we will need to add the PHP 8 repository to our system. We can do this by running the following command:
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --set-enabled remi-php80
This will add the PHP 8 repository to our system and enable it.
Next, we can install PHP 8 by running the following command:
sudo dnf install php php-common
This will install PHP 8 and the necessary dependencies on our system.
Once PHP 8 is installed, we need to configure Apache2 to use it. To do this, we will need to edit the Apache2 configuration file. We can do this by running the following command:
sudo vi /etc/httpd/conf/httpd.conf
This will open the Apache2 configuration file in the vi
text editor.
In the Apache2 configuration file, we need to find the following line:
#LoadModule mpm_event_module modules/mod_mpm_event.so
We need to remove the #
character at the beginning of the line to uncomment it. This will enable the mod_mpm_event
module, which is required for PHP 8 to work with Apache2.
Next, we need to find the following line:
#LoadModule php7_module modules/libphp7.so
We need to remove the #
character at the beginning of the line to uncomment it, and change php7_module
to php8_module
to enable the PHP 8 module. The line should now look like this:
LoadModule php8_module modules/libphp8.so
Next, we need to add the following lines to the end of the Apache2 configuration file:
<FilesMatch \\.php$>
SetHandler application/x-httpd-php
</FilesMatch>
These lines will tell Apache2 to handle files with the .php
extension using PHP 8.
Now we can save the Apache2 configuration file and exit the vi
text editor.
To restart Apache2 and apply the changes we made to the configuration file, we can run the following command:
sudo systemctl restart httpd
This will restart Apache2 and apply the changes to the configuration file.
At this point, PHP 8 should be successfully installed and configured to work with Apache2 on Rocky Linux 8. To verify that PHP 8 is working correctly, we can create a test PHP file in the Apache2 document root directory, which is typically located at /var/www/html
.
To create a test PHP file, we can run the following commands:
sudo vi /var/www/html/test.php
This will open the test.php
file in the vi
text editor.
In the test.php
file, we can add the following code:
<?php
phpinfo();
?>
This code will display information about the PHP installation on our system.
Now we can save the test.php
file and exit the vi
text editor.
To access the test.php
file in a web browser, we can open a web browser and navigate to http://localhost/test.php
. This should display the PHP information page, indicating that PHP 8 is working correctly with Apache2 on our Rocky Linux 8 system.
In conclusion, the process of installing PHP 8 with Apache2 on Rocky Linux 8 involves a few steps, including updating the system, installing Apache2 and PHP 8, and configuring Apache2 to use PHP 8. By following the steps outlined in this article, you should be able to successfully install and configure PHP 8 with Apache2 on Rocky Linux 8.