21 C
Senior Writer and partner

How to Install PHP 7 on CentOS 7 in an easy way?

CentOS 7 is a great Linux server system. It has great support, an active user community and most importantly, it is very stable. However, stability often comes at a price. CentOS 7 comes with a very old version of PHP (5.6 in particular) that is not compatible with many current web applications. That’s why I will show how to install PHP 7 on CentOS 7.

The PHP 7 branch is part of an attempt by developers to improve the syntax of the language in order to allow programmers to write better code and create better web applications.

Another aspect to bear in mind is that PHP 7 represents a substantial improvement in security with previous versions.

In summary, these are some of its novelties:

  • The improved core of Zend Engine 3.0, a runtime engine that interprets PHP, is now faster and more efficient, which makes PHP 7 much better performing.
  • PHP 7 removed obsolete functions in order to make it smaller and lighter.
  • Now you can declare up to 4 types of primitive data, int, string, float and boolean.
- Advertisement -

In others words, if you are a web developer or you are starting in the world of web management or if on the contrary, you manage a CMS, you must install PHP 7.

1. Upgrade CentOS 7

In the first place, you must update the system. It’s always a good idea to do so, because it ensures we have the latest security patches for the system. Open a terminal and type:

:~$ su

After entering the password you will be root user.

Next, you must run yum to update the system in question.

:~# yum update

1.- Upgrading CentOS 7
1.- Upgrading CentOS 7

When the installation is finished, you will have an updated system ready for PHP7.

2. Add an external repository

As I mentioned earlier, CentOS 7 comes in its repositories with PHP 5.6. That’s why you need an external repository for PHP7.

Remi is a repository for CentOS 7, RHEL and Fedora that contains updated RPM packages such as PHP. It is highly reliable and very popular with the Linux distribution community. Today you will use this repository to install PHP 7. Run:

:~# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

2.- Adding the remi repository
2.- Adding the remi repository

Then to enable the use of the repository, type:

:~# yum-config-manager --enable remi-php72

2.- Enabling Remi repository
3.- Enabling Remi repository

3. Install PHP

PHP is a vital component of the LAMP stack. Now proceed to install the most common PHP packages. Of course these will depend on the applications you need to run. I will only show the most used ones.

:~$ yum install php php-common php-opcache php-cli php-xml php-gd php-curl php-mcrypt php-zip php-imap

4.- Installing PHP 7 common packages
4.- Install PHP 7

When installation is complete, you can check which version has been installed. Run:

:~# php -v

5.- Checking the PHP version installed
5.- Checking the PHP version installed

4. Configure PHP to work with apache and Nginx

In fact, PHP 7 doesn’t need extra configurations to work with apache. You just have to restart the service and that’s enough.

:~# systemctl restart httpd

In the case of Ngnix, if you have to install the php-fpm package.

.~# yum install php-fpm

6.- Installing required package for PHP may work with ngnix
6.- Installing required package for PHP to may work with ngnix

Just install a web server and try your new PHP 7.

And this is it.

As you could see, the installation is quite simple but very useful when working with web applications. Updating PHP is a good way to keep the server in top condition.

Tell us, PHP programs? have you noticed a big performance difference? Did you use this tutorial?

Please spread this tutorial through your social networks.


- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article