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 -> Third-party Modules View previous topic :: View next topic
Reply to topic   Topic: Using different PHP installation for one application Page 1, 2  Next
Author
gijs



Joined: 27 Apr 2012
Posts: 189
Location: The Netherlands

PostPosted: Sun 26 Jan '14 17:32    Post subject: Using different PHP installation for one application Reply with quote

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

PostPosted: Mon 27 Jan '14 11:35    Post subject: Using different PHP installation for one application Reply with quote

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

PostPosted: Mon 27 Jan '14 11:59    Post subject: Reply with quote

It is possible using mod_fcgid
There is a topic about that https://www.apachelounge.com/viewtopic.php?t=3430

I run successfully with that method different PHP versions on my servers.
Back to top
Anaksunaman



Joined: 19 Dec 2013
Posts: 54

PostPosted: Mon 27 Jan '14 12:42    Post subject: Using different PHP installation for one application Reply with quote

Ah, very interesting. Thank you. Smile
Back to top
gijs



Joined: 27 Apr 2012
Posts: 189
Location: The Netherlands

PostPosted: Mon 27 Jan '14 13:01    Post subject: Reply with quote

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

PostPosted: Mon 27 Jan '14 21:04    Post subject: Reply with quote

It is possible.
Back to top
gijs



Joined: 27 Apr 2012
Posts: 189
Location: The Netherlands

PostPosted: Tue 28 Jan '14 22:57    Post subject: Reply with quote

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. Confused
Back to top
James Blond
Moderator


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

PostPosted: Tue 28 Jan '14 23:26    Post subject: Reply with quote

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

PostPosted: Tue 28 Jan '14 23:42    Post subject: Reply with quote

Yes that works, thank you Smile
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

PostPosted: Wed 29 Jan '14 0:12    Post subject: Reply with quote

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

PostPosted: Wed 29 Jan '14 2:05    Post subject: Reply with quote

I didn't notice and performance difference Very Happy

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

PostPosted: Wed 29 Jan '14 16:09    Post subject: Reply with quote

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

PostPosted: Wed 29 Jan '14 16:45    Post subject: Reply with quote

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

PostPosted: Wed 29 Jan '14 18:32    Post subject: Reply with quote

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

PostPosted: Wed 29 Jan '14 18:43    Post subject: Reply with quote

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

PostPosted: Thu 30 Jan '14 16:26    Post subject: Reply with quote

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

PostPosted: Thu 30 Jan '14 16:56    Post subject: Reply with quote

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

PostPosted: Thu 30 Jan '14 17:01    Post subject: Reply with quote

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

PostPosted: Thu 30 Jan '14 17:15    Post subject: Reply with quote

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

PostPosted: Thu 30 Jan '14 17:44    Post subject: Reply with quote

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


Reply to topic   Topic: Using different PHP installation for one application View previous topic :: View next topic
Post new topic   Forum Index -> Third-party Modules Page 1, 2  Next