We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Namespace / routing issues in staging nginx

When moving my app to staging i have encountered an issue with auto loading with the following error:

 5876#0: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'App\Config\Config' not found in /var/www/app.com/public/index.php on line 23" while reading response header from upstream, client: xx.xx, server: app.syack.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "app.com"

Environment

  • Ubuntu 14.04
  • Phalcon 2.0.5 PPA
  • Staging: nginx Dev: apache

What I've Tried

  • Verified phalcon extension present
  • Manually included the class (fails later with other namespaces)
  • Double checking nginx config

Index.php

use \App\Config\Config;
use \App\Config\Modules;
use \Phalcon\DI\FactoryDefault;
use \Phalcon\Mvc\Application as BaseApplication;

class Application extends BaseApplication
{   
    protected function registerServices()
    {
        $loader = new \Phalcon\Loader();
        $loader->registerNamespaces(
            array(
               "App\Config"    => "../app/config/",
            )
        )->register();

        require_once __DIR__ . '../../vendor/autoload.php';

        $config = new Config(); \\fail line 23

nginx config

server {
    listen 80;

    server_name app.com;

    index index.php index.html index.htm;

    set $root_path '/var/www/app.com/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^(.*)$ /index.php?_url=$1;
    }

    location ~ \.php$ {
       # try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index /index.php;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

   location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
   }

    location ~ /\.ht {
       deny all;
    }


3.1k
edited Aug '15

Ive done some more debugging and actually removed phalcon. Getting the same issue. Its almost like phalcon is not installed. The module is listed under phpinfo and its extension is valid. No errors in php fpm log.



3.1k
Accepted
answer
edited Aug '15

Removed PPA, compiled from source. This seemed to fix the issue. Only issue now is a volt caching issue. (permissions) easy fix.

edited Aug '15

Removed PPA, compiled from source. This seemed to fix the issue. Only issue now is a volt caching issue. (permissions) easy fix.

Hi, I have the same issue. Could you please describe the solution in details? (English is not my main language). I tried to compile phalcon from sources and to install from a repository but the result didn't change.

Thanks.



3.1k

If you are uing the nginx configuration as described in the documentation, you need to verify that cgi.fix_pathinfo is set to cgi.fix_pathinfo=1 in the php ini file. The configuration assumes that this is set.. This was also related to my issue.

My Nginx Config

server {
    listen 80;

    server_name domain.com;

    index index.php index.html index.htm;

    set $root_path '/var/www/domain.com/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^(.*)$ /index.php?_url=$1;
    }

    location ~ \.php$ {
       # try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index /index.php;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

   location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
   }

    location ~ /\.ht {
       deny all;
    }
}

If you are uing the nginx configuration as described in the documentation, you need to verify that cgi.fix_pathinfo is set to cgi.fix_pathinfo=1 in the php ini file. The configuration assumes that this is set.. This was also related to my issue.

Thanks



3.1k

did this solve your problem

If you are uing the nginx configuration as described in the documentation, you need to verify that cgi.fix_pathinfo is set to cgi.fix_pathinfo=1 in the php ini file. The configuration assumes that this is set.. This was also related to my issue.

Thanks

did this solve your problem

As to my case, the error had the other reason. But anyway thanks for your response. I think it could be useful for others.