ScaleScaleScaleScale

Tips / Nginx


Nginx configuration for CakePHP framework

CakePHP is a free open-source development framework for PHP. This fabulous framework can enable you to work in a structured and rapid way, without losing any flexibility while you write the code. Today we are going to share you a basic CakePHP configuration for Nginx webserver.

I will assume you have nginx and php-fpm properly installed and configured to work with sockets, otherwise, you should need to change fastcgi_pass_unix to 127.0.0.1:9000, that is the default port and interface php-fpm listen to. Also, feel free to change domain.tld with your own domain name and root directory to the real directory of your app.

server {
    listen   80;
    server_name www.mysite.com;
    rewrite ^(.*) http://mysite.com$1 permanent;
}

server {
    listen   80;
    server_name mysite.com;

    root   /var/www/mysite.com/public/app/webroot/;
    index  index.php;

    access_log /var/www/mysite.com/log/access.log;
    error_log /var/www/mysite.com/log/error.log;

    # main cakephp rewrite rule
    location / {
        try_files $uri $uri/ /index.php?$uri&$args;
    }

        location ~ .php$ {
            root           /var/www/mysite.com/public/app/webroot/;
            try_files $uri =404;
            fastcgi_pass   unix:/tmp/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 4k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }

}

If you have troubles, please reffer to the official documentation.

Popular search terms:

  • cakephp nginx
  • nginx cakephp url rewrite
  • cakephp run on nginx server
  • gencake neginx
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking