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 PrerequisitesThis is what you’ll need for our how to install PHP on CentOS tutorial:
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 Follow our tutorial to get the latest version of PHP on CentOS. Step 1: Update CentOSAs always, you need to update your CentOS first: yum update Step 2: Install and configure necessary packagesFirst, you need to install the necessary (extra) packages: yum install epel-release yum-utils Next, we’ll need the Remi RPM repository. If you’re using CentOS 7, run: yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm If you’re using CentOS 8, run: yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm Then, enable the PHP 8.1 module. If you’re using CentOS 7, run: yum-config-manager --enable remi-php81 If you’re using CentOS 8, run: yum module enable php:remi-8.1 You can also install any other version of PHP by updating the command for the PHP module above. Update the repos again: yum update And 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 php You can verify if PHP was installed by running php -v 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 extensionsThere are some PHP extensions that are often used and needed for various apps and use-cases. To install a PHP package, just run the 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-xmlreader These 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
Getting StartedMake sure your CentOS server is having the latest packages by running the following command. sudo yum update sudo yum upgrade This will update the package index and update the installed packages to the latest version. Install Remi RepositoryAs PHP 8.0 is not available in the default repositories you need to install the Remi repository and sudo dnf -y install http://rpms.remirepo.net/enterprise/remi-release-8.rpm sudo dnf -y install dnf-utils Now you can see the available PHP version for installation using the following command. sudo dnf module list php You 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.0 Once this is done you can install PHP 8.0 Install PHP 8 for HTTPDExecute the following command to install PHP 8 sudo dnf install php After the installation has completed, you can confirm the installation using the following command php -v Output
PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies Install PHP 8.0 FPM for NginxFor Nginx you need to install FPM, execute the following command to install PHP 8 FPM. sudo yum install php-fpm After the installation has completed, enable the service using the following command. sudo systemctl enable php-fpm.service Start PHP-FPM service with the below command. sudo systemctl start php-fpm.service Install PHP 8 ExtensionsInstalling PHP extensions are simple with the following syntax. sudo dnf install php-extension_name Now, install some commonly used sudo dnf install php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl,bcmath} -y Configure PHP 8.0Now we configure PHP for Web Applications by changing some values in For PHP 8 the sudo nano /etc/php.ini Hit upload_max_filesize = 32M 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 – NignxPHP 8.0 FPM allows you to configure the sudo nano /etc/php-fpm.d/www.conf Change the following lines by replacing the www-data with your user = username group = username listen.owner = username listen.group = username Hit Restart PHP 8 FPM – NginxOnce you have updated your PHP FPM settings you need to restart it to apply the changes. sudo systemctl restart php-fpm.service Now 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 ConclusionNow 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. |