Linux – How to configure NGINX + PHP-FPM + Drupal 7.0

I have configure properly Drupal7 with NGINX, PHP-FPM and APC.
The whole thing rock and has an excellent speed.

Installation of needed packages :

Configure your nginx :

And done.

Short URL: http://sck.pm/CiS9

One Pingback/Trackback

  • piisawheel

    So is that ..*/.*php$ line supposed to prevent the image.gif/somecrap.php security exploit?

    • I don’t know. Do you try it ?

  • Pingback: Run Drupal 7 in Nginx | Eureka!()

  • Thank you, thank you, thank you. Works with exactly 0 hitches =)

    I did not understand this comment: # Else this rewrite block wouldn't be needed (GlobalRedirect)

    Could you please elaborate on what a GlobalRedirect is? Which among the lines of this config file is the GlobalRedirect?

  • franck

    got this error : [crit] 11033#0: *1 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream,

    • did you start php5-fpm ?
      I have forget to put the conf for it, but it need to listen on this unix port, by default is “127.0.0.1:9000” I think

      go in /etc/php/fpm/conf/www.conf or something like that, and find the listen

  • gonzales

    Thank you.

  • buminda

    on fastcgi_pass unix:/var/run/php-fpm.sock; I changed this to 127.0.0.1:9000 to work.Otherwise it returns 502 badgateway. Thanks for sharing this mate.

  • Dan

    I still had to manually add apc to my php.ini before I could use it. I just added “extension=apc.so” to /etc/php5/fpm/php.ini

  • Clint

    Hi Dan, nice to see you here. I didn’t need to edit my php.ini APC was loading from /etc/php5/fpm/conf.d/apc.ini

    I did need to change fastcgi_pass unix:/var/run/php-fpm.sock; to fastcgi_pass 127.0.0.1:9000;

    I also modified rewrite ^/(.*)$ /index.php?q=$1; based on the recommendation from Nginx at http://wiki.nginx.org/Drupal because I’m using Drupal 7.

    Thanks for the guide.

  • Rizzy Savage

    Hi

    I am migrating my server from lighttpd to nginx, in lighttpd I used to put fast cgi configuration in one file called fastcgi.conf.
    As I have multiple subdomains, do i need to put mentioned configuration for every virtual host in nginx.

    location ~ .php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/var/run/php-fpm.sock;

    And restart both the service of nginx and php-fpm.

    Rizzy

    • I think you can put all the params in the fastcgi_params config file and only include this.
      But push SCRIPT_FILENAME with this kind of custom stuff, may not work on other system than drupal.

  • error500

    > location@rewrite{
    >                # Some modules enforce no slash (/) at the end of the URL
    >                # Else this rewrite block wouldn't be needed (GlobalRedirect)
    >                rewrite^/(.*)$/index.php?q=$1;
    >        }
    and
    >   try_files$uri$uri/@rewrite;


    is real shit for nginx internal engine = double rewrite – must be like

    error_page    404 = @rewrite

    location @rewrite{
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param QUERY_STRING q=$uri&$args;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    }

    that is not full tested config but is recomended way from Igor Sysoev (main nginx developer)