Author |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Sun 26 Jan '14 17:32 Post subject: Using different PHP installation for one application |
|
|
Most of my app's are ready for PHP 5.5 but one of my app's isn't.
Is it possible to globally set PHP 5.5 in the apache config and using a .htaccess or something like that in the app's folder so that it uses a different PHP installation? |
|
Back to top |
|
Anaksunaman
Joined: 19 Dec 2013 Posts: 54
|
Posted: Mon 27 Jan '14 11:35 Post subject: Using different PHP installation for one application |
|
|
Perhaps someone can correct me, but I don't believe it's possible to load php instances via .htaccess.
However, if you google running multiple instances of php on the same server, there are a number of tutorials on this. Essentially you run your second instance of php as cgi in conjunction with a virtual host (possible on a separate port), or, for the more modern versions of php, with PHP-FPM (FastCGI Process Manager)/FastCGI.
That said, dependent on environment, the simplest thing may actually be to have a second instance of Apache running the older version of php, set up as an application server of sorts in conjunction with some manner of reverse proxy.
This second option would most likely be my preferred method in a production environment, just to avoid any possible server issues. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
Anaksunaman
Joined: 19 Dec 2013 Posts: 54
|
Posted: Mon 27 Jan '14 12:42 Post subject: Using different PHP installation for one application |
|
|
Ah, very interesting. Thank you. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Mon 27 Jan '14 13:01 Post subject: |
|
|
Those examples are for a virtual host.
Is it possible to do the same with .htaccess? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 27 Jan '14 21:04 Post subject: |
|
|
It is possible. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Tue 28 Jan '14 22:57 Post subject: |
|
|
I've tried adding:
Code: | FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
AddHandler fcgid-script .php
FcgidWrapper "C:/Progra~2/PHP54/php-cgi.exe" .php |
In to the .htaccess file but it creates a 500 error. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 28 Jan '14 23:26 Post subject: |
|
|
What works is
Code: |
<Files ~ "\.php$">
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "C:/php5/php-cgi.exe" .php
#FcgidWrapper /usr/bin/php5-cgi .php
</Files>
|
|
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Tue 28 Jan '14 23:42 Post subject: |
|
|
Yes that works, thank you
They do seem to share the same php.ini file, how can I change that? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 29 Jan '14 0:12 Post subject: |
|
|
Put the FcgidInitialEnv PHPRC stuff into the Files container.
However: using .htaccess can be a performance killer. Better use only for dev servers. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Wed 29 Jan '14 2:05 Post subject: |
|
|
I didn't notice and performance difference
But when I add the code like this: Code: | <IfModule mod_fcgid.c>
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
FcgidInitialEnv PATH "C:/Progra~2/PHP54;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"
</IfModule> |
or
Code: | <Files ~ "\.php$">
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
FcgidWrapper "C:/Progra~2/PHP54/php-cgi.exe" .php
#FcgidWrapper /usr/bin/php5-cgi .php
</Files> |
It causes a 500 error again. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 29 Jan '14 16:09 Post subject: |
|
|
Well you have combine it.
httpd.conf
Code: |
<IfModule mod_fcgid.c>
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
</IfModule>
|
each htaccess
Code: |
<Files ~ "\.php$">
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
FcgidInitialEnv PATH "C:/Progra~2/PHP54;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
FcgidWrapper "C:/Progra~2/PHP54/php-cgi.exe" .php
</Files>
|
|
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Wed 29 Jan '14 16:45 Post subject: |
|
|
Ahh, I understand.
Is there any other way to do it?
I have a few different virtual hosts and it be a little annoying if I had to change the .htaccess for all of them.
Perhaps it's possible to only use the .htaccess as override or enable it for the other virtual host on the virtual host level and for this one virtual host in .htaccess? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 29 Jan '14 18:32 Post subject: |
|
|
I thought you wanted htaccess ...
of cause you can put the <Files/> block in each vhost. And yes the .htaccess should override it.
Well here one of my test environment configs http://pastebin.com/e7STtCcH |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Wed 29 Jan '14 18:43 Post subject: |
|
|
When I set it for the vhost it works fine, but once I set them in .htaccess it gives a 500 error again.
This is my httpd.conf
Code: | <IfModule mod_fcgid.c>
# Where to look for the php.ini file?
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
# Set PHP_FCGI_MAX_REQUESTS to greater than or equal to FcgidMaxRequestsPerProcess
# to prevent php-cgi process from exiting before all requests completed
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1500
# Maximum requests a process should handle before it is terminated
FcgidMaxRequestsPerProcess 0
# Maximum number of PHP processes
FcgidMaxProcesses 300
FcgidMaxRequestInMem 268435456
FcgidOutputBufferSize 268435456
FcgidProcessLifeTime 43200
FcgidMinProcessesPerClass 300
FcgidMaxRequestLen 1073741824
FcgidProcessLifeTime 10800
FcgidZombieScanInterval 20
FcgidTimeScore 3
# Number of seconds of idle time before a php-cgi process is terminated
FcgidIdleTimeout 0
FcgidIOTimeout 40
FcgidConnectTimeout 16
<Files ~ "\.php$">
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "C:/Progra~2/php/php-cgi.exe" .php
</Files>
</IfModule>
|
I've also tried with this:
Code: | <IfModule mod_fcgid.c>
# Where to look for the php.ini file?
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
# Set PHP_FCGI_MAX_REQUESTS to greater than or equal to FcgidMaxRequestsPerProcess
# to prevent php-cgi process from exiting before all requests completed
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1500
# Maximum requests a process should handle before it is terminated
FcgidMaxRequestsPerProcess 0
# Maximum number of PHP processes
FcgidMaxProcesses 300
FcgidMaxRequestInMem 268435456
FcgidOutputBufferSize 268435456
FcgidProcessLifeTime 43200
FcgidMinProcessesPerClass 300
FcgidMaxRequestLen 1073741824
FcgidProcessLifeTime 10800
FcgidZombieScanInterval 20
FcgidTimeScore 3
# Number of seconds of idle time before a php-cgi process is terminated
FcgidIdleTimeout 0
FcgidIOTimeout 40
FcgidConnectTimeout 16
</IfModule>
|
|
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Thu 30 Jan '14 16:26 Post subject: |
|
|
I think the problem is with
Code: | <Files ~ "\.php$">
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
FcgidInitialEnv PATH "C:/Progra~2/PHP54;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
FcgidWrapper "C:/Progra~2/PHP54/php-cgi.exe" .php
</Files> |
I tried:
Code: | <Files ~ "\.php$">
FcgidInitialEnv PATH "C:/Progra~2/PHP54;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv PHPRC "C:/Progra~2/PHP54"
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "C:/Progra~2/PHP54/php-cgi.exe" .php
</Files> |
But it still gives 500 errors. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 30 Jan '14 16:56 Post subject: |
|
|
Sorry, but FcgidInitialEnv can't bet set in .htaccess
That has to be in the vhost config. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Thu 30 Jan '14 17:01 Post subject: |
|
|
Ahh I see.
Would it be possible to make a different vhost, which still loads as domain.com/program/
If not I'll have to use program.domain.com and rewrite all my url's... |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 30 Jan '14 17:15 Post subject: |
|
|
You can have different domain names with the same document root.
Or the same domain name on different ports. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Thu 30 Jan '14 17:44 Post subject: |
|
|
In that case I think it's best to make a new folder and host it under its own subdomain.
And then putting a redirect in the folder it's currently located in. |
|
Back to top |
|