23Systems

  • Home
  • News
  • Downloads
  • Plugins
    • Lightbox Plus for WordPress
      • Lightbox Plus for WordPress Demos
      • Lightbox Plus for WordPress Installation
      • Lightbox Plus for WordPress Frequently Asked Questions
      • Lightbox Plus for WordPress Change Log
    • Actionable for WordPress
      • Actionable for WordPress Demo
    • Facelift Image Replacement (FLIR) for WordPress
      • FLIR for WordPress Installation
      • FLIR for WordPress Frequently Asked Questions
      • FLIR for WordPress Change Log
    • Donate to support WordPress Plugin Development
  • Services
    • Client Questionnaire
    • WordPress Website Design Portfolio
  • Support
    • Website and Service Support
    • WordPress Plugin Support
  • About
  • Contact

Installing PHP 5.6.x and 7.0.x with Ubuntu 14.04 and Virtualmin 5.0gpl using a PPA

January 8, 2016 by Dan Zappone 9 Comments

Installing PHP 5.6.x and 7.0.x with Ubuntu 14.04 and Virtualmin 5

Installing PHP 5.6.x and 7.0.x with Ubuntu 14.04 and Virtualmin 5

Updated with new information regarding having PHP 5.6.x and PHP7.0.x work with the creation of new sites

This tutorial shows you how to install PHP 5.6.x and PHP 7.0.x side by side on Ubuntu 14.04 with Virtualmin using FCGI and assumes that you already have Virtualmin configured on a server. Please read through this entire tutorial before starting.

Note: As always backup your servers or sites. I accept no liability for loss of data, problems, or damage caused to your server by following this tutorial. This worked for me but – use at your own risk.

Adding the PPA

The first thing you’ll need to do is add the ppa that lets you install PHP 5.6.x and PHP 7.0.x side by side. The following ppa allows both PHP 5.6.x and PHP 7.0.x to run side-by-side. Type or paste the following:

sudo add-apt-repository ppa:ondrej/php

Once you enter the above command You should see something similar to the following when you add the repository.

Co-installable PHP versions: PHP 5.6, PHP 7.0 and batteries included.

You can get more information about the packages at https://deb.sury.org

For PHP 5.6 use: ppa:ondrej/php5-5.6
For PHP 5.5 use: ppa:ondrej/php5
For PHP 5.4 use: ppa:ondrej/php5-oldstable

BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/pages/bugreporting.html

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating: https://deb.sury.org/pages/donate.html

WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# apt-get install -y language-pack-en-base
# LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or ctrl-c to cancel adding it

Press enter when prompted or ctrl-c if you change your mind. If you press enter the server should respond with the following output:

gpg: keyring `/tmp/tmp6l1myhl1/secring.gpg' created
gpg: keyring `/tmp/tmp6l1myhl1/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp6l1myhl1/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

Next you will need to update and upgrade the system before we continue. This should ensure that you have the latest Webmin, Usermin and Virtualmin if you haven’t already updated them. I’m going to use aptitude because I want to easily see what the options are for any conflicts. Type or paste the following two lines.

sudo aptitude update
sudo aptitude full-upgrade

You should hopefully see something more or less like the following, depending on if we’ve updated recently we may only see the bit about new packages and removing packages without any upgrades listed.

Current status: 10 updates [+5], 1622 new [+199].
The following NEW packages will be installed:
  libmemcached11{a} libqdbm14{a} libssl1.0.2{a} php-cli{a} php-common{a} php-readline{a} php7.0-cli{ab} php7.0-common{ab} php7.0-json{a} php7.0-opcache{a} php7.0-readline{a}
The following packages will be upgraded:
  libgnutls-openssl27 libgnutls26 libmemcachedutil2 libpng12-0 libssl-dev libssl-doc openssl php-pear usermin webmin-virtual-server
10 packages upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.2 MB of archives. After unpacking 25.0 MB will be used.
The following packages have unmet dependencies:
 php7.0-cli : Breaks: php5-cli (< 5.6.16+dfsg-4~) but 5.5.9+dfsg-1ubuntu4.14 is installed.
 php7.0-common : Conflicts: php5-common (< 5.6.16+dfsg-4~) but 5.5.9+dfsg-1ubuntu4.14 is installed.
The following actions will resolve these dependencies:

     Remove the following packages:
1)     php-pear

     Keep the following packages at their current version:
2)     php-cli [Not Installed]
3)     php-readline [Not Installed]
4)     php7.0-cli [Not Installed]
5)     php7.0-common [Not Installed]
6)     php7.0-json [Not Installed]
7)     php7.0-opcache [Not Installed]
8)     php7.0-readline [Not Installed]

Accept this solution? [Y/n/q/?]

Go ahead and accept this solution, PHP will still be at the existing version (PHP 5.5.9) but you’ll change that in the next section.

Installing PHP 5.6.x and PHP 7.0.x

Once you’ve updated your repositories and upgraded your system to ensure you have the latest version of Virtualmin you are ready to install PHP 5.6.x and PHP 7.0.x. Type or paste the next code section and press enter. This will remove and replace the default PHP 5.5.9 packages that come with Ubuntu 14.04 with the versions from the ppa.

sudo aptitude install pkg-php-tools php5.6 php5.6-cgi php5.6-cli php5.6-dbg php5.6-common php5.6-curl php5.6-gd php5.6-imap php5.6-intl php5.6-mysql php5.6-pspell php5.6-sqlite3 php5.6-tidy php5.6-opcache php5.6-json php5.6-bz2 php5.6-mcrypt php5.6-readline php5.6-xmlrpc php5.6-enchant php5.6-xsl php-all-dev php7.0 php7.0-cgi php7.0-cli php7.0-common php7.0-dbg php7.0-curl php7.0-enchant php7.0-gd php7.0-imap php7.0-intl php7.0-ldap php7.0-mcrypt php7.0-readline php7.0-pspell php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-json php7.0-sqlite3 php7.0-mysql php7.0-opcache php7.0-bz2 libapache2-mod-php7.0

Check and accept the solution offered unless it looks like it will break something else in your system. Again, this will remove and replace the default PHP 5.5.9 packages. Once the system has completed installing and configuring PHP check to see if you have a new php-cli running with the following command:

php -v

Following these instructions should yield PHP 7.0.x on the command line and you should see the following (depending on PHP version):

HP 7.0.2-1+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

Configuring files and paths for Virtualmin

Next you will need to move some files into place for Virtualmin to have access to php.ini files per server. This may be necessary for you depending on how you want manage you sites. If you don’t need individual php.ini files you can skip down to Detected php-cgi versions below.

Virtual Server php.ini files

Copy php.ini files to home directories and remember to change to the name of the virtualmin home/directory and user.

sudo mkdir /home//etc/php5.6
sudo mkdir /home//etc/php7
sudo mkdir /home//etc/php7.0
sudo cp /etc/php/5.6/cgi/php.ini /home//etc/php5.6/
sudo cp /etc/php/7.0/cgi/php.ini /home//etc/php7/
sudo cp /etc/php/7.0/cgi/php.ini /home//etc/php7.0/
sudo chown -R . /home//etc

If you have many sites and sub-sites you might want a script that can loop through the home directory and update as required. I’ve provided a script, vmin-inis.sh, that can do that but as always check the scripts and verify the path for your system and update the script as needed.

If you want to use the script instead of typing the above commands make it executable and go ahead and run it.

chmod +x vmin-inis.sh
sudo ./vmin-inis.sh

Detected php-cgi versions

For some reason the detected version of PHP are either not install correctly or Virtualmin detects them incorrectly. So in order for Virtualmin to work with PHP 5.6.x and PHP 7.0.x you will need to correct the location of where the php-cgi executables are. Instead of fixing them in the /home//fcgi-bin/*.fcgi files you will need to fix them on the file system. The reason for this is that Virtualmin will change the files back to what it detects and then you will start getting 500 errors. Type or paste the following to set the files correctly.

cd /usr/bin
sudo mv -f php5.6 php5.6.old
sudo mv -f php7.0 php7.0.old
sudo ln -s php-cgi5.6 php5.6
sudo ln -s php-cgi7.0 php7.0

This may need to be done again after updating PHP 5.6.x and PHP 7.0.x unless the detection or installation is fixed in the future. Here’s a script, fcgi-fix.sh, that will move the phpX.X files Virtualmin points to to phpX.X.old and create symbolic links for phpX.X to php-cgiX.X instead which seems to work correctly script. You can download, extract, run this and that should be able to do the above and which you can run after updating PHP should the need arise.

chmod +x fcgi-fix.sh
sudo ./fcgi-fix.sh

At this point almost everything is set but php-cgi will not quite work. What will happen at this point if you try to go to one of your site is that your web browser will try to download the php file. You’ll need to edit the apache configuration file to tell it to not handle php files.

nano /etc/apache2/mods-available/php7.0.conf

Configuring Apache for PHP

Comment out SetHandler application/x-httpd-php and SetHandler application/x-httpd-php-source. It should look like this when done.

<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
    # SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    # SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied
</FilesMatch>
    
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

After updating the php7.0.conf you must restart apache.

service apache2 restart

If you see this message when restarting apache you will need to update your /etc/hosts file with the ip address and domain name. I don’t think this is an issue with the install as I think there was a problem with my /etc/hosts file not having the domain added when Virtualmin was installed but I am providing this information just in case.

AH00557: apache2: apr_sockaddr_info_get() failed for 

Finalizing Virtualmin Configuration

Now, make the switch or fix existing PHP 5.5.9 sites to use one of the new versions of PHP you installed. Once PHP 5.6.x and PHP 7.0.x are installed we will need to ensure that Virtualmin can see them both. First go to our Virtualmin Server -> Virtualmin -> System Settings -> Re-Check Configuration. Once that completes we should be able to see PHP 5.6.x and PHP 7.0.x as options.

Then go to Virtualmin -> Server Configuration -> PHP Versions and select 5.6.x or 7.0.x as required for the Default HTML directory then click Save Versions. That virtual host should now be using the selected version PHP.

Check your sites to make sure they work as expected. I’ve had a few WordPress sites that have plugins that are not compatible with PHP 7.0.x and started throwing 500 errors but work fine when reverted to PHP 5.6.x.

s far as the creation of new sites goes you will need to edit you server templates to accomodate the new version of PHP. To do that go to Virtualmin –> System Setting Server Templates and edit each of the templates. When editing the templates at the Edit template section choose Apache website then scroll down until you see Template for PHP 5.6/7.0/7 configuration file and change from default to the following respectively:

OptionSetting
Template for PHP 5.6 configuration file/etc/php/5.6/cgi/php.ini
Template for PHP 7.0 configuration file/etc/php/7.0/cgi/php.ini
Template for PHP 7 configuration file/etc/php/7.0/cgi/php.ini

Sources

https://www.virtualmin.com/documentation
https://askubuntu.com/questions/705880/how-to-install-php-7
https://launchpad.net/~ondrej/+archive/ubuntu/php

Filed Under: Apache, development, Linux, php, web development Tagged With: Apache, php, ubuntu, virtualmin

Comments

  1. doc_denis says

    April 25, 2016 at 2:46 am

    sorry for the disturbance, i’m launch new virtualmin installation in ubuntu 16.04 for use php7.
    thank-you

    Reply
  2. doc_denis says

    April 23, 2016 at 4:51 pm

    hello, after this command : “service apache2 reload” i have this message :
    SuexecUserGroup configured, but suEXEC is disabled: Invalid owner or file mode for /usr/lib/apache2/suexec

    Thank you for your help

    Reply
    • Dan Zappone says

      April 23, 2016 at 5:04 pm

      You should be able to run a2enmod suexec and theb service apache2 reload to enable it.

      Reply
      • doc_denis says

        April 25, 2016 at 2:49 am

        Hello, I tried without success. “a2enmod suexec”
        I reinstall the server in Ubuntu 16.04 and installed virtualmin
        thank you for your message

        Reply
  3. Michel Doens says

    February 14, 2016 at 12:01 pm

    On the commandline php -v gives the cgi php verison ( not the cli version) which causes errors when using composer. Seems something with the symbolic link workarounds?

    Reply
    • Dan Zappone says

      February 14, 2016 at 8:14 pm

      Thanks Michel! I need to do a little testing but I think the latest version of the PPA no longer requires the FCGI fix to work correctly. I’ll update the tutorial accordingly.

      Reply
  4. J-P says

    January 19, 2016 at 5:35 pm

    Hi Dan

    Your tutorial helped me solve a PHP issue on my Centos7+php56+php7+Atomic Secured Linux+Virtualmin5+dedicated MySQL server with multiple MySQL instances setup which had me pulling my hair out for the last 8 hours or so.

    Thank you!

    J-P

    Reply
    • Dan Zappone says

      January 21, 2016 at 11:41 pm

      Glad it helped!

      Reply
  5. Dan Zappone says

    January 10, 2016 at 8:11 pm

    Now with spell check! I had a few typos which I corrected along with wrong source link.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Follow Us

  • Facebook
  • LinkedIn
  • RSS
  • Twitter

Tags

23Systems about acta actionable alternative php cache apc bbpress beta test colorbox contact design facebook facelift facelift image replacement flir fonts forums gallery gravity forms images internet issues JQuery lightbox Lightbox Plus menus performance photos php plugin Plugins quote resources sopa styles Support technology Themes tutorial video Web design web development web fonts web sites Wordpress

Contact Us

Copyright © 2025 · Agency Pro on Genesis Framework · WordPress · Log in

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT