Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 17d ago

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;
});