Difference between revisions of "User:Woozle/nginx"
(progress, but no cigar yet) |
(problem solved) |
||
Line 38: | Line 38: | ||
From what I can tell, this means that PHP is not receiving the name of the script it is supposed to run, and this is supposed to be passed in the SCRIPT_FILENAME environment variable. Trying to figure out how to do that on the nginx end. | From what I can tell, this means that PHP is not receiving the name of the script it is supposed to run, and this is supposed to be passed in the SCRIPT_FILENAME environment variable. Trying to figure out how to do that on the nginx end. | ||
+ | |||
+ | No progress on that... but at least one source suggests that setting PHP's [http://us2.php.net/manual/en/ini.core.php#ini.open-basedir open_basedir] option may help. Though this would be a kluge if it worked (and would prevent us from using PHP on the main site), it would also help narrow down the problem. So, added to php.ini: | ||
+ | open-basedir = /home/mylwiki/wiki.makeyourlaws.org | ||
+ | |||
+ | No change. Removed line from php.ini. | ||
+ | |||
+ | SCRIPT_FILENAME is set to a filespec which includes $document_root (this is apparently [http://wiki.nginx.org/Pitfalls#FastCGI_Path_in_Script_Filename good practice]). | ||
+ | |||
+ | $document_root is set by nginx's [http://nginx.org/en/docs/http/ngx_http_core_module.html#root root] directive. | ||
+ | |||
+ | Finally kluged nginx.conf by adding this line after the fastcgi_params include: | ||
+ | fastcgi_param SCRIPT_FILENAME /home/mylwiki/wiki.makeyourlaws.org$fastcgi_script_name; | ||
+ | |||
+ | After that. simple PHP pages would load but MediaWiki still would not. Examination of nginx's error.log revealed sufficient clues to point to the fact that LocalSettings.php had somehow been read-protected for everyone except the owner; making it world-readable fixed that problem and rendered the wiki fully accessible. | ||
+ | |||
+ | I should post the script I used to determine what nginx was sending via the CGI port; it was helpful in isolating the problem. | ||
==Background== | ==Background== |
Revision as of 22:25, 23 June 2012
The Problem
nginx works with static files (and Ruby), but will not execute PHP files. PHP runs fine from a command line.
On requesting a PHP file (such as http://wiki.makeyourlaws.org/phpinfo.php), here's what seems to be happening:
- nginx receives the request
- nginx forwards it to PHP-FPM
- This can be done one of two ways -- either via a UNIX pipe or via a port. I've tried both; currently using port, I think.
- PHP never receives the request; the log file does not show it.
- nginx somehow receives a success code, and logs the request as successful (http code 200) returning a result of zero bytes.
- The web browser displays a blank page.
Notes
2012-06-21
Looks like the package "spawn-fcgi" may be the part of FastCGI that I need to install, extrapolating from this. Installing it...
2012-06-23
Noticed that this says "Unlike Apache or Lighttpd, Nginx does not automatically spawn FCGI processes. You must start them separately. ... So we simply run php -b 127.0.0.1:9000 manually, or create an init script like so...".
This turns out to be not quite correct; "php" by itself doesn't accept the -b parameter. You have to run php-cgi:
php-cgi -b 127.0.0.1:9000
Unfortunately, I get this:
Cannot bind/listen socket - [98] Address already in use. Couldn't create FastCGI listen socket on port 127.0.0.1:9000
...meaning that something is already listening there. Presumably that's PHP-FPM:
ps aux | grep php woozle 11404 0.0 0.1 3372 752 pts/1 S+ 15:25 0:00 grep --color=auto php root 24667 0.0 0.2 62892 1488 ? Ss Jun18 0:22 php-fpm: master process (/etc/php5/fpm/php-fpm.conf) www-data 24668 0.0 0.3 63180 1984 ? S Jun18 0:00 php-fpm: pool www www-data 24669 0.0 0.3 63180 1996 ? S Jun18 0:00 php-fpm: pool www www-data 24670 0.0 0.3 63180 1996 ? S Jun18 0:00 php-fpm: pool www www-data 24671 0.0 0.3 63180 1996 ? S Jun18 0:00 php-fpm: pool www
So, how can we determine if PHP-FPM is receiving the page request?
Set "log_level = debug" in php-fpm.conf. Evidence would seem to indicate that PHP-FPM is not receiving page requests from nginx. (Reset logging back to default level and restarted PHP-FPM.)
Stopped PHP-FPM. Reloading http://wiki.makeyourlaws.org/phpinfo.php now receives a "502 Bad Gateway" error. Running "php-cgi -b 127.0.0.1:9000" seems to be successful, and now the page just displays "No input file specified.".
From what I can tell, this means that PHP is not receiving the name of the script it is supposed to run, and this is supposed to be passed in the SCRIPT_FILENAME environment variable. Trying to figure out how to do that on the nginx end.
No progress on that... but at least one source suggests that setting PHP's open_basedir option may help. Though this would be a kluge if it worked (and would prevent us from using PHP on the main site), it would also help narrow down the problem. So, added to php.ini:
open-basedir = /home/mylwiki/wiki.makeyourlaws.org
No change. Removed line from php.ini.
SCRIPT_FILENAME is set to a filespec which includes $document_root (this is apparently good practice).
$document_root is set by nginx's root directive.
Finally kluged nginx.conf by adding this line after the fastcgi_params include:
fastcgi_param SCRIPT_FILENAME /home/mylwiki/wiki.makeyourlaws.org$fastcgi_script_name;
After that. simple PHP pages would load but MediaWiki still would not. Examination of nginx's error.log revealed sufficient clues to point to the fact that LocalSettings.php had somehow been read-protected for everyone except the owner; making it world-readable fixed that problem and rendered the wiki fully accessible.
I should post the script I used to determine what nginx was sending via the CGI port; it was helpful in isolating the problem.
Background
- Distro: Ubuntu 10.04.4 LTS
nginx was compiled from source; PHP5 was installed from standard Ubuntu packages.
File Locations
- /opt/nginx/ - configuration and logging folders
- /opt/nginx/conf/nginx.conf - master config file
- /opt/nginx/conf/fastcgi.conf - FastCGI config file
- /opt/nginx/conf/scgi_params - Simple CGI config -- presumably not in use
- /etc/php5/fpm/ - PHP-FPM configuration
- /etc/php5/fpm/pool.d/www.conf - config file to actually edit
Folder Listings
- /opt/nginx
- total 25532
drwx------ 2 nobody root 4096 2012-04-26 18:47 client_body_temp drwxrwxr-x 2 root root 4096 2012-06-09 22:25 conf drwx------ 2 nobody root 4096 2011-12-02 23:20 fastcgi_temp drwxr-xr-x 2 root root 4096 2011-12-02 22:52 html drwxrwxr-x 2 root root 26071040 2012-06-11 06:43 logs drwx------ 2 nobody root 4096 2011-12-02 23:20 proxy_temp drwxrwxr-x 2 root root 4096 2012-04-22 04:41 sbin drwx------ 2 nobody root 4096 2011-12-02 23:20 scgi_temp drwx------ 2 nobody root 4096 2011-12-02 23:20 uwsgi_temp
- /opt/nginx/conf
- total 80
-rw-r--r-- 1 root root 979 2011-12-02 22:52 fastcgi.conf -rw-r--r-- 1 root root 979 2012-04-22 04:41 fastcgi.conf.default -rw-r--r-- 1 root root 909 2011-12-02 22:52 fastcgi_params -rw-r--r-- 1 root root 909 2012-04-22 04:41 fastcgi_params.default -rw-r--r-- 1 root root 2837 2012-04-22 04:41 koi-utf -rw-r--r-- 1 root root 2223 2012-04-22 04:41 koi-win -rw-r--r-- 1 root root 3362 2011-12-02 22:52 mime.types -rw-r--r-- 1 root root 3463 2012-04-22 04:41 mime.types.default -rw-r--r-- 1 root root 6651 2012-06-10 18:50 nginx.conf -rw-r--r-- 1 root root 2685 2012-04-22 04:41 nginx.conf.default -rw------- 1 root root 0 2012-04-23 16:29 nginx.conf.save -rw-r--r-- 1 root root 4208 2012-04-23 16:29 nginx.conf.save.1 -rw-r--r-- 1 root root 544 2011-12-02 22:52 scgi_params -rw-r--r-- 1 root root 544 2012-04-22 04:41 scgi_params.default -rw-r--r-- 1 root root 570 2011-12-02 22:52 uwsgi_params -rw-r--r-- 1 root root 570 2012-04-22 04:41 uwsgi_params.default -rw-r--r-- 1 root root 3610 2012-04-22 04:41 win-utf