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 $app->'get' function not working on production server.

Hi, I've a very odd issue, I was working with Phalcon Micro to create a Rest API, on my development server (PHP 5.6, Phalcon 2.0.13, Apache, Ubuntu 16) works like a charm, but I moved the code to the production server (AWS Instance, PHP 5.6, Phalcon 3.0.1, Apache, Ubuntu 16) and seem that not working like the development server because the ‘GET’ function of the Micro is not working but the ‘POST’ does. Here is an example:


use Phalcon\Mvc\Micro,
    Phalcon\Http\Response,
    Phalcon\Http\Request;   
    $app = new Micro();
    $app->get('/say/{id}', function($id){
    echo $id; 
    }
    $app -> handle();

This is working on my development server but the production server it doesn’t. On the production server I get a 404 when I request x.x.x.x/users/say/1234567


use Phalcon\Mvc\Micro,
    Phalcon\Http\Response,
    Phalcon\Http\Request;   
    $app = new Micro(); 
    $app->post('/', function(){
    $request = new Phalcon\Http\Request(); 
        // Get the user data from the request
        $user_data = $request->getJsonRawBody();
        print_r($user_data);
        }
    $app -> handle();

And the odd part is that this code is working in both servers. *Both codes are examples not actual code.

So, something changed between versions so I need to change my code, or is something I miss on the setup. Thank you very much for your time.

Regards!

x.x.x.x/users/say/1234567

But i see /say/{id}

I guess this is about some apache2 config and that's it. Not using it so can't help.



4.1k

Hi, thank you for the response, yep is /users/ because is the folder where is located the main file with the code.

x.x.x.x/users/say/1234567

But i see /say/{id}

I guess this is about some apache2 config and that's it. Not using it so can't help.

edited Aug '16

And you sure you have proper rewrite rule ? For instance try to:

$di->set('url', function () {
    $url = new Url();
    $url->setBaseUri('/users/');
    return $url;
});
$app->setDI($di);


4.1k

I'll try this, and yeah, I created a rewrite rule on the .htaccess on my users folder like this and on my index.php are my code.


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

And you sure you have proper rewrite rule ? For instance try to:

$di->set('url', function () {
   $url = new Url();
   $url->setBaseUri('/users/');
   return $url;
});
$app->setDI($di);
edited Aug '16
RewriteBase /users

or

RewriteCond %{REQUEST_FILENAME} !-d


4.1k
Accepted
answer

@Jurigag Thank you for your help, you help me to point to the right direction, after I active the apache “a2enmod rewrite” I don’t edit the 000-default.conf adding this lines:


<Directory "/var/www/">
    AllowOverride All
</Directory>

After adding the lines and restart the apache2 service, Everything worked just like the development sever.

Thank you to all, regards!