Install PHP 7 on CentOS 7 / RHEL 7 & CentOS 6 / RHEL 6

PHP is a widely-used open-source programming language for web development created by Rasmus Lerdorf.

33

PHP is a widely-used open-source programming language for web development created by Rasmus Lerdorf. It is an HTML-embedded scripting language for creating dynamic web sites.

CentOS 7/6 comes with PHP 5.x by default which is already the end of life.

In this post, we will see how to install PHP 7.3 / 7.2 / 7.1 on CentOS 7 / RHEL 7 & CentOS 6 / RHEL 6.

Add PHP 7.x Repository

Remi, a third-party repository which offers the latest version of PHP (7.3 / 7.2 / 7.1) for CentOS.

To enable the Remi repository, install the Remi repository auto-configuration package.

### CentOS 7 / RHEL 7 ###

yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

### CentOS 6 / RHEL 6 ###

yum install -y https://rpms.remirepo.net/enterprise/remi-release-6.rpm

Install PHP 7.x

Install PHP 7.3 on CentOS 7 & CentOS 6

Use the below command to install PHP 7.3 package by temporarily enabling Remi PHP 7.3 repository.

yum install -y --enablerepo=remi-php73 php php-cli

Install PHP 7.2 on CentOS 7 & CentOS 6

Use the below command to install PHP 7.2 package by temporarily enabling Remi PHP 7.2 repository.

yum install -y --enablerepo=remi-php72 php php-cli

Install PHP 7.1 on CentOS 7 & CentOS 6

Use the below command to install PHP 7.1 package by temporarily enabling Remi PHP 7.1 repository.

yum install -y --enablerepo=remi-php71 php php-cli

Check PHP Version

Once you have installed the required PHP version, check the PHP version with the following command.

php -v

Output:

PHP 7.3.8 (cli) (built: Jul 30 2019 09:26:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies

Install PHP Extensions

PHP extensions are compiled libraries which enables specific functions/support for your code. For example, installing PHP MySQL extension will enable your PHP code to connect with the MySQL database.

PHP extensions package is normally named like php-<extn_name>.

To install MySQL support, you can install php-mysqlnd package.

yum install -y --enablerepo=remi-php73 php-mysqlnd

Once you have installed a particular extension, you can use the below command to verify it.

php -m | grep -i mysql

Output:

mysqli
mysqlnd
pdo_mysql

PHP Extensions for WordPress

The following extensions are good enough to install and run WordPress on your CentOS system. WordPress recommends having PHP v7.3 for the installation.

yum install -y --enablerepo=remi-php73 php-dom php-simplexml php-ssh2 php-xml php-xmlreader php-curl php-date php-exif php-filter php-ftp php-gd php-hash php-iconv php-imagick php-json php-libxml php-mbstring php-mysqlnd php-openssl php-pcre php-posix php-sockets php-spl php-tokenizer php-zlib

PHP Extensions for Joomla

The following extensions are good enough to install and run Joomla on your CentOS system. Joomla requires PHP v7.1 and above.

yum install -y --enablerepo=remi-php73 php-mysqlnd php-zlib php-xml php-pear php-json php-mcrypt

PHP Extensions for Drupal

The following extensions are good enough to install and run Joomla on your CentOS system. Drupal requires PHP v7.1 and above.

yum install -y --enablerepo=remi-php73 php-mysqlnd php-date php-dom php-filter php-gd php-hash php-json php-pcre php-pdo php-session php-simplexml php-spl php-tokenizer php-xml

Conclusion

That’s All. Please share your feedback in the comments section.

Source link

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More