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.
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:
After entering the password you will be root user.
Next, you must run yum to update the system in question.
:~# yum update
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
Then to enable the use of the repository, type:
:~# yum-config-manager --enable remi-php72
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
When installation is complete, you can check which version has been installed. Run:
:~# php -v
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 owe the
.~# yum install php-fpm
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.