Hello fellow nginx users. I'm setting up my server to use nginx / php-fpm and I seem to have hit a brick wall. html pages are served correctly to the browser but requests for php pages prompt for download of the file.
default index.html => home.idea-team.org
test html page => home.idea-team.org/test.html
test php page (same page as above but with php extension) => home.idea-team.org/test.php
phpinfo page => home.idea-team.org/phpinfo.php
please check it out if you have a minute, hopefully it's something silly I overlooked
other info:
php 5.3.5
suhosin patch 0.9.10
suhosin 0.9.32.1
with the following compile configuration
./configure --with-config-file-path=/usr/local/lib/php --with-curl --enable-exif --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-t1lib --with-mcrypt --with-mhash --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-sysvmsg --enable-wddx --with-xsl --enable-zip --with-bz2 --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-sqlite-utf8 --with-gettext --enable-shmop --with-xmlrpc --enable-dba --enable-sysvsem --enable-sysvshm --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data
and using the default php.ini
nginx 0.9.3
with the following compile configuration
sudo ./configure --user=www-data --group=www-data --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_stub_status_module --with-http_gzip_static_module --with-rtsig_module --http-client-body-temp-path=/var/cache/nginx/client_body_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=/home/smiro/nginx/nginx-upload-progress-module --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf
and using perusio's drupal optimized nginx.conf from => https://github.com/perusio/drupal-with-nginx
nginx -t returns no errors and nothing significant in the logs...
searching google for crazy stuff like "i'm downloading php pages" mentioned a possible problem with mime types?
thank you for taking a look at my problem. i look forward to running a solid nginx server!
-miro
Comments
Make sure you have something
Make sure you have something to the effect of:
location ~ .php$ {
fastcgi_pass 127.0.0.1:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/drupal$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;
}
Google: Drupal nginx config and you'll get many examples.
This means that PHP is not being
interpreted. The above config is/could be insecure.
How do you run the FastCGI? UNIX or TCP sockets? Note that my config a very specific location for the UNIX socket, which is created by an init script that sets de permissions to
700owned bywww-data.What do:
netstat --unix -lreturns? (UNIX)and
netstat -t -l? (TCP)i went the php-fpm way the
i went the php-fpm way
the commands you suggested return the following
netstat --unix -lActive UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 35385 /usr/local/var/run/php-fpm.sock
unix 2 [ ACC ] STREAM LISTENING 717 @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 2813 /var/run/mysqld/mysqld.sock
and
netstat -t -lActive Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:mysql : LISTEN
tcp 0 0 :www *: LISTEN
tcp 0 0 :ssh *: LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
but i'm not sure how to interpret it.
thank you very much for your help!
Ok
This means that there's a UNIX socket listening on
unix:/usr/local/var/run/php-fpm.sock.Replace the
fastcgi_passvalue from the config with this, i.e.:fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;reload the config and try to run the PHP code again. It should work.
woohoo! thank you slovak++
woohoo! thank you slovak++ and perusio++ i'm very happy to confirm that worked!
i added
location ~ .php$ {fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;
}
i was looking for the correct conf file to add the directive to but couldn't find one to change so i just added it to the drupal.conf file
that should do it right?
thank you!
I don't recommend that config
I deemed it insecure. What you need to do is just replace all the ocurrences of the
fastcgi_passdirective with the one that points to your socket address. That's not done indrupal.confbut indrupal_boost.confand/ordrupal_boost_drush.conf. Like this:# Restrict access to the strictly necessary PHP files. Reducing the# scope for exploits. Handling of PHP code and the Drupal event loop.
location ~* ^/(?:index|boost_stats)\.php$ {
fastcgi_pass unix:/usr/local/var/run/php-fpm.sock; # <-- here it is!
# Filefield Upload progress
# http://drupal.org/project/filefield_nginx_progress support
# through the NgninxUploadProgress modules.
track_uploads uploads 60s;
}
I suggest you remove the
~ .php$location you inserted and instead use the above indrupal_boost.confand/ordrupal_boost_drush.conf.wow yes, that is a very
wow yes, that is a very secure setup!
i didn't think of looking in the boost config
thank you again for the help, and for your contributions in this field!
i took the liberty of adding a sentence to your installations instructions to describe this process
It should display the PHP CGI socket. default is set to /tmp/php-cgi/php-cgi.socket; if yours is different change the all the accurances of the fastcgi_pass directive in the drupal_boost.conf and/or drupal_boost_drush.confas shown here
it might help people like me that are still learning ;)