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

Micro Framework Endpoints Fail after Switch to Linux

So I've been developing on a Windows machine (I know, I know), and I'm having trouble with the switch over to Linux, as my routes are no longer being recognized. What's strange is that my error message appears to make it very clear that I AM connecting to the right route, but it's not going through.

For my Users handler, I have:

$users = new MicroCollection();
$users->setHandler('UsersController', true);
$users->setPrefix('/users');
$users->post('/login', 'login');
$app->mount($users);

and my notFound handler is being triggered when I try the login function:

$app->notFound(
    function () use ($app) {
        throw new ErrorException('URI not found: ' . $app->request->getMethod() . ' ' . $app->request->getURI(), 404, 10);
    }
);

Giving this error: URI not found: POST \/users\/login which seems to perfectly match the path it should.

I verified that all the path names are are the correct cases, and made sure my autoloader is working properly (Database connection is working fine, classes are all registered).

Any ideas what could have broken with the switch to Linux?

That would've been my first guess, but then how does the request know about the correct URI?

That was it! NGINX was misconfigured, I hadn't seen that it was shown in the docs, so I was manually configuring it, but I admit when it had the right URI I assumed I had set it all up correctly.

Not 100% sure if this is what caused it, but my app is in a subdirectory and I had failed to change the fastcgi_index to reflect that. I did make some other changes to match the docs better, but that was the most obvious mistake I noticed.

edited Nov '17

Nginx config with Phalcon is quite simple. What did you do wrong?

location / {
        try_files $uri $uri/ /index.php$is_args$query_string;
        }

And just set Router component to read info from $_SERVER['REQUEST_URI'].

$di->setShared('router', function (){
        $router = new \Phalcon\Mvc\Router(false); //Create the router without default routes (note: if routes are handled manually via MicroCollection)

        //we're using Front Page Controller pattern in relation from nginx -> Phalcon
        $router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI); // Use $_SERVER['REQUEST_URI']

        //Set whether router must remove the extra slashes in the handled routes
        $router->removeExtraSlashes(true);

    return $router;
});