API not working on production [Error 500]

I made a very basic API with 2 simple controllers like this one


<?php


namespace api\controllers;


use yii\rest\ActiveController;


class TimeController extends ActiveController

{

    public $modelClass = 'api\models\Time';

}

It works locally but when I try to run it on production I only get a XML with error 500


<response>

<name>Internal Server Error</name>

<message>An internal server error occurred.</message>

<code>0</code>

<status>500</status>

</response>

I tried to add a regular controller inside my api application and it works fine.

Here is my api/config/main.php




<?php

$params = array_merge(

    require __DIR__ . '/../../common/config/params.php',

    require __DIR__ . '/../../common/config/params-local.php',

    require __DIR__ . '/params.php',

    require __DIR__ . '/params-local.php'

);


return [

    'id' => 'app-api',

    'basePath' => dirname(__DIR__),

    'controllerNamespace' => 'api\controllers',

    'bootstrap' => ['log'],

    'modules' => [],

    'components' => [

        'request' => [

        'parsers' => [

	          'application/json' => 'yii\web\JsonParser',

	        ],

      	],

        'user' => [

            'identityClass' => 'common\models\User',

            'enableAutoLogin' => true,

            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],

        ],

        'session' => [

            // this is the name of the session cookie used for login on the api

            'name' => 'advanced-api',

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

        

        'urlManager' => [

            'enablePrettyUrl' => true,

            // 'enableStrictParsing' => true,

            'showScriptName' => false,

            'rules' => [

                [

                	'pluralize' => false,

                    'class' => 'yii\rest\UrlRule', 

                    'controller' => 'time',

                    'tokens' => [

                        '{id}' => '<id:\\w+>'

                    ]

                ],

                [

                	'pluralize' => false,

                    'class' => 'yii\rest\UrlRule', 

                    'controller' => 'jogo',

                    'tokens' => [

                        '{id}' => '<id:\\w+>'

                    ]

                ]

            ],        

        ],

        

    ],

    'params' => $params,

];



What is the log from app.log and apache?

Sorry for the long time without an answer. I was busy with other projects. So, log says:




An Error occurred while handling another error:\nexception 'yii\\base\\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in /var/www/futebola/vendor/yiisoft/yii2/base/Module.php:537\nStack trace:\n#0 /var/www/futebola/vendor/yiisoft/yii2/web/ErrorHandler.php(97): yii\\base\\Module->runAction('site/error')\n#1 /var/www/futebola/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\\web\\ErrorHandler->renderException(Object(yii\\web\\NotFoundHttpException))\n#2 [internal function]: yii\\base\\ErrorHandler->handleException(Object(yii\\web\\NotFoundHttpException))\n#3 {main}\nPrevious exception:\nexception 'yii\\base\\InvalidRouteException' with message 'Unable to resolve the request "".' in /var/www/futebola/vendor/yiisoft/yii2/base/Module.php:537\nStack trace:\n#0 /var/www/futebola/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction('', Array)\n#1 /var/www/futebola/vendor/yiisoft/yii2/base/Application.php(386): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))\n#2 /var/www/futebola/api/web/index.php(17): yii\\base\\Application->run()\n#3 {main}\n\nNext exception 'yii\\web\\NotFoundHttpException' with message 'Page not found.' in /var/www/futebola/vendor/yiisoft/yii2/web/Application.php:115\nStack trace:\n#0 /var/www/futebola/vendor/yiisoft/yii2/base/Application.php(386): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))\n#1 /var/www/futebola/api/web/index.php(17): yii\\base\\Application->run()\n#2 {main}\n$_SERVER = [\n    'HTTP_HOST' => 'api.futebola.jhob.com.br',\n    'HTTP_CONNECTION' => 'keep-alive',\n    'HTTP_UPGRADE_INSECURE_REQUESTS' => '1',\n    'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',\n    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',\n    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',\n    'HTTP_ACCEPT_LANGUAGE' => 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',\n    'HTTP_COOKIE' => 'advanced-api=5lhanneg8f9qnkjsp7attkdu81; _csrf=d250edab010879419d527c6cdb6360aad061ba6b112ab4bbabfd32d0820732b8a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22Z5RJUvU-RQ2-WzdWisD4iQR29aN7cyPp%22%3B%7D',\n    'PATH' => '/usr/local/bin:/usr/bin:/bin',\n    'SERVER_SIGNATURE' => '<address>Apache/2.2.22 (Debian) Server at api.futebola.jhob.com.br Port 80</address>\n',\n    'SERVER_SOFTWARE' => 'Apache/2.2.22 (Debian)',\n    'SERVER_NAME' => 'api.futebola.jhob.com.br',\n    'SERVER_ADDR' => '207.182.128.211',\n    'SERVER_PORT' => '80',\n    'REMOTE_ADDR' => '200.181.189.109',\n    'DOCUMENT_ROOT' => '/var/www/futebola/api/web',\n    'SERVER_ADMIN' => '[no address given]',\n    'SCRIPT_FILENAME' => '/var/www/futebola/api/web/index.php',\n    'REMOTE_PORT' => '59984',\n    'GATEWAY_INTERFACE' => 'CGI/1.1',\n    'SERVER_PROTOCOL' => 'HTTP/1.1',\n    'REQUEST_METHOD' => 'GET',\n    'QUERY_STRING' => '',\n    'REQUEST_URI' => '/',\n    'SCRIPT_NAME' => '/index.php',\n    'PHP_SELF' => '/index.php',\n    'REQUEST_TIME_FLOAT' => 1518281767.7639999,\n    'REQUEST_TIME' => 1518281767,\n]



I believe that when I try to access /time Yii is trying to find a to find the controller Time and its view (index.php) with i don’t have because it’s a rest controller

Found the problemn. Database parameters was wrong.