How To install PHP 7 On a cPanel/WHM server with EasyApache 3 ?

Latest versions of cPanel come with EasyApache 4 which provides a lot of new features like native support for multiple PHP versions, PHP 7 support, very fast, etc. So it is recommended to migrate to EasyApache 4 to utilize these features. However, if you cannot migrate EasyApache 4 because of some reason (Example: Tomcat support), you will have to compile the PHP 7 manually from source to use it with EasyApache3.

To migrate to EasyApache4, just run the below command. cPanel will try to build a matching PHP setup using EasyApache 4.

# /scripts/migrate_ea3_to_ea4 –run

If anything goes wrong during the upgrade process, you can always go back with /scripts/migrate_ea3_to_ea4 –revert –run

PHP7 manual installation

Following steps are tested with cPanel 11.64.0.36 and CentOS 6.9 64 bit. The PHP handler should be Suphp to get this working.

# cd /usr/local/src/
# wget http://php.net/distributions/php-7.0.22.tar.gz  ; Go to php.net site to find the latest version
# tar xvf php-7.0.22.tar.gz

Now build it.

./configure –enable-bcmath –enable-calendar –enable-exif –enable-ftp –enable-gd-native-ttf –enable-libxml –enable-mbstring –enable-pdo=shared –enable-sockets –enable-zip –prefix=/usr/local/php70 –with-curl=/opt/curlssl/ –with-freetype-dir=/usr –with-gd –with-gettext –with-imap=/opt/php_with_imap_client/ –with-imap-ssl=/usr –with-jpeg-dir=/usr –with-kerberos –with-libdir=lib64 –with-libxml-dir=/opt/xml2/ –with-mcrypt=/opt/libmcrypt/ –with-mysqli –with-openssl=/usr –with-openssl-dir=/usr –with-pcre-regex=/opt/pcre –with-pdo-mysql=shared –with-pdo-sqlite=shared –with-pic –with-png-dir=/usr –with-xpm-dir=/usr –with-zlib –with-zlib-dir=/usr

You may add any additional parameters required. You can run ./configure –help to see all available options first.
Important: Do not forget to set the “–prefix=/usr/local/php70”. Otherwise, your existing PHP installation will be lost.

# make
# make install

If everything is successful, the PHP binaries will be installed in “/usr/local/php70/bin/” directory. Now copy the default php.ini:
# cp -pr /usr/local/src/php-7.0.22/php.ini-production /usr/local/php70/lib/php.ini
Add pdo,opcache, other modules to php.ini file.
# echo “extension=pdo.so” >> /usr/local/php70/lib/php.ini
# echo “extension=pdo_mysql.so” >> /usr/local/php70/lib/php.ini
# echo “zend_extension=opcache.so” >> /usr/local/php70/lib/php.ini

Verify the installation:

# /usr/local/php70/bin/php -v
PHP 7.0.22 (cli) (built: Aug 5 2017 01:56:23) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.22, Copyright (c) 1999-2017, by Zend Technologies
Now link our new PHP 7 installation with Apache web server:

Generate the PHP config:

# cat > /usr/local/apache/conf/php70.conf << EOF
AddType application/x-httpd-php7 .php7 .php
<Directory />
suPHP_AddHandler application/x-httpd-php7
</Directory>
EOF
To add new handler to Suphp, edit the /opt/suphp/etc/suphp.conf and add below code, at the end of the handlers list to enable PHP7 handler.
application/x-httpd-php7=”php:/usr/local/php70/bin/php-cgi”

Now add our custom php config file to EasyApache list so that the changes will not be lost future in EasyApache builds.

There are two options here. You can either go into WHM and edit the post_virtualhost_global.conf file from there or you simply run the following:

# vi /usr/local/apache/conf/includes/post_virtualhost_global.conf

Add the line below in that file and you should be all done.

Include /usr/local/apache/conf/php70.conf
Now restart Apache
# service httpd restart

In order to configure your website to use PHP7, add following code to .htaccess file(/home/username/public_html/.htaccess)

AddType application/x-httpd-php7 .php7 .php

You are done!

Be up-to-date: Importance of updating servers

Importance of Updating Servers
If you’re using a Linux distribution like Debian or Ubuntu, it will be having Linux kernel, the core that actually makes your distribution a Linux distribution. Windows also has its own kernel that its operating systems use, since Linux have a modular architecture whereby its kernel is more commonly discussed where a lot can be done on it. You could take the kernel, patch it up with lots of fixes, tweak other settings, strip out everything you won’t need, and then replace your original kernel with your final product, and it will run just fine (assuming it was done right). Being able to simply replace a part with something else without issue is what makes Linux great.
Security Fixes

Every time when we update kernel, some sort of security fixes are implemented to overcome the previous drawbacks. This is probably one of the most important reasons why we should update kernel, as you will be always safer with a patched kernel. If left unpatched, your system give way for the hackers. The Wannacry ransomware attack that caused millions of loss in the Internet world recently, is one such attack that targeted servers that had outdated OS versions. A lot of damage can be done or the system simply crashes if it is exposed to hackers. As the year passes, the job is getting easier for hackers. The analysis report published by MITRE vulnerability database shows that the number of software vulnerabilities keep on increasing. The more the vulnerabilities, the greater the chance for a successful hack. These situations can be easily avoided with up-to-date kernels. Once your server is hacked, the loss you encounter is unimaginable –

1. Server downtime leading to customer loss and compensations

2. Data loss leading to poor reputation and security risks that can end you up in law suits and further financial loss.
All the hard work you did to build up your business, the cost and effort you put in over years to garner a decent customer base, the future prospects of getting more business, everything can go for a toss due to a single hack incident.

Stability Improvements

Not only do kernel updates bring with it security fixes, but it can fix other issues that could possibly make the system crash through regular use. Some people argue that constantly updating the kernel actually decreases the overall system stability because you’ll be running on a kernel that you’ve never used, so you cannot assume that it will work as well as the kernel you were previously running on. While this is also true, that margin is rather slim, and only people who run servers or other important systems really need to be cautious. For most normal consumer-type users, updating your kernel outweighs those issues by a lot.
Updated Drivers

While those were the updates you get with minor kernel updates, let’s check out some improvements you can commonly see with major updates. First of all, every major kernel update is guaranteed to include the latest open source drivers for all of your devices. Out of all the drivers being updated, the graphics drivers are probably those that you’ll notice the most, as every refresh usually adds a bit more performance. While it’s always possible to go for proprietary route, knowing that the open source drivers keep getting better and better is good too. Most of the time, you’ll be fine with open-source software on Linux. But if you want real gaming and graphical power, you’ll need proprietary drivers. Here’s how to get them.
Updated Kernel Functions
Major updates to the kernel in Linux also brings some new functions. These functions are basically parts of the kernel that programs can use to do some sort of task or operation. Additionally, other functions may have also changed. You most likely won’t break your system if you don’t update your kernel for this exact reason, but sooner or later you’ll find programs and other packages that require a certain version of the kernel. It’s best to have the latest one so you know you won’t come across that issue.
Increased Speed

Last but not least, many major updates to the kernel improve the overall speed of the system. While some changes can be very subtle, others aren’t. If you’re a speed demon this is a good way to get a bit more juice out of your hardware.
Conclusion
In the end, it’s very worthwhile to update your kernel for Linux whenever you can. For consumer-type users, the benefits that come along with it far outweigh the risks. Additionally, each kernel that you update to will have been tested for at least a couple of days by developers and test users to ensure that it runs without a hitch. In case your system does have a problem with it, you should be able to choose a previous kernel from the boot menu so you can get back into your system. Then you can delete the offending kernel and make a choice of staying with your current kernel or waiting until a working update appears.
Do you have your own policies for updating the Linux kernel? Do you think distributions should always use the absolute latest or should they lag a bit for stability reasons? Should there be major kernel updates during a release (like Fedora does, or used to do) or only minor updates (like Ubuntu does)? Let us know in the comments!