Setting up PHP as Fast CGI (FCGI) under Apache

1) Download the Apache mod_fcgi module: http://fastcgi.coremail.cn/

2) Configuration in your Apache httpd.conf:
a) LoadModule fcgid_module modules/mod_fcgid.so

b.1) <Directory "C:/Apache2/htdocs/php/">
    SetHandler fcgid-script
    Options execCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    FCGIWrapper "c:/php/php-cgi.exe" .php
</Directory>

b.2) This works too (it's actually the method I'm using):

AddHandler fcgid-script .php

<Directory "C:/Apache2/htdocs/php/">
    FCGIWrapper "c:/php/php-cgi.exe" .php
    Options ExecCGI
    allow from all
</Directory>

So using method b.2:
Just add to your httpd.conf:
AddHandler fcgid-script .php

Then in the folders running your PHP scripts:
FCGIWrapper "c:/php/php-cgi.exe" .php
Options ExecCGI

3) To overwrite any of the default FCGI directives in your httpd.conf see:
http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html (now part of Apache.org ... was htttp://fastcgi.coremail.cn/doc.htm)

One particular setting is recommend:
MaxRequestsPerProcess 500

4) This is in the doc but if you missed it:

Note: If you get:

Can't create TCP/IP socket (10106) error while running PHP script(on Win32 only), you will have to set these (Please modify the values if necessary):
DefaultInitEnv PHPRC "c:/php/"
DefaultInitEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
DefaultInitEnv SystemRoot "C:/Windows"
DefaultInitEnv SystemDrive "C:"
DefaultInitEnv TEMP "C:/WINDOWS/TEMP"
DefaultInitEnv TMP "C:/WINDOWS/TEMP"
DefaultInitEnv windir "C:/WINDOWS"

(Thank Steffen of apachelounge.com for this note)

Note: SiteBuddy.com is now under FCGI also using eAccelerator 0.9.5.

 



http://fastcgi.coremail.cn/

http://fastcgi.coremail.cn/ is not available, here is the mirror site: http://www.javatang.com/mod_fcgid/

Can't create TCP/IP socket (10106)

Hi there,

I got the MySql "Can't create TCP/IP socket (10106)" issue.

First of all, would like to thanks Chris, since his post was the first I found with a solution to this issue.

And maybe also give some feedback...

Of all DefaultInitEnv entries described by Crhis, I only needed "SystemRoot"...the others do not hurt, but I usually try to keep my config files modifications to the lowest...

Regards,
Gonzalo.

Hi Gonzalo, Make you do not

Hi Gonzalo,

Make you do not try to bind two services on the same ip/port.
Also if you are running some firewall on the local server disable for a few seconds to see it that helps.

Cheers,
Chris

What is the purpose of adding FCGI and how well it goes?

Hi whoever concern,

i read some documents about this fast cgi thingy, and really want to give my site a try, but i am just a noob about server stuff, what i can do for my site is just adding the module to my apache modules folder and configure in httpd.conf by adding this line of module "LoadModule fcgid_module modules/mod_fcgid.so" , after that i am stuck at the next state by configure the directory and the value for FCGID in httpd.conf , so i decide to post here to ask for a lift if any one can help me out with this problem and so on

I am running a server name AppServ and installed at D:\AppServ

My Apache direcory is D:\AppSev\Apache2.2
My PHP directory is D:\AppServ\php5
And my website is located at D:\AppServ\www

how will i configure the directory for fast scgi in my httpd.conf according the set of my server?

Thanks

Basically fast cgi enable..

Next add to your httpd.conf:
AddHandler fcgid-script .php

Make sure your comment out the previous lines handling .php.

Next your should see a line like:

<Directory "D:\AppServ\php5">
...some configuration directives....
</Directory>

Simply add the lines (adjust to your location of php-cgi.exe) :
FCGIWrapper "c:/php/php-cgi.exe" .php
and then make sure your options include ExecCGI with:
Options ExecCGI
or to add this option to your existing Options:
Options +ExecCGI

Note if you use the .htaccess mechanism you can also add those 2 lines to that file (in the directory with your php scripts).

Basically fast cgi enable a recycling of the "PHP threads". Apache and PHP (on windows at least) is know to create problems after x amount of PHP requests. Using FASTCGI you actually keep the "PHP engine" loaded for a few minutes or a few hours and it will recycle itself (you can configure this exact behavior with the FASTCGI directives). The main advantage with FASTCGI versus CGI is that since you actually keep a "PHP context" for a few hours you can also use PHP accelerator to even further compensate for the slowness CGI introduces. So you end up with a stable "Apache + PHP" stack that is pretty much the same speed as when using the PHP module.

Cheers,
C

Still confusing which directory ...

Hi Christ,

Thanks alot for the reply, but i am still lost about which directory i need to config in httpd.conf for fast cgi module to run

Here is two directory i am guessing that i can be able to config for:

<Directory D:\AppServ\php5> and <Directory D:\AppServ\www>

which one i should go for, or tell me any other directory i need to add if none of those are good to go

thanks

Its probably the

Its probably the D:\AppServ\www directory.

Try adding the lines to both and if it works remove from one and see if it still works.

Gotta be something wrong

Hi christ,

i got this error when config using <Directory D:\AppServ\www>

It is internal error 500 message, and the error log of apache wrote this:

[Sun Dec 17 16:48:22 2006] [error] [client 69.237.184.84] D:/AppServ/www/index.php is not executable; ensure interpreted scripts have "#!" first line, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:22 2006] [error] [client 69.237.184.84] (9)Bad file descriptor: mod_fcgid: don't know how to spawn child process: D:/AppServ/www/index.php, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:23 2006] [error] [client 69.237.184.84] D:/AppServ/www/index.php is not executable; ensure interpreted scripts have "#!" first line, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:23 2006] [error] [client 69.237.184.84] (9)Bad file descriptor: mod_fcgid: don't know how to spawn child process: D:/AppServ/www/index.php, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:25 2006] [error] [client 69.237.184.84] D:/AppServ/www/index.php is not executable; ensure interpreted scripts have "#!" first line, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:25 2006] [error] [client 69.237.184.84] (9)Bad file descriptor: mod_fcgid: don't know how to spawn child process: D:/AppServ/www/index.php, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:36 2006] [error] [client 69.237.184.84] D:/AppServ/www/index.php is not executable; ensure interpreted scripts have "#!" first line, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:36 2006] [error] [client 69.237.184.84] (9)Bad file descriptor: mod_fcgid: don't know how to spawn child process: D:/AppServ/www/index.php, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:36 2006] [error] [client 69.237.184.84] D:/AppServ/www/index.php is not executable; ensure interpreted scripts have "#!" first line, referer: http://tinhthienthu.ath.cx/
[Sun Dec 17 16:48:36 2006] [error] [client 69.237.184.84] (9)Bad file descriptor: mod_fcgid: don't know how to spawn child process: D:/AppServ/www/index.php, referer: http://tinhthienthu.ath.cx/

But when i use <Directory D:\AppServ\php5> nothing happen, any suggestion ?

May be i need you to decide for me, let me first tell you that i am running a phpbb forum in this directory D:\AppServ\www

my apache server is in D:\AppServ\Apache2.2
and php is in D:\AppServ\php5

I am totally lost, but i really like the fast cgi thingy to be working for my forum, plaese help me christ

Thanks

FCGI: This should work

Hi Panda,

This should work:

1) In your httpd.cong add:

LoadModule fcgid_module modules/mod_fcgid.so

AddHandler fcgid-script .php

2) Remember to comment out the old PHP module:

#LoadModule php4_module "D:/Apache2/bin/php4apache2.dll"
#LoadModule php5_module "D:/Apache2/bin/php5apache2_2.dll"

3) Add in the <Directory D:\AppServ\www> directive:

Options +ExecCGI
FCGIWrapper "D:/AppServ/php5/php-cgi.exe" .php

Make sure you indeed have the file php-cgi.exe in that folder !

Note: you might have to add these 2 previous lines in your .htaccess located at: D:\AppServ\www

If you still have issues please post in the Forums. Thanks.

Happy Holidays!

Apache fail to start

Thanks again christ for your reply

but unfortunately, after i tried to config like you said, the apache wont start, i dont know why but the error log didn't witness anything went wrong, may be i need to post my httpd.conf for you to check

Sorry i am in the hurry to create a nick name in the forum, next time i will and post in there

Very appreciated for your help and i am still looking forward to wait for fast cgi to be working on my server.

Best wishes and happy holidays to you.