NGinx + PHP5 + MySQL
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
Install the following:
- Nginx - the vanilla install will work
- yum install nginx -y
- Lighttpd - vanilla install will work yet again
- yum install lighttpd -y
- 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
Labels: php nginx mysql


3 Comments:
Did you look at the work that Cliff Wells did? He ran some of the docs through a translator, cleaned them up and put up a wiki here
April 4, 2008 3:03 PM
I guess I should mention that it's an wiki which specifically documents NGINX.
April 4, 2008 3:05 PM
Yeah, you're late to the party! The wiki is well over a year old now (and there's actually work on several languages beside English).
Also don't forget to join the English Nginx mailing list (and we can always use people in the irc channel):
http://wiki.codemongers.com/NginxCommunity
Regards,
Cliff
April 5, 2008 1:55 AM
Post a Comment
Subscribe to Post Comments [Atom]
<< Home