eZ Community » Blogs » Philippe VINCENT-ROYOL » eZ Publish & nginx


eZ Publish & nginx

Thursday 08 March 2012 12:14:45 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Pour les personnes non anglophones, vous trouverez cet article sur http://www.pheelit.fr/HighTech/Developpement/eZ-Publish-nginx


At this time, light webserver are more and more known. For example Lighttpd (pronounced lighty ) and Nginx (Engine X). This blog post will explain how to use eZ Publish with Nginx :)

This install runs with Debian 6.0.4 and nginx 1.0.12-1

Repository configuration

First step, we will configure apt to retrieve the latest versions of php and mysql from Dotdeb. Edit sources.list file:

vim /etc/apt/sources.list

and add:

deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all

we need to get GPG keys:

wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | sudo apt-key add -

Finish with

apt-get update && apt-get upgrade

Mysql Installation

Really quickly 

apt-get install mysql-server

and... done :)

Php5-fpm installation 

To install php5-fpm and principals libraries, here is the command line

apt-get install php5-fpm php5-xcache php5-mcrypt php5-curl php5-mysql php5-cli

Nginx installation

Lazy install here too.. you could add some comments above to explain how to compile each applications.

apt-get install nginx 

Global configuration.

We will be focusing on nginx and php-fpm. For mysql i let you checking some tutorials.

Contrary to what is found on the web, I do not recommend editing the file /etc/init.d/nginx unless you really know what you do.

This is /etc/nginx tree.

Nginx tree

First file to edit : nginx.conf

I let worker_processes to 1. Many website recommend changing this value to match numbers of CPU cores. So if you have a quadcore just put value: 4.

worker_connection : numbers of simultaneous connection by worker processes. Recommended value is between 512 and 2048.

keep_alive: when a visitor connect to the site, the established connection does not close shortly.This allows multiple requests passed through a single connection. It is recommended to put a value between 10 and 20 seconds.

Don't forget to reduce I/O. (please refer to access logs, error logs, open file cache, buffers and gzip compression). 

Using logrotate

You could create or modify /etc/logrotate.d/nginx if needed. Don't forget to adapt this file to your server !

/var/log/nginx/*.log { 
    #rotate the logfile(s) daily 
    # adds extension like YYYYMMDD instead of simply adding a number
    # If log file is missing, go on to next one without issuing an error msg 
    # Save logfiles for the last 10 days 
    rotate 10
    # Old versions of log files are compressed with gzip
    # Postpone compression of the previous log file to the next rotation cycle
    # Do not rotate the log if it is empty 
    #after logfile is rotated and nginx.pid exists, send the USR1 signal 
        [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`

Is the directive which is specific to postrotate nginx and that matters: Once log tours/archived you throw a stop signal to Nginx to recreate log files.

Php.ini configuration files

Why i m talking about php files and not file ? Because php-fpm read an other php.ini file than php cli for example.

Php-fpm file is located at 


And cli version


Of course don't forget to increase memory_limit, max_execution_time and specify date_timezone. 

Create virtualhost for ez

The file /etc/nginx/conf.d/default.conf contains all informations about localhost domain.

We are going to create a new file named ez.conf

server {
   listen 80;
   server_name  ez.local admin.ez.local;
   root /var/www/ez;
   index index.php;
   if (!-f $request_filename) {
       rewrite ^(.*)$ /404;
   location ~ "^/[^/]*\.php$" {
      set $script "index.php";
      if ( $uri ~ "^/(.*\.php)" ) {
         set $script $1;
      fastcgi_pass   unix:/tmp/php-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME /var/www/ez/$script;
      include        fastcgi_params;
   location / {
           rewrite "^/var/storage/(.*)$" "/var/storage/$1" break;
           rewrite "^/var/([^/]+)/storage/(.*)$" "/var/$1/storage/$2" break;
           rewrite "^/var/(([^/]+/)?)cache/(texttoimage|public)/(.*)$" "/var/$1cache/$3/$4" break;
           rewrite "^/design/([^/]+)/(stylesheets|images|javascript)/(.*)$" "/design/$1/$2/$3" break;
           rewrite "^/share/icons/(.*)$" "/share/icons/$1" break;
           rewrite "^/extension/([^/]+)/design/([^/]+)/(stylesheets|images|javascripts|javascript|flash|lib?)/(.*)$" "/extension/$1/design/$2/$3/$4" break;
           rewrite "^/packages/styles/(.+)/(stylesheets|images|javascript)/([^/]+)/(.*)$" "/packages/styles/$1/$2/$3/$4" break;
           rewrite "^/packages/styles/(.+)/thumbnail/(.*)$" "/packages/styles/$1/thumbnail/$2" break;
           rewrite "^/favicon\.ico$" "/favicon.ico" break;
           rewrite "^/robots\.txt$" "/robots.txt" break;
           rewrite "^/var/cache/debug.html(.*)$" "/var/cache/debug.html$1" break;
           rewrite "^/var/(([^/]+/)?)cache/public/(.*)$" "/var/$1cache/public/$3" break;
           rewrite "^/var/([^/]+)/cache/debug\.html(.*)$" "/var/$1/cache/debug.html$2" break;
           rewrite "content/treemenu/?$" "/index_treemenu.php" break;
           rewrite "ezjscore/call/?$" "/index_ajax.php" break;
           rewrite "^(.*)$" "/index.php?$1" last;

That's all for a basic virtualhost. I m using ez.local for the front office and admin.ez.local for the back office.

It's time to restart php-fpm and nginx

/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart

done :)

Proudly Developed with from