logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: Vhosts with mutiple php versions
Author
hankman



Joined: 08 Jan 2008
Posts: 24
Location: Veghel, NL

PostPosted: Wed 24 Jun '15 16:30    Post subject: Vhosts with mutiple php versions Reply with quote

I have a site with multiple hosts running. Things work just fine. Now I want to run each host with a different php version. Just can't find out how to configure this, searched this site and the web.

Some sugguestions would be welcome. Thanks in advance.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Wed 24 Jun '15 16:59    Post subject: Reply with quote

You have to search better Smile

More posts about it, see for example www.apachelounge.com/viewtopic.php?t=5773 and www.apachelounge.com/viewtopic.php?t=3430

James Blond is the specialist !
Back to top
hankman



Joined: 08 Jan 2008
Posts: 24
Location: Veghel, NL

PostPosted: Thu 25 Jun '15 0:54    Post subject: Reply with quote

Maybe I don't understand completely the information at the suggested links,
but what I really want to do is the following:

vhost 1 needs to run php 5.6
vhost 2 needs to run php 7
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Thu 25 Jun '15 23:25    Post subject: Reply with quote

Do you have mod_fcgid installed?

Did you want to load the different mod_phps for the 2 vhosts? Looking at the Apache docs LoadModule and LoadFile can be used in the VirtualHost context so it may be possible. I've never tried it.

With mod_fcgid it would look something like

Code:
#using mod_fcgid and /home/vhost1/php.ini
<VirtualHost *:80>
    ServerName vhost1.example.com
    DocumentRoot "/home/vhost1/htdocs"
      FcgidInitialEnv PHPRC "/home/vhost1"
      AddHandler fcgid-script .php
      FcgidWrapper "/php56/php-cgi.exe" .php
</VirtualHost>

#using mod_fcgid and /home/vhost2/php.ini
<VirtualHost *:80>
    ServerName vhost2.example.com
    DocumentRoot "/home/vhost2/htdocs"
      FcgidInitialEnv PHPRC "/home/vhost2"
      AddHandler fcgid-script .php
      FcgidWrapper "/php7/php-cgi.exe" .php
</VirtualHost>


With mod_php it would look something like

Code:
#using mod_php and /home/vhost1/php.ini
<VirtualHost *:80>
    ServerName vhost1.example.com
    DocumentRoot "/home/vhost1/htdocs"
    LoadModule php5_module /php56/php5apache2_4.dll
    Loadfile /php56/php5ts.dll
    PHPIniDir /php56
    AddType application/x-httpd-php .php
</VirtualHost>

#using mod_php and /home/vhost2/php.ini
<VirtualHost *:80>
    ServerName vhost2.example.com
    DocumentRoot "/home/vhost2/htdocs"
    LoadModule php7_module /php7/php5apache2_4.dll
    Loadfile /php7/php7ts.dll
    PHPIniDir /php7
    AddType application/x-httpd-php .php
</VirtualHost>

You need thread safe versions and
I've never tried this so it may not work.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1266
Location: Amsterdam, NL, EU

PostPosted: Fri 26 Jun '15 12:04    Post subject: Reply with quote

I would be really surprised if mod_php could be loaded into Apache multiple times with different PHP-versions. With mod_fcgid it seems possible:
https://bbs.archlinux.org/viewtopic.php?pid=901050#p901050

Skip the part of building PHP, but look at the confs. NaX_sa defines a php52_fcgid.conf and a php53_fcgid.conf and loads one of them in the Virtualhost context.

If you only need 2 different versions the easy way is to use one with mod_php (php5apache2_4.dll loading a TS version) and one with mod_fcgid (loading a NTS version as NTS is faster than TS). I am running this in production: PHP 5.3 for Drupal6 and PHP 5.5/5.6 for all other frameworks. Note: you cannot use OPcache for both versions. Use for instance php_opcache.dll for the PHP TS version and php_wincache.dll or php_xcache.dll for the PHP NTS version.

In the Virtualhost context you can decide which PHP version to use. If you do not specify anything it will use the PHP that is loaded with mod_php.

You can also use this in the Directory context:
Code:

   <FilesMatch "\.(php|inc)$">
      SetHandler application/x-httpd-php
      <IfModule fcgid_module>
         Options +ExecCGI
         SetHandler fcgid-script
      </IfModule>
   </FilesMatch>

or just
Code:

   <FilesMatch "\.(php|inc)$">
      SetHandler application/x-httpd-php
   </FilesMatch>

Be aware the Directory context is inherited for all subdirs.


Last edited by Jan-E on Fri 26 Jun '15 17:29; edited 1 time in total
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Fri 26 Jun '15 17:01    Post subject: Reply with quote

Since Steffen mentioned my name ...

In each vhost I use something like

Code:

   <IfModule fcgid_module>
      FcgidInitialEnv PHPRC "C:\\php5"
      FcgidInitialEnv PATH "C:\\php5;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;"
      FcgidInitialEnv SystemRoot "C:\\Windows"
      FcgidInitialEnv SystemDrive "C:"
      FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP"
      FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP"
      FcgidInitialEnv windir "C:\\WINDOWS"
      FcgidPassHeader Authorization
      <Files ~ "\.php$">
         Options Indexes FollowSymLinks ExecCGI
         AddHandler fcgid-script .php
         FcgidWrapper "C:/php5/php-cgi.exe" .php
         AddHandler fcgid-script .html
         FcgidWrapper "C:/php5/php-cgi.exe" .html
      </Files>
   </IfModule>


and in the global context

Code:
<IfModule fcgid_module>
   FcgidConnectTimeout 10
   FcgidMaxProcesses 300
   FcgidMaxProcessesPerClass 300
   FcgidOutputBufferSize 64
   ProcessLifeTime 0
   FcgidMaxRequestsPerProcess 0
   FcgidMinProcessesPerClass 0
   FcgidFixPathinfo 0
   FcgidProcessLifeTime 0
   FcgidZombieScanInterval 20
   FcgidMaxRequestLen 536870912
   FcgidIOTimeout 120
   FcgidTimeScore 3
</IfModule>
Back to top
tgabor



Joined: 09 Oct 2015
Posts: 2
Location: Hungary, Budapest

PostPosted: Fri 09 Oct '15 14:43    Post subject: Reply with quote

We also, in our production-server we want to execute multiple PHP version.

Windows 10 / 64
Intel Core i5 3.2GHz, 8 Gb RAM
Apche/2.4.16 (Win64)

We realized after much experimentation, that each PHP releases own environment variables must be ensured. with FcgidCmdOptions. See below how.
Otherwise, there were frequent errors. ( Like: End of script output before headers, mod_fcgid: get overlap result error)

It is important that every 7 options must have a value! ( http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidcmdoptions )
However, there is a problem;
PHP5.5 and PHP5.6 version use OPCACHE.
If PHP7(RC4, 64 bit) in addition to permitting the use of OPCACHE, the system unstable again.

My question is: This PHP7 bug, or config error?

Code:
Define PHP53 'C:/webservices/php53_32_nts'
Define PHP54 'C:/webservices/php54_32_nts'
Define PHP55 'C:/webservices/php55_32_nts'
Define PHP56 'C:/webservices/php56_32_nts'
Define PHP7064 "C:/webservices/php70_64_nts"

FcgidCmdOptions '${PHP53}/php-cgi.exe' \
      InitialEnv Path='${PHP53};${Path}' \
      InitialEnv PHPRC=${PHP53} \
      InitialEnv PHP_FCGI_MAX_REQUESTS=10000 \
      ConnectTimeout 30 \
      IdleTimeout 120 \
      IOTimeout 600 \
      MaxProcesses 10 \
      MaxProcessLifeTime 240 \
      MaxRequestsPerProcess 5000 \
      MinProcesses 0

   
   FcgidCmdOptions '${PHP54}/php-cgi.exe' \
      InitialEnv PATH='${PHP54};${Path}' \
      InitialEnv PHPRC=${PHP54} \
      InitialEnv PHP_FCGI_MAX_REQUESTS=10000 \
      ConnectTimeout 30 \
      IdleTimeout 120 \
      IOTimeout 600 \
      MaxProcesses 10 \
      MaxProcessLifeTime 240 \
      MaxRequestsPerProcess 5000 \
      MinProcesses 0

   FcgidCmdOptions '${PHP55}/php-cgi.exe' \
      InitialEnv PATH='${PHP55};${Path}' \
      InitialEnv PHPRC=${PHP55} \
      InitialEnv PHP_FCGI_MAX_REQUESTS=10000 \
      ConnectTimeout 30 \
      IdleTimeout 120 \
      IOTimeout 600 \
      MaxProcesses 10 \
      MaxProcessLifeTime 240 \
      MaxRequestsPerProcess 5000 \
      MinProcesses 0
   
   FcgidCmdOptions '${PHP56}/php-cgi.exe' \
      InitialEnv PATH='${PHP56};${Path}' \
      InitialEnv PHPRC=${PHP56} \
      InitialEnv PHP_FCGI_MAX_REQUESTS=10000 \
      ConnectTimeout 30 \
      IdleTimeout 120 \
      IOTimeout 600 \
      MaxProcesses 10 \
      MaxProcessLifeTime 240 \
      MaxRequestsPerProcess 5000 \
      MinProcesses 0

   FcgidCmdOptions '${PHP7064}/php-cgi.exe' \
      InitialEnv PATH='${PHP7064};${Path}' \
      InitialEnv PHPRC=${PHP7064} \
      InitialEnv PHP_FCGI_MAX_REQUESTS=10000 \
      ConnectTimeout 30 \
      IdleTimeout 120 \
      IOTimeout 600 \
      MaxProcesses 10 \
      MaxProcessLifeTime 240 \
      MaxRequestsPerProcess 5000 \
      MinProcesses 0

   # It seems, they must be defined as "quasi-global"
   FcgidInitialEnv SystemDrive '${SystemDrive}'
   FcgidInitialEnv SystemRoot '${SystemRoot}'
   FcgidInitialEnv windir '${windir}'
Back to top
tgabor



Joined: 09 Oct 2015
Posts: 2
Location: Hungary, Budapest

PostPosted: Fri 09 Oct '15 14:58    Post subject: Reply with quote

yeah, I forgot:

Above code is in httpd.conf and in vh.conf looks like:

Code:
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin info@example.com
   
...
   FcgidWrapper '${php_path}/php-cgi.exe \
      -d open_basedir=${vh_dir}/ \
      -d upload_tmp_dir=${vh_dir} \
      -d opcache.enable=1' .php
       
   
    <Directory '${vh_dir}'>
        <IfModule fcgid_module>
            AddHandler fcgid-script .php
        </IfModule>
    </Directory>

</VirtualHost>
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 12 Oct '15 16:34    Post subject: Reply with quote

tgabor wrote:

My question is: This PHP7 bug, or config error?


I think it is an PHP7 issue. It is RC4.

See https://bugs.php.net/search.php?limit=30&order_by=id&direction=DESC&cmd=display&status=Open&bug_type=All&phpver=7.0

If there isn't a bug yet you may file a bug at https://bugs.php.net/
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1266
Location: Amsterdam, NL, EU

PostPosted: Wed 14 Oct '15 18:25    Post subject: Reply with quote

PHP 7.0.0 RC5 is in the Members Downloads forum now.
Back to top


Reply to topic   Topic: Vhosts with mutiple php versions View previous topic :: View next topic
Post new topic   Forum Index -> Other Software