Please help me get FastCGI working with nginx

Igor Clark igor at
Mon Aug 4 15:23:04 MSD 2008


As has been said, php-fpm is probably the smart way to go, but it  
seems from your mail that you might want to try running /usr/local/bin/ 
php-cgi instead of /usr/local/bin/php. php is the CLI version, php-cgi  
is the cgi/fcgi version.


On 4 Aug 2008, at 05:26, Rt Ibmer wrote:

> I've spent the past several days going around and around trying to  
> get FastCGI working with Nginx and I am stuck. Hopefully someone  
> here can guide me please.
> In summary I am trying to use nginx to front-end a PHP web site  
> (instead of using Apache/PHP I want to us Nginx/PHP).
> I have a working nginx 0.6.latest.ver working without PHP and  
> FastCGI support, as I've used nginx plenty in the past.  So now I am  
> trying to add PHP and FastCGI into the picture but am totally stuck...
> The first thing I did was download and compile PHP with FastCGI  
> support:
> ../configure --enable-mbstring --with-mysql=/usr/bin --with-mysql- 
> sock=/mnt/mysql/data/mysql.sock --enable-fastcgi --with-curl -- 
> enable-sockets --with-config-file-path=\etc
> make
> make install
> So that goes OK.
> But then when I run /usr/local/bin/php -v it says:
>  PHP 5.2.6 (cli) (built: Aug  3 2008 23:45:09)
>  Copyright (c) 1997-2008 The PHP Group
>  Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
> I read somewhere that if that output says "(cli)" and not "(fast- 
> cgi)" then PHP is not installed with FastCGI support. So perhaps  
> this is my issue.
> However as you can see from my ./configure command for PHP included  
> above, I am specifying --enable-fastcgi which according the several  
> web sites and the ".configure --help" says is all that is needed.
> Am I missing something here?
> Then based on pages like 
> NginxFcgiExample I am doing this:
> /usr/local/bin/spawn-fcgi -a -p 8888 -f /usr/local/bin/php
> and it exists with this:
> spawn-fcgi.c.218: child exited with: 0, Success
> However when I do a "ps -A" I don't see spawn-fcgi running.   
> Furthermore if I telnet to port 8888 on localhost it says connection  
> refused so I don't think anything is listening there.
> So then of course when I try a .php page on nginx I get this in its  
> error log:
> connect() failed (111: Connection refused) while connecting to  
> upstream, client: x.y.z.a, server: localhost, request: "GET / 
> test.php5 HTTP/1.1", upstream: "fastcgi://", host:  
> "myhost"
> Can someone please point me in the right direction? Any tips are  
> GREATLY appreciated!  Also is there any chance we will get FastCGI  
> natively implemented in nginx like it is with Apache and other  
> servers? Thank you so much in advance!!

Igor Clark • POKE • 10 Redchurch Street • E2 7DD • +44 (0)20 7749 5355  

More information about the nginx mailing list