Adding php support to nginx (notes)

Already got nginx running with ruby, now I want a php site:

apt-get install php-cgi

configure nginx (mine is in a weird location, /opt/nginx/conf/nginx.conf:

server {
    listen 80;
    server_name my.hostname.local;
    root /path/to/site/public/;
    access_log /path/to/site/log/access.log;
    error_log /path/to/site/log/error.log;
    index index.php;
    location ~ \.php$ {
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       include fastcgi_params;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME /path/to/site/public$fastcgi_script_name;
       fastcgi_pass localhost:8020;
    }
}

then start php

php-cgi -b 127.0.0.1:8020

and restart nginx

Leave a Reply

Your email address will not be published. Required fields are marked *