Thursday 21 April 2011 1:30:43 pm
Since there's a lot of scattered information on how to get eZ to work wih nginx, I am outlining the steps I have taken to get a working eZ Publish 4.2011 Community Project (~ 4.5) installation running with Nginx and pretty URL rewriting. The following howto assumes a clean netinstall of Debian 6 (Squeeze) with only base admin tools installed, but should be adaptable to other versions and distributions. If you want to modify an existing LAMP setup, you should uninstall all apache and php packages before continuing. Naturally, don't test this on a production server and always back up before attempting any modifications. All operations are assumed to be executed as root unless otherwise noted. Step 1: Update your apt sources file Nginx 1.0.0 and PHP-FPM (FastCGI Process Manager) 5.3.6 is available on dotdeb, and your apt sources file should be updated accordingly. Add the following to your /etc/apt/sources.list file:
deb http://packages.dotdeb.org stable all deb-src http://packages.dotdeb.org stable all
Update the dotdeb key:
wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add - Run: apt-get update Step 2: Install required packages
apt-get install nginx
apt-get install mysql-server
apt-get install php5-cli php5-common php5-suhosin apt-get install php5-fpm php5-cgi php5-curl php5-gd php5-imagick php5-mysql php5-apc imagemagick Step 3: configure PHP and nginx Update the files listed below:
In /etc/php5/fpm/pool.d/www.conf: listen = /tmp/php-fpm.sock
In /etc/php5/fpm/php.ini:
date.timezone = "YOUR TIME ZONE, such as Europe/Oslo"
short_open_tag = On
memory_limit = 256M
max_execution_time = 120
variables_order = "EGPCS" cgi.fix_pathinfo=0
In /etc/php5/cli/php.ini:
date.timezone = "YOUR TIME ZONE, such as Europe/Oslo" max_execution_time = 120
In /etc/nginx/sites-available/default: (or other site config file. sites-available/sites-enabled work the same way as in apache) (replace YOUR.INTERNET.HOSTNAME and YOUR_EZPUBLISH_ROOT as necessary) server {
server_name YOUR.INTERNET.HOSTNAME; root YOUR_EZPUBLISH_ROOT; index index.php;
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; } location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|swf|flv)$ { access_log off;
expires 30d;
} 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 $document_root$script; include fastcgi_params;
} } Step 4: reload php and nginx
/etc/init.d/php5-fpm restart /etc/init.d/nginx restart Step 5: Install or move eZ Publish Download and unpack the eZ Publish distribution to the chosen web root directory and install as normal. You can also move an existing installation, but it should be upgraded to eZ Publish 4.5 or 4.2011 community because of issues with fastcgi in earlier versions. Step 6: Update eZ Publish site.ini eZ Publish doesn't automatically recognise virtual host mode on Nginx as opposed to Apache. In settings/override/site.ini.append.php, add the following under the [SiteAccessSettings] block: ForceVirtualHost=true Step 7: Flush caches
su - www-data
cd /var/www/YOUR_EZ_PUBLISH_ROOT php bin/php/ezcache.php --clear-all --purge You should now have an eZ Publish installation that works just like it does under Apache - but with the load-handling and memory consumption benefits of Nginx. Thanks to Boris Huisgen for providing the basic rewrite rules for nginx.
Daniel A. Øien
Open Concept SA, Norway
Web: http://openconcept.no/
In English: http://openconcept.no/eng
|