In this tutorial, we’re going to show you how to install PHP on CentOS. Beginner-friendly, step-by-step instructions on how to install different versions of PHP on different versions of CentOS. Table of Contents
Prerequisites
This is what you’ll need for our how to install PHP on CentOS tutorial:
- The root user or a user with sudo privileges
- SSH access to the server (or just open Terminal if you’re on a desktop)
- A CentOS system. We tested this tutorial on CentOS 7 and CentOS 8 servers from Linode, but these instructions will work on any other RHEL-based distro. You can get a Linux VPS from any provider.
Depending on what kind of a distro setup you’re using and when you’re reading this, CentOS might have different versions included in their repos. As of writing, by default, CentOS 8 has no PHP installed, and the default version in the repos is PHP 7.2.24 – which is already past its EOL. CentOS 7 also has no PHP installed and the default version in the repos is 5.4.16 – which is way past its EOL. So if you just run the yum install php command on CentOS, you’ll get outdated versions.
Follow our tutorial to get the latest version of PHP on CentOS.
Step 1: Update CentOS
As always, you need to update your CentOS first:
yum updateStep 2: Install and configure necessary packages
First, you need to install the necessary (extra) packages:
yum install epel-release yum-utilsNext, we’ll need the Remi RPM repository.
If you’re using CentOS 7, run:
yum install //rpms.remirepo.net/enterprise/remi-release-7.rpmIf you’re using CentOS 8, run:
yum install //rpms.remirepo.net/enterprise/remi-release-8.rpmThen, enable the PHP 8.1 module.
If you’re using CentOS 7, run:
yum-config-manager --enable remi-php81If you’re using CentOS 8, run:
yum module enable php:remi-8.1You can also install any other version of PHP by updating the command for the PHP module above.
Update the repos again:
yum updateAnd finally, after you enabled the PHP 8.1 module, you can install PHP 8.1 (or whatever version you enabled) with the following command:
yum install phpYou can verify if PHP was installed by running
Which should give you a result similar to:
PHP 8.1.2 (cli) (built: Jan 18 2022 23:52:03) (NTS gcc x86_64)Step 4: Install PHP extensions
There are some PHP extensions that are often used and needed for various apps and use-cases. To install a PHP package, just run the yum install php-<extension-name> command.
Here’s how to install some of the most common PHP extensions:
yum install php-fpm php-curl php-cli php-json php-mysql php-opcache php-dom php-exif php-fileinfo php-zip php-mbstring php-hash php-imagick php-openssl php-pcre php-xml php-bcmath php-filter php-pear php-gd php-mcrypt php-intl php-iconv php-zlib php-xmlreaderThese are also most of the extensions you’ll need if you are installing WordPress.
And that’s all. You successfully installed the latest version of PHP on your CentOS.
Linux StansThe official Linux Stans account.
49 postsHow to Install PHP 8 on CentOS. This guide let you learn how install the latest PHP version 8 on your CentOS system or your CentOS server on any VPS or any Cloud or any Dedicated hosting and configure it with Httpd and Nginx.
The latest PHP 8 version is officially released on November 26th, 2020. It comes with a number of new features and a few incompatibilities that you should be aware of before upgrading from the previous version.
This installation is tested on Google Cloud Platform with a Compute Compute Engine VM Instance. So this set up is guaranteed to work on all Linux based servers.
Prerequisites
- A CentOS server set up with sudo privileges.
Getting Started
Make sure your CentOS server is having the latest packages by running the following command.
sudo yum update sudo yum upgradeThis will update the package index and update the installed packages to the latest version.
Install Remi Repository
As PHP 8.0 is not available in the default repositories you need to install the Remi repository and yum-utils and enable the epel-release.
sudo dnf -y install //rpms.remirepo.net/enterprise/remi-release-8.rpm sudo dnf -y install dnf-utilsNow you can see the available PHP version for installation using the following command.
sudo dnf module list phpYou can see that PHP 8.0 will be available through the Remi repository.
Now you can reset the module and enable PHP 8.0
sudo dnf module reset php sudo dnf module install php:remi-8.0Once this is done you can install PHP 8.0
Install PHP 8 for HTTPD
Execute the following command to install PHP 8
sudo dnf install phpAfter the installation has completed, you can confirm the installation using the following command
Install PHP 8.0 FPM for Nginx
For Nginx you need to install FPM, execute the following command to install PHP 8 FPM.
sudo yum install php-fpmAfter the installation has completed, enable the service using the following command.
sudo systemctl enable php-fpm.serviceStart PHP-FPM service with the below command.
sudo systemctl start php-fpm.serviceInstall PHP 8 Extensions
Installing PHP extensions are simple with the following syntax.
sudo dnf install php-extension_nameNow, install some commonly used php-extensions with the following command.
sudo dnf install php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl,bcmath} -yConfigure PHP 8.0
Now we configure PHP for Web Applications by changing some values in php.ini file.
For PHP 8 the php.ini location will be in following directory.
sudo nano /etc/php.iniHit F6 for search inside the editor and update the following values for better performance.
upload_max_filesize = 32Mpost_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000
Once you have modified your PHP settings you need to restart your Httpd or PHP-FPM for the changes to take effect.
Configure PHP 8 FPM Pools – Nignx
PHP 8.0 FPM allows you to configure the user and group that the service will run under. You can modify these using the following commands.
sudo nano /etc/php-fpm.d/www.confChange the following lines by replacing the www-data with your username.
user = username group = username listen.owner = username listen.group = usernameHit CTRL+X and Y to save the configuration and check if the configuration is correct and restart PHP.
Restart PHP 8 FPM – Nginx
Once you have updated your PHP FPM settings you need to restart it to apply the changes.
sudo systemctl restart php-fpm.serviceNow you are having PHP 8.0 Installed and configured in CentOS.
Prepare yourself for a role working as an Information Technology Professional with Linux operating system
Conclusion
Now you have learned how to install PHP 8 on your CentOS server.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.
How do I enable PHP extensions in Linux?
How To Compile And Install PHP Extensions From Source.
Install the PHP development package. On Ubuntu/debian, you can use apt-get, it's a piece of cake. ... .
Download & unzip the PHP5 source code. ... .
Prepare the extension (phpize) ... .
Configure & Make the extension. ... .
Move the extension. ... .
Edit your PHP. ... .
Restart your php..
How do I enable and install PHP extensions?
Steps to Install PHP Extension in cPanel.
Step 1: Select the cPanel and login..
Step 2: Go to PHP version..
Step 3: Pick your ideal PHP version and click on Set as Current and select the extensions..
Step 4: Select the required Extensions..
Does Rhel 8 have PHP 8?
No translations currently exist.
What version of PHP comes with RHEL 8?
The version of PHP supplied by default in RHEL 8 / CentOS 8, from the AppStream repository is 7.2.