Multiple php versions

Hi,

I would like to ask if I can install and use multiple php versions. I have ubuntu 14.04.

Thanks.

Status: 
Active

Comments

Howdy -- there unfortunately isn't a simple way to do that with Ubuntu 14.04.

CentOS has a repository called "Software Collections", that makes this super simple. In that repository, they have packages designed to be installed side-by-side with your existing software.

With Ubuntu, it's possible to install a second PHP version, but you would need to manually compile and install the new software you're interested in. There isn't a repository they provide which handles that.

itwebservices's picture
Submitted by itwebservices on Mon, 03/14/2016 - 18:04

yes, I have read that and I have manually compile another version of php but the system cannot switch them.

I have installed the latest php version two months ago and I could switch them.

Is there any way?

Now I have the following php:

root@server ~ # php -v PHP 5.6.16 (cli) (built: Jan 27 2016 23:41:05) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

To add an additional manually compiled PHP version, what you'd need to do is provide the path to that PHP version in System Settings -> Virtualmin Config -> PHP Options.

There, you'll see an option named "Additional locations for PHP commands", where you can input the path to an additional PHP binary that you've installed.

itwebservices's picture
Submitted by itwebservices on Tue, 03/15/2016 - 07:21

could you tell me how can I find the php that it has installed with virtualmin and the php that I have installed manually? How can I find all the versions of php I have? Or when I have installed the new version it overrides the old one?

Well, that all depends on how the new PHP version was installed. That's not something we would know (if that were easy for us to know, it would actually be programmed into Virtualmin to just detect any newly installed version).

I can offer that the standard PHP version is installed in /usr/bin/php-cgi.

However, a manually compiled/installed version wouldn't necessarily be named that. And it could be located anywhere.

Note that I wouldn't recommend overwriting the existing PHP version with the new one. And so long as both are installed, Virtualmin can use both at the same time.

itwebservices's picture
Submitted by itwebservices on Tue, 03/15/2016 - 12:20

yes I understand.

The system php located in /usr/bin/php-cgi

I have begun the installation from /install/php/php-5.6.16/. Then I run the commands: ./configure make install install

so I thought that it is installed to the folder: /usr/share/php5/ according to the following command.

root@server ~ # locate php.ini /etc/php5/apache2/php.ini /etc/php5/cgi/php.ini /etc/php5/cli/php.ini

/install/php/php-5.6.16/php.ini-development /install/php/php-5.6.16/php.ini-production

/usr/share/php5/php.ini-development /usr/share/php5/php.ini-production /usr/share/php5/php.ini-production.cli root@server ~ #

Now, what I should add to the field "Additional locations for PHP commands"? Will be correct if I add "/usr/share/php5/"?

Also, I would like to mention that from Virtualmin (server configuration --> php versions) I get the message below: Your system only has PHP version 5.5.9 installed, so selecting a different version for each directory is not possible.

but from ssh I get the message root@server ~ # php -v PHP 5.6.16 (cli) (built: Jan 27 2016 23:41:05) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

So it seems to be I have two php versions but I don't know which of them is active.

Hmm, what is the output of these two commands:

which php
/usr/bin/php -v
itwebservices's picture
Submitted by itwebservices on Tue, 03/15/2016 - 12:59

root@server ~ # which php /usr/local/bin/php

root@server ~ # /usr/bin/php -v PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

root@server ~ # /usr/local/bin/php -v PHP 5.6.16 (cli) (built: Jan 27 2016 23:41:05) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

It looks like you have another PHP version installed into /usr/local.

If there is a "/usr/local/bin/php-cgi", that's what you'd want to add into Virtualmin.

itwebservices's picture
Submitted by itwebservices on Tue, 03/15/2016 - 13:28

yes! Perfect!

http://awesomescreenshot.com/05e5poit8a

Let me ask you something else. What I have to add to the field below the "Default HTML directory" field? Also If I download and install the latest version (5.6.19), it will override the version 5.6.16 I have installed manually?

Would you like to give you access to check it?

It all depends on how the new version is installed. If the new PHP version overwrites the previous version, then it would override it.

If it's installed in another location, then it could be used in addition to it.

Regarding your "Default HTML directory" question -- that column is named "Website Subdirectory".

What that means is that you can have different PHP versions for different sub-directories in your public_html folder.

For example, you could keep the "Default HTML directory" set to PHP 5.5.9. But you could install, say, Joomla into a folder named "joomla", and then have it use PHP 5.6.16.

itwebservices's picture
Submitted by itwebservices on Tue, 03/15/2016 - 14:37

I name it "Joomla" but I don't understand what changes. Where can I select php versions to a joomla website for example?

When I install a new version of php, I download it, I extract it and the I run the commands below. ./configure make install install

Could you tell me how can I specify a "custom" location during a new version of php installation?

We unfortunately don't have instructions for custom installing PHP. I'm not sure what the exact syntax would be, you may need to review the documentation, or chat with the folks over at php.net regarding that. There is likely some sort of path or prefix parameter you would need to set though.

Regarding how to specify a different PHP version for a particular directory --

Let's say that you installed Joomla into the "joomla" directory in public_html.

In the "Website subdirectory" column, you would add "joomla" to the text box. Next to that, you would specify your preferred PHP version.

Then click the "Save versions" button.

itwebservices's picture
Submitted by itwebservices on Wed, 03/16/2016 - 08:54

ok! I understand!

Let me ask you something. I have set the new version of php but when I try to install a joomla site an error require to enable "zlib" from php.ini. I have set the "zlib" to "On" from /etc/php5/php.ini but I think that this php.ini file concerns the virtualmin system version. Do you know where I can find the php.ini for the new version of php in order to change it?

Thanks.

You should see the PHP configs for your domain located in $HOME/etc, there may be multiple directories in there (if Virtualmin was able to find the main PHP configs).

However, I don't know where the php.ini file for a custom installed PHP version would be, it all depends on how the custom installation was performed. They may be somewhere in /usr/local though, since that's where your PHP command was.

itwebservices's picture
Submitted by itwebservices on Wed, 03/16/2016 - 12:33

unfortunately, I change all the php.ini file but only the virtualmin system php is working.

In home/domain/etc/ there is only the virtualmin system php.ini.

However, If I would like to update the virtualmin system php, is it possible and how can I do it? For example, now I have the 5.5.9 and the lastest version is the 5.6.19.

Virtualmin doesn't actually provide a PHP version... during the Virtualmin installation, the installer just tells your distribution to install the PHP version included with it.

PHP 5.5.9 is the only official PHP version that is available to Ubuntu 14.04.

The only officially supported way of installing multiple PHP versions, or newer PHP versions, would be to use CentOS, where you would have access to the CentOS SCL repository. Using that, there are multiple newer PHP versions that you could install alongside the standard CentOS PHP version.

Joe's picture
Submitted by Joe on Wed, 03/16/2016 - 13:10 Pro Licensee

I believe there is a PPA for newer PHP on Ubuntu. That would be the first place I'd look. I don't think we've had enough input from folks on that being something that is recognized by Virtualmin without configuration (and I don't know if it is technically easy, as it is for SCL on CentOS), but I think that's the direction we'd want to go for users on Ubuntu trying to use newer versions.

That said: unless there is a feature you need in the newer PHP, sticking with the distro default is wise. Virtualmin will support almost anything with the right configuration, but the amount of testing and security-related attention a PPA gets vs. the distro version is gonna be much lower.

Joe's picture
Submitted by Joe on Wed, 03/16/2016 - 13:18 Pro Licensee

Specifically, this one looks well-supported and maintained:

https://launchpad.net/~ondrej/+archive/ubuntu/php

If you try this, let us know how it works (the PHP packages; we'll help make Virtualmin work with it). If the packages are solid, we'll look into adding some kind of automatic detection and configuration for PPA installed PHP versions. (We have a lot fewer Ubuntu users than CentOS, so stuff like this comes as Ubuntu users ask for it, rather than as the first iteration of a new feature.)

Joe's trying to be helpful, but I'd urge caution in using non-standard packages on a live server. They don't always install seamlessly.

If you want to try that out, great, but be careful doing that on a live server, as sometimes it can change the PHP configuration in subtle ways that can cause some problems.

If you could, I'd recommend trying it on a test server before installing that onto your production server.

Also, I should ask -- is there something you need in the latest PHP version, that isn't available in PHP 5.5.9?

Although PHP 5.5.9 looks older than the most recent PHP available, Ubuntu (and other distributions) backport bugfixes and security updates into the software they release.

So you're using a secure PHP version. It may be missing some of the more bleeding edge features that PHP 5.6.x has, but it's otherwise fully functional and up to date.

itwebservices's picture
Submitted by itwebservices on Thu, 03/17/2016 - 16:31

No, but I would like to have at least two versions of php (latest and some older). Sometimes, some applications requires to have a php version an above. If I stay in 5.5.9 and in two months I need to update the php what and how can I do?

There isn't currently a supported way of installing a second PHP version, or a newer PHP version, using any distros other than CentOS.

We suggest using the distro's PHP version, which is 5.5.9 in this case. And if you need a newer PHP version down the road, you can always upgrade to a more recent distribution (Ubuntu 16.04 comes out in April, for example, and will have PHP 7).

You could also try the packages Joe mentioned, but that's not something we recommend or support. That said, there are people who use them.

itwebservices's picture
Submitted by itwebservices on Wed, 03/30/2016 - 16:46

I would like also to mention that Virtualmin under the domains can see only the php that installed with Virtualmin. The manually installed php version cannot be seen from virtualmin under domain...

Is there any solution from Virtualmin for that?

Trying to setup a second PHP version, when not using CentOS, is going to be complicated.

I have not tested the above, so I unfortunately don't know if that will work properly.

However, if you are able to install a second PHP version, you can tell Virtualmin about it by going into System Settings -> Virtualmin Config -> PHP Options, and there you can provide the path to your additional PHP command(s).

Also, your server isn't actually using PHP FPM, it's using CGI and FCGID. If you're going to compile PHP, you'd want to compile it with CGI and FCGID options, rather than PHP-FPM.

itwebservices's picture
Submitted by itwebservices on Fri, 04/01/2016 - 18:11

I try to install the phpPgAdmin script and I get the error below.

PHP module pgsql is required .. Enabling module in PHP configuration ..

How can I enable the pgsql ?

Just to clarify, is that for the standard PHP version included with your distro, or is it using an alternate PHP version?

itwebservices's picture
Submitted by itwebservices on Sat, 04/02/2016 - 03:50

For the standard PHP version included with my distro,

Okay, try running this command:

apt-get install php5-pgsql

That will install the pgsql PHP module on Ubuntu.

After doing that, see if you're able to install that script.

itwebservices's picture
Submitted by itwebservices on Sat, 04/02/2016 - 14:02

already installed....

root@server ~ # apt-get install php5-pgsql
Reading package lists... Done
Building dependency tree
Reading state information... Done
php5-pgsql is already the newest version.
php5-pgsql set to manually installed.
The following packages were automatically installed and are no longer required:
  linux-headers-3.19.0-49 linux-headers-3.19.0-49-generic
  linux-image-3.19.0-49-generic linux-image-extra-3.19.0-49-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
root@server ~ #

This issue here may be related to the other issue you mentioned, where a few different install scripts weren't working for you.

I tried creating a basic test.php script, which would test that PHP was working properly -- and that failed.

So for some reason, basic PHP functionality isn't working on your server.

Did you attempt enabling an alternate PHP version? I'm wondering if it's trying to use that, rather than the default PHP that comes with your distro.

Ah, I see the problem.

It looks like the option "allow_call_time_pass_reference" had been enabled.

That is causing it to throw a PHP error, as that option is no longer supported in PHP.

At least, that's the error when I tested it with the koryfaia.gr domain.

Here's what I'd suggest -- first, if that option is enabled for the domain you're testing in $HOME/etc/php.ini, comment out that option.

If you continue to have a problem, first try changing the PHP Execution Mode to CGI in Server Configuration -> Website Options.

Then, access the PHP script, and then look at the error log in $HOME/logs/error_log.

You should there see the cause of the problem that you're experiencing.

itwebservices's picture
Submitted by itwebservices on Sun, 04/03/2016 - 12:17

ok. The pgadmin is working now. How can I disable "allow_call_time_pass_reference" for all domains?

Also, let me ask you something. What option is better for running the websites? 1) CGI wrapper (run as virtual server owner) 2) FCGId (run as virtual server owner)

Using CGI can be helpful for troubleshooting, as it produces better error messages.

But FCGID is a little faster, and is good for production environments.

As for allow_call_time_pass_reference -- I just checked, it doesn't appear to be enabled for any other domains.