Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: PHP as FCGID w/multiple PHP.INI files |
|
Author |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Wed 10 Mar '10 1:24 Post subject: PHP as FCGID w/multiple PHP.INI files |
|
|
First off, I did try to search AL for this topic, without success.
I have researched to the best of my current abilities to answer this without success.
Currently FCGID resolves the issue of stability having to call numerous non-thread-safe EXE's via PHP's EXEC() and SYSTEM() commands.
I have about 400 vhosts. I want to have at least two different PHP.INI files, at least two but maybe more.
The services I offer use a web-based file management, customized mail services, online image manipulation services, online media conversion services and so on. These all use a huge number of command line capable apps to make this all happen in this manner and PHP is so darn easy to code and secure, I just hate think that I have to go down a different path, starting over.
I could run some users, the bulk of my VHOSTS with the PHP module, but then I am running a more complicated environment than I would like to. If that is the only option for having multiple INI files, then so be it.
######################
My Questions: Is it possible in WAMP to run PHP exclusively as FCGID and have different PHP.INI files?
If so, how?
######################
|
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Wed 10 Mar '10 3:33 Post subject: |
|
|
php.example.com uses mod_php and it's one php.ini file
user1.example.com uses mod_fcgid and loads only the php.ini file in /home/user1
user2.example.com uses mod_fcgid and loads only the php.ini file in /home/user2
user3.example.com uses mod_fcgid but loads mod_php's php.ini file
Code: |
#httpd.conf
LoadModule php5_module /php/php5apache2_2.dll
LoadModule fcgid_module modules/mod_fcgid.so
PHPIniDir /php
<IfModule fcgid_module>
# whatever directives wanted bla bla bla
# Use same php.ini as mod_php globally for mod_fcgid
FcgidInitialEnv PHPRC "/php"
</IfModule>
#httpd-vhost.conf
#using mod_php and /php/php.ini
<VirtualHost *:80>
ServerName php.example.com
DocumentRoot "/home/htdocs"
</VirtualHost>
#using mod_fcgid and /home/user1/php.ini
<VirtualHost *:80>
ServerName user1.example.com
DocumentRoot "/home/user1/htdocs"
FcgidInitialEnv PHPRC "/home/user1"
AddHandler fcgid-script .php
FcgidWrapper "/php/php-cgi.exe" .php
</VirtualHost>
#using mod_fcgid and /home/user2/php.ini
<VirtualHost *:80>
ServerName user2.example.com
DocumentRoot "/home/user2/htdocs"
FcgidInitialEnv PHPRC "/home/user2"
AddHandler fcgid-script .php
FcgidWrapper "/php/php-cgi.exe" .php
</VirtualHost>
#using mod_fcgid and global php.ini
<VirtualHost *:80>
ServerName user3.example.com
DocumentRoot "/home/user3/htdocs"
AddHandler fcgid-script .php
FcgidWrapper "/php/php-cgi.exe" .php
</VirtualHost>
|
There may be other ways to do this but this works for me.
There is no need to use mod_php I just did it cause I want to show the mix & match aspect of it.
Last edited by glsmith on Wed 10 Mar '10 18:34; edited 1 time in total |
|
Back to top |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Wed 10 Mar '10 7:25 Post subject: |
|
|
Many thanks for this incredibly simple explanation.
Checked the test INI files, perfect.
Currently I am in test flight, but this solution looks promising.
Question: Do you notice any change in memory usage?
Even if the processing load creates more load, even if it were to and if it were to use more RAM, so what! This should be rock solid stable.
Thank you very much for your fast reply. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 10 Mar '10 10:36 Post subject: |
|
|
Hi Brian,
there no more usage with using different ini files as I know from my experience. At least if you don't load a different number of extensions. You should also be able to load different php version. Sometimes very useful for testing. |
|
Back to top |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Thu 11 Mar '10 5:28 Post subject: |
|
|
Different PHP versions, actually that can be important.
I have one extension that I use with ImageMagick, it requires a 4.x.x version of PHP but does somethings that I need very nicely.
I will probably end up running PHP as CGI and Module after all.
FCGID has really come a long ways with regards for PHP support and on Windows it really was needed.
I am running a full testing server on my workstation and so far I am very happy.
I have not had a chance to set up MySQL and also MSSQL yet. I also have an application for using an ODBC connection (SQLite3?) to pull data to generate reports from a Spiceworks db file. I used SQLite3 to pull live data into Excel so I assume that is the same connector PHP would use, not sure yet though.
I really appreciate AL and the many experienced contributors here, my simple question was thoroughly and quickly answered. Thank you. |
|
Back to top |
|
flatcircle
Joined: 27 Jun 2006 Posts: 79
|
Posted: Thu 11 Nov '10 15:18 Post subject: |
|
|
Is this correct?
<VirtualHost *:80>
ServerName php.example.com
DocumentRoot "/home/htdocs"
</VirtualHost>
Shouldn't the line:
Code: | AddType application/x-httpd-php .php |
be included as well?
mod_php => AddType application/x-httpd-php .php
Code: | <VirtualHost *:80>
ServerName php.example.com
DocumentRoot "/home/htdocs"
AddType application/x-httpd-php .php
</VirtualHost> |
mod_fcgid => AddHandler fcgid-script .php
Code: | <VirtualHost *:80>
ServerName user1.example.com
DocumentRoot "/home/user1/htdocs"
FcgidInitialEnv PHPRC "/home/user1"
AddHandler fcgid-script .php
FcgidWrapper "/php/php-cgi.exe" .php
</VirtualHost> |
|
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
Posted: Mon 03 Jan '22 17:44 Post subject: |
|
|
Hi,
I know that this thread is old, nevertheless, since we talk about Wampserver and that it is there, with the help of glasmith - thanks to him - that I found how to do it, I post here :
How to use fcgid_module and have different PHP versions for VirtualHost
- Procedure done under Wampserver 3.2.7 with Apache 2.4.52
To be done with Wampserver not started.
- 1 - Of course, the first thing to do is to download fcgid_module from the Apache Lounge download page depending on whether you use 32 or 64 bit Wampserver.
Unzip the related zip file and copy the 'mod_fcgid.so' file to the wamp(64)\bin\apache2.4.52\modules\ folder
- 2 - Edit the file wamp(64)\bin\apache2.4.52\conf\httpd.conf
Under the line: LoadModule php_module "${INSTALL_DIR}/bin/php/php.... (About line 199)
Be careful, it can be php7_module or php5_module depending on the php version used.
Add:
Code: |
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
FcgidMaxProcessesPerClass 300
FcgidConnectTimeout 10
FcgidProcessLifeTime 0
FcgidMaxRequestsPerProcess 0
FcgidMinProcessesPerClass 0
FcgidFixPathinfo 0
FcgidZombieScanInterval 20
FcgidMaxRequestLen 536870912
FcgidIOTimeout 120
FcgidTimeScore 3
FcgidPassHeader Authorization
Define PHPROOT ${INSTALL_DIR}/bin/php/php
</IfModule>
|
If you start Wampserver at this moment, nothing will change, all the VirtualHost will always use the version of PHP defined by the menu Left-Click -> PHP, i.e. PHP defined as an Apache module.
To use another PHP version, of course provided that this version already exists in Wampserver as an addon, simply modify the desired VirtualHost as follows:
By default, a VirtualHost created by Wampserver looks like this:
Code: |
<VirtualHost *:80>
ServerName mysite
DocumentRoot "G:/www/myfolder"
<Directory "G:/www/myfolder/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride all
Require local
</Directory>
</VirtualHost>
|
In order for this VirtualHost to use fcgid_module and another version of PHP, we just need to add four lines, the first of which defines the version of PHP to be used and, to avoid any error if the fcgid_module is not loaded, we will frame these four lines with a <IfModule fcgid_module>... </IfDefine> structure:
Code: |
<IfModule fcgid_module>
Define FCGIPHPVERSION "7.2.34"
FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</IfDefine>
|
and you must add the +ExecCGI option in the Directory options for the VirtualHost.
This makes the VirtualHost become:
Code: |
<VirtualHost *:80>
ServerName mysite
DocumentRoot "G:/www/myfolder"
<IfModule fcgid_module>
Define FCGIPHPVERSION "7.2.34"
FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</IfDefine>
<Directory "G:/www/myfolder/">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AllowOverride all
Require local
</Directory>
</VirtualHost>
|
And that's all.
Last edited by Otomatic on Tue 04 Jan '22 10:28; edited 1 time in total |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3094 Location: Hilversum, NL, EU
|
Posted: Mon 03 Jan '22 17:59 Post subject: |
|
|
Thanks for sharing. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Tue 04 Jan '22 13:18 Post subject: |
|
|
Otomatic wrote: |
and you must add the +ExecCGI option in the Directory options for the VirtualHost.
This makes the VirtualHost become:
|
Nope! Don't do that. Only enable that for php files.
Code: |
# httpd.conf
Define PHP80RC "C:\\php80"
<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>
|
Code: |
#vhost config file
<VirtualHost *:80>
ServerName website
DirectoryIndex index.php index.html index.htm
<IfModule fcgid_module>
FcgidInitialEnv PHPRC "${PHP80RC}"
FcgidInitialEnv PATH "${PHP80RC};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:/php80/php-cgi.exe" .php
</Files>
</IfModule>
CustomLog "C:\nul" common
DocumentRoot "G:/www/myfolder"
<Directory "G:/www/myfolder">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
|
As you can see <Files ~ "\.php$"> is a much better option for security. |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
Posted: Fri 14 Jan '22 16:28 Post subject: |
|
|
Hi,
Here I am now and it seems to work correctly while keeping PHP as an Apache module that coexists with fcgid_module.
In the file httpd.conf:
Code: | PHPIniDir "${APACHE_DIR}/bin"
LoadModule php_module "${INSTALL_DIR}/bin/php/php8.1.1/php8apache2_4.dll"
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
FcgidMaxProcessesPerClass 300
FcgidConnectTimeout 10
FcgidProcessLifeTime 1800
FcgidMaxRequestsPerProcess 0
FcgidMinProcessesPerClass 0
FcgidFixPathinfo 0
FcgidZombieScanInterval 20
FcgidMaxRequestLen 536870912
FcgidBusyTimeout 120
FcgidIOTimeout 120
FcgidTimeScore 3
FcgidPassHeader Authorization
Define PHPROOT ${INSTALL_DIR}/bin/php/php
</IfModule>
|
In the httpd-vhosts.conf, to use fcgi in place of Apache module.
Code: | <VirtualHost *:80>
ServerName faq-fra-fcgi
DocumentRoot "g:/www/faq-fra"
<IfModule fcgid_module>
Define FCGIPHPVERSION "7.4.27"
FcgidInitialEnv PHPRC "${PHPROOT}${FCGIPHPVERSION}/php.ini"
<Files ~ "\.php$">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</Files>
</IfModule>
<Directory "g:/www/faq-fra/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
|
Where I had a little problem is for the aliases.
Indeed if I apply for the aliases the same procedure as for the VirtualHost, for example for the alias PhpMyAdmin 5.1.1 which is not compatible with PHP 8.1.1:
Code: |
Alias /phpmyadmin "E:/wamp64/apps/phpmyadmin5.1.1/"
<IfModule fcgid_module>
Define FCGIPHPVERSION "7.4.27"
FcgidCmdOptions ${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe \
InitialEnv PHPRC=${PHPROOT}${FCGIPHPVERSION}/php.ini
<Files ~ "\.php$">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</Files>
</IfModule>
<Directory "E:/wamp64/apps/phpmyadmin5.1.1/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require local
</Directory>
|
This alias being launched by 'http://localhost/phpmyadmin/' it is the whole localhost which passes in fcgi mode and that, I do not want it. I want localhost to stay in Apache module.
To do this, I first wanted to put the <IfModule...>...</IfModule> structure into the <Directory...>...</Directory> structure so that fcgi mode only applies to this Directory, but the FcgidInitialEnv directive is not accepted in <Directory.
I then split <IfModule...>...</IfModule> into two parts, as below:
Code: | Alias /phpmyadmin "E:/wamp64/apps/phpmyadmin5.1.1/"
<IfModule fcgid_module>
Define FCGIPHPVERSION "7.4.27"
FcgidCmdOptions ${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe \
InitialEnv PHPRC=${PHPROOT}${FCGIPHPVERSION}/php.ini
</IfModule>
<Directory "E:/wamp64/apps/phpmyadmin5.1.1/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require local
<IfModule fcgid_module>
<Files ~ "\.php$">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</Files>
</IfModule>
</Directory>
|
It works as I want, only the Directory goes to fcgi mode, localost remains in Apache module mode.
The question I ask myself: Is this the right method?
Last edited by Otomatic on Fri 08 Jul '22 15:12; edited 2 times in total |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 14 Jan '22 17:09 Post subject: |
|
|
You are doing it right with the fcgid config inside the directory.
On the other hand, I use "directory junctions" like a directory symlink on Linux. In that case, the config from the vhost is enough.
I wonder why you don't run fcgid only, but the module, too. |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
Posted: Sat 15 Jan '22 10:14 Post subject: |
|
|
James Blond wrote: | I wonder why you don't run fcgid only, but the module, too. |
Hi,
Because, as already explained in a previous message, Wampserver exists since more than seventeen years and was developed with PHP as an Apache module (PHP 3 and 4 and Apache 1.9 then 2) and that everything is made so that the beginner can develop locally without headache.
The menus for modifying extensions and configuration of PHP have been defined for the version of PHP used as an Apache module and it is impossible to make menus for all versions used in FCGI mode. |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1266 Location: Amsterdam, NL, EU
|
Posted: Sun 23 Jan '22 1:47 Post subject: |
|
|
James Blond wrote: | I wonder why you don't run fcgid only, but the module, too. |
I recently ran into a problem with a script that only worked with mod_php. gitpull.php does essentially this
Code: | <?php
$ret = exec('"C:\Program Files\git\bin\git.exe" pull', $out);
echo $out;
?> |
This only worked with mod_php, not with mod_fcgid. With mod_fcgid git.exe somehow asked for my credentials, which could not be provided in a exec'd script.
My solution was creating a extra file type .mod_php with handler application/x-httpd-php and rename the file into gitpull.mod_php. That worked.
Even when running git.exe at the command prompt it can be a frustating job since github removed support for password authentication, but I really would not know why the script succeeds with mod_php and fails with mod_fcgid.
Edit It had something to do with using OpenSSL. When I changed the http.sslBackend to schannel it worked also with mod_fcgid. |
|
Back to top |
|
alfred0809
Joined: 22 May 2022 Posts: 2 Location: Bangalore
|
Posted: Sun 22 May '22 8:23 Post subject: reply |
|
|
I have not had a chance to set up MySQL and also MSSQL yet. I also have an application for using an ODBC connection (SQLite3?) to pull data to generate reports from a Spiceworks db file. I used SQLite3 to pull live data into Excel so I assume that is the same connector PHP would use, not sure yet though. |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
Posted: Wed 06 Jul '22 13:27 Post subject: |
|
|
Hi,
I edit my previous post:
Replace all:
Code: | FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION} |
by
Code: | FcgidInitialEnv PHPRC "${PHPROOT}${FCGIPHPVERSION}/php.ini" |
|
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 213 Location: Paris, France, EU
|
Posted: Fri 08 Jul '22 15:10 Post subject: |
|
|
Hi,
If we use FcgidInitialEnv for the aliases, this raises the problem of remembering this first FCGI environment for the other aliases.
After reading the FCGI documentation very carefully, this is explained by :
Environment variables can also be set with FcgidInitialEnv, but they then apply to all applications.
and
Certain settings or other concepts that depend on the virtual host, such as FcgidInitialEnv or process classes, distinguish between virtual hosts only if they have distinct server names. (See the ServerName documentation for more information.) In the case of FcgidInitialEnv, if two virtual hosts have the same server name but different environments as defined by FcgidInitialEnv, the environment used for a particular request will be that defined for the virtual host of the request that caused the FastCGI process to be started.
By the way, in my case, alias have the same ServerName : localhost. This can be seen with phpinfo().
After a lot of testing and checking, for the aliases, we will replace FcgidInitialEnv with:
Code: | FcgidCmdOptions ${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe \
InitialEnv PHPRC=${PHPROOT}${FCGIPHPVERSION}/php.ini
|
In addition, it allows you to add environment variables and options different from the default ones for each alias.
So, basically, an FCGI alias should be:
Code: | Alias /phpmyadmin "E:/wamp64/apps/phpmyadmin5.1.1/"
<IfModule fcgid_module>
Define FCGIPHPVERSION "7.4.27"
FcgidCmdOptions ${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe \
InitialEnv PHPRC=${PHPROOT}${FCGIPHPVERSION}/php.ini
<Files ~ "\.php$">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
</Files>
</IfModule>
<Directory "E:/wamp64/apps/phpmyadmin5.1.1/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require local
</Directory> |
|
|
Back to top |
|
vee
Joined: 19 May 2012 Posts: 2 Location: TH
|
Posted: Thu 28 Dec '23 18:54 Post subject: |
|
|
I just know that with Alias, follow with FcgidCmdOptions, and <Directory...> can make PHP run different version per folder.
Wonderful! Thanks a lot.
Here is my config in case who is looking fore more example.
Code: |
<VirtualHost *:443>
ServerAdmin admin@localhost
DocumentRoot "${WWWROOT}/_testcs"
ServerName testcs.mycom.local
ErrorLog "logs/testcs.mycom.local-error.log"
CustomLog "logs/testcs.mycom.local-access.log" common
SSLEngine on
SSLCertificateFile "${SRVROOT}/conf/server.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/server.key"
FcgidMaxRequestLen 1000000000
FcgidIOTimeout 1800
FcgidInitialEnv PATH "${WWWSERVER}/php/php-running;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv PHPRC "${WWWSERVER}/php/php-running"
<Directory "${WWWROOT}/_testcs">
<Files ~ "\.php$">
AddHandler fcgid-script .php
FcgidWrapper "${WWWSERVER}/php/php-running/php-cgi.exe" .php
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Files>
</Directory>
Alias /my2ndapp "${WWWROOT}/_testcs/my2ndapp"
FcgidCmdOptions "${WWWSERVER}/php/php8.1/php-cgi.exe" \
InitialEnv PHPRC="${WWWSERVER}/php/php8.1/php.ini"
<Directory "${WWWROOT}/_testcs/my2ndapp">
<Files ~ "\.php$">
AddHandler fcgid-script .php
FcgidWrapper "${WWWSERVER}/php/php8.1/php-cgi.exe" .php
</Files>
</Directory>
</VirtualHost>
|
Accessing https://testcs.mycom.local => PHP 7.4 (my default)
https://testcs.mycom.local/aaa-folder => PHP 7.4
https://testcs.mycom.local/my2ndapp => PHP8.1
everything else until ...
https://testcs.mycom.local/zzz-folder => PHP 7.4 |
|
Back to top |
|
|
|
|
|
|