Configuring Nginx for PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    Configuring Nginx for PHP

    For windows:

    Download the recent stable release from INTERNET.
    Extract the file to any folder.

    In my case it is C:\nginx-0.7.60

    locate configuration file in path\conf\nginx .conf.

    In my case C:\nginx-0.7.60\conf\ngi nx.conf

    Uncomment and edit following lines

    Code:
    location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  c:/nginx/nginx-0.7.61/html/$fastcgi_script_name;
                include        fastcgi_params;
            }
    Save it and run nginx.exe (the server will started).

    For proxy and other stuffs please uncomment respective sections in conf file.
    Also if your PHP is not enabled with fcgi during installation, please do use fast cgi from third party(like lighttpd etc).

    For Linux:

    Download the stable release from the internet untar and chage working directory to untarred folder and in terminal type

    Code:
    #./configure
    #make
    #make install
    For configuration help please see ./configure --help.

    It will get installed to /usr/local/nginx or something like this.

    Uncomment and edit following in nginx.conf:

    Code:
    ocation ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
                include        fastcgi_params;
            }
    If your PHP has no fcgi support, use lighttpd fast cgi. Download lighttpd and untar and give following command.

    Code:
    #./confiigure
    #make 
    #make install
    start nginx by:
    Code:
    #/usr/local/nginx/sbin/nginx
    Then spawn php-cgi from /usr/local/bin or some folder like this as
    Code:
    #/usr/local/bin/spawn-fcgi -p 9000 -f /usr/local/bin/php-cgi
    If you are not root you may need to give the -u option too.


    Regards
    Dheeraj Joshi
    Last edited by Dormilich; Sep 2 '09, 06:26 AM. Reason: added [code] tags
Working...