nginx+php-fpm+Drupal on Linux
How to configure nginx with PHP-FPM to run Drupal on Ubuntu Linux for better performance.
Nginx is a high performance lightweight web-server that is visibly faster than Apache and takes less memory. On my machine, Drupal’s module list page (admin/modules) comes up within 2 seconds on Nginx, while on Apache 2.2 it takes over 4 seconds.
Setup on Ubuntu Linux:
- Shutdown Apache:
sudo service apache2 stop - Install nginx:
sudo apt-get install nginx - Install CGI version of PHP:
sudo apt-get install php5-cgi - Install PHP-FPM:
sudo apt-get install php5-fpm
Configuration for Drupal in /etc/nginx/sites-enabled/default:
location / {
try_files $uri $uri/ /index.html @drupal;
}
location @drupal {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
Then restart nginx: sudo service nginx restart