This article will demonstrate how to install php for Linux operating systems. Specifically, these instructions will cover how to install php on Redhat 8.
Install PHP on Redhat 8
The EPEL repository contains extra packages for linux that are not available by default on RHEL and CentOS. EPEL is short for Extra Packages for Enterprise Linux.
Follow these steps to successfully install PHP on Redhat 8. Root privileges are assumed.
- Install and enabled the EPEL repository. Note that the EPEL repository is a fedora project.
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
- Install the remi repository made available by the EPEL repository.
dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
- List the available php modules before choosing the version you wish to install.
dnf module list php
- Enable the latest PHP 8 module before installing PHP.
dnf module enable php:remi-8.2 -y
- Install PHP for Apache on Redhat. We have a separate article for installing Apache on Redhat.
dnf install php php-cli php-common
- Verify the installation was successful and the expected version is displayed.
php -v
Finally, create a test file named index.php and place it in your /var/www/html folder.
<?php
phpinfo();
?>
Restart your apache server (or nginx, although that was not covered in this article).
systemctl restart httpd
Your index.php will display your php installation information at http://localhost.
If you have difficulty accessing your site, ensure that the local firewall is not blocking you. We have a separate article on Redhat firewall management here.
Install PHP Extensions on Redhat Linux
To install additional php libraries and extensions that may not be provided with the vanilla php install, run the following command.
dnf install php-{extension-name}
Then, running php -m will show the installed extensions.
Conclusion
This article has demonstrated how to install PHP for Linux, specifically for Redhat 8. Let us know in the comments if you have any questions or would like to see more examples of installing PHO on other flavors of Linux.
We hope you have found this document helpful and hope that more of our linux articles can be of use to you.
Leave a Reply