CakePHP 3: Ain’t gonna GET if it ain’t gotta GET

Written by James McDonald

April 1, 2016

Just installed CakePHP3 under nginx and tried to switch between pages of a paginated view and every time it would return the default 1st page.

The url for each page was

Discovered using debug_kit that the GET request QUERY_STRING parameters weren’t being sent to CakePHP. The query string is everything after the question mark in the URL. In other words page=2.

This was because nginx wasn’t sending the query string to the PHP-FPM process.

But the fix:

    document_root /var/www/html/;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 1d;
        #log_not_found off;
        rewrite ^/cake3(?!/webroot)(.+)$ /cake3/webroot$1? break;
        try_files $uri $uri/ =404;

    location /cake3 {
           rewrite ^/cake3(?!/webroot)(.+)$ /cake3/webroot$1$is_args$args break;
           # put $is_args$args into the rewrite statement above
           try_files $uri $uri/ /cake3/index.php$is_args$query_string;

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;


Submit a Comment

Your email address will not be published.

You May Also Like…

List your VSCode Extensions

Ever wondered what extensions you have installed and want to keep a list? This actually is a good way to audit your...