Install PHP 7 on a cPanel/WHM Server

How to install PHP 7 on a cPanel/WHM Server


mkdir php7.0
cd php7.0
wget http://php.net/distributions/php-7.0.1.tar.gz
tar -xvf php-7.0.1.tar.gz
cd php-7.0.

Run

./configure –help (to see all available options first)

./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

make
make test
make install

cd /usr/local/php70/bin

To see the new version:

./php -v

Running ./php -v in the /usr/local/php70/bin folder should give you something like this:
  
PHP 7.0.1 (cli) (built: Dec 18 2015 03:53:53) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Here’s some simple extensions added based on the basic php.ini template


cp -f /usr/local/php7.0/php-7.0.1/php.ini-production /usr/local/php70/lib/php.ini

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

At this point you can delete the /usr/local/php7.0 folder (the source code)

Now, we need to create a configuration file for apache in order to be able to add the php7 handler so, to do that, open up a new file:
touch /usr/local/apache/conf/php7.conf
and paste the code below. (Don’t forget to modify the “Directory” path regex to suit your needs.)

vi /usr/local/apache/conf/php7.conf
<IfModule mod_suphp.c>
<Directory ~ "home/user/public_html/">
AddType application/x-httpd-php7 .php
suPHP_AddHandler application/x-httpd-php7
</Directory>
</IfModule>

To create a new handler in supPHP open up the suphp.conf:

vim /opt/suphp/etc/suphp.conf

Then add the new handler using the code below, at the end of the handlers list.


;Handler for php-scripts
#... existing handlers are here ... put yours below them
application/x-httpd-php7="php:/usr/local/php70/bin/php-cgi"

Now let’s add our handlers into the EasyApache/cPanel/WHM configuration without breaking anything… There are two options here. You either go into WHM and edit the post_virtualhost_global.conf file from there or you just run:


vim /usr/local/apache/conf/includes/post_virtualhost_global.conf

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


include /usr/local/apache/conf/php7.conf

Now restart Apache and enjoy!


service httpd restart

credit: https://www.codepunker.com/blog/how-to-install-php-7-on-a-cpanel-whm-driven-server-without-breaking-everything

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.