Had a bitch ass time getting NGinx + PHP5 + MySQL working on Fedora 8. There's very little documentation and what little documentation there is, is in Russian.
At anyrate -- Nginx is the webserver. It serves up content that's it. Because it does it's 1 job really well, that means you have to hook-in all the other shit that you want to use. In my case, I want to serve up PHP pages. Nginx isn't like Apache where you can compile PHP into. You have to host the PHP-FastCGI in a wrapper (lighttpd) that will be accessed by Nginx.
When a request comes in for a .php file, nginx connects to the localhost usually on a port you specify to LightTPD. LightTPD is just sitting there twiddling it's thumbs waiting for shit like this to be requested. At that point, everything should work as planned -- your .php is served. See below for a list of steps that I think is close to being true.
- user_connects_to_your_page
- nginx sees request for .php page
- nginx contacts lightTpd and passes php page to be parsed
- lightTpd passes page onto PHP-FastCGI being hosted
- PHP-FastCGI handles .php page/request
- page returned to nginx
- user_is_happy
The install instructions below are Fedora 8 specific, so I'm sorry if you aren't running it. You should be able to follow the process flow regardless of your flavor.
Install the following:
- Nginx - the vanilla install will work
- Lighttpd - vanilla install will work yet again
- Php5 - here's the bitch.
- download the source
- untar it somewhere
- ./configure --prefix=/opt/php --enable-fastcgi --with-mysql
- (If you are running on the 64-bit version of Fedora you'll pull your hair out if you don't add the switch --with-libdir=lib64 at the end of the previous line)
- cross your fingers that everything got installed properly and will "Just-work" the first time
Now the fun starts. I'm not going to go into crazy detailed configurations, I'm just going to tell you which files you'll probably want to look at and some options since alot of that information is out there already. (do a
find for the files if they aren't in the same spot as mine)
- nginx.conf - this acts like apache's httpd.conf, pay attention to the server directories and port # in red.
- The port number, corresponds to the port that light-tpd is running on that you launch
- the directory is obviously the root of where all your php scripts will be running from
server {
listen 80;
server_name myspace.com;
access_log logs/myspace.access.log main;
location / {
root /sites/myspace.com;
index index.html index.php;
}
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME /sites/myspace.com/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass 127.0.0.1:10004;
fastcgi_index index.php;
}
}
- start-fastcgi.php - a script I made to just get the thing working
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 10004 -u lighttpd -g lighttpd -f /opt/php/bin/php-cgi