Monday, June 23, 2014

Nginx 1.6 stable fail php-fpm on Debian Wheezy

I am big fan of Debian.
It just easy to setup a nice clean server get the job done.

For more effective web server, I try to use Nginx + PHP5-FPM to serve Wordpress and Mediawiki.

I bring up a new Debian Wheezy 7.5 64-bit server today.

1.First upgrade all new patch:
aptitude update && aptitude upgrade

2.Install Nginx Stable follow Nginx's offical Pre-Built Packages:
http://nginx.org/en/linux_packages.html#stable
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
aptitude update
aptitude install nginx

3.Install Latest MariaDB Pre-Built Packages:
aptitude install python-software-properties
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/debian wheezy main'
aptitude install mariadb-server

4.Install PHP5-FPM:
aptitude install php5-fpm

5.Modify Nginx vhost location in /etc/nginx/nginx.conf:
include /etc/nginx/sites-enabled/*.conf;

6.Put my vhost file at /etc/nginx/sites-available/mds.conf:
server {
listen 80;
server_name localhost;

access_log /var/log/nginx/log/mds.access.log main;
error_log /var/log/nginx/log/mds.error.log error;

root /var/www/mds;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mds;
}

# With php5-fpm / php5-cgi will be different:
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Make a link:
ln -s /etc/nginx/sites-available/mds.conf /etc/nginx/sites-enable/

Restart Nginx:
service nginx restart

Then I put a index.php with phpinfo() into the /var/www/mds folder.
But the browser shows blank page.
I try follow different post, able to bring errors logs: php5-fpm.sock failed (13: Permission denied) error

But still not able to quickly fix it.

Spend almost half hour on it, finally found:

Missing this line in /etc/nginx/fastcgi_params:
fastcgi_param   SCRIPT_FILENAME         $request_filename;

I should just stay with Debian Nginx 1.2, what a wast!
Nginx's RPM package works just fine.

Hope this helps.

Update 1 on June 24, 2014:

It seems more problem are coming, I really miss stock debian package.

Php page show error, but nothing in error log file.

I have to run this to bring the php page up:
chmod 666 /var/run/php5-fpm.sock

Thanks the post: http://www.nginxtips.com/php5-fpm-sock-failed-13-permission-denied-error/

I modified file: /etc/php5/fpm/pool.d/www.conf
;listen.owner = www-data
;listen.group = www-data
;listen.mode = 0660
listen.owner = nginx
listen.group = nginx

service php5-fpm restart

Update 2: Additional installation to make it works better
aptitude install php-apc
aptitude install php5-mysqlnd
mysql_secure_installation


Update 2 on November 14, 2014:

Another solution for .sock permission issue will be:

/etc/nginx/nginx.conf
#user nginx;
user www-data;


This because php5-fpm package set /var/www owner to www-data.
It will be much cleaner just set nginx run as www-data, therefor we borrow the Debian setting over.

[poll id="2"]

5 comments:

  1. What i don't understood is in reality how you're not really
    much more smartly-appreciated than you might be now.
    You're very intelligent. You already know thus significantly in terms of this matter, made
    me for my part consider it from a lot of numerous angles.
    Its like women and men are not interested until it's one thing to accomplish with Woman gaga!
    Your own stuffs outstanding. At all times care for it up!

    ReplyDelete
  2. I see you share interesting stuff here, you can earn some extra money,
    your website has huge potential, for the monetizing method, just
    type in google - K2 advices how to monetize a website

    ReplyDelete
  3. I tried to used LIMP for my sites but all version gives errors, like 504, 502 want to find stable version to do, any help please.

    ReplyDelete
  4. To help you may I have your OS detail? As well as the error log file?
    504, 502 may cause by nginx vhost config.

    ReplyDelete
  5. Just have to say, thankyou!

    I've been drawing blank php pages with no errors, yet I could see the service was running without error (and html worked fine) for about 3 bloomin hours until I came across your article. You have just made an extremely frustrated person very happy indeed. Thank you!!

    ReplyDelete