Cron - Yii Advance console

I’m trying to create a Cron, so far my code works fine on my localhost, but on live i get this error

PHP Warning:  require(/var/www/html/common/config/db-local.php): Failed to open stream: No such file or directory in /var/www/html/common/config/main.php on line 3
PHP Fatal error:  Uncaught Error: Failed opening required '/var/www/html/common/config/db-local.php' (include_path='.:/usr/share/php') in /var/www/html/common/config/main.php:3
Stack trace:
#0 /var/www/html/yii(16): require()
#1 {main}

in my /frontend/web/index.php i have this

$localhost = [
   '127.0.0.1',
   '::1'
];

if(isset($_SERVER['REMOTE_ADDR']) && in_array($_SERVER['REMOTE_ADDR'], $localhost)) { 
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
}
else { 
    defined('YII_DEBUG') or define('YII_DEBUG', false);
    defined('YII_ENV') or define('YII_ENV', 'prod');
}

in common/config/main.php i have this on the very top

print_r(YII_ENV); die;

on local print_r(YII_ENV); die; i get dev, but on live i still get dev when i run this command in command prompt

php yii cron/reports

Why does YII_ENV not change to prod on console? Thanks

First: when you run php cli command on your production server you are on localhost from the server’s point of view. Second: using $_SERVER methodology has meaning with request from web server, not cli. It would be much better to have distinct entry point for web requests and for cli commands. Both basic and advanced templates work this way (web/index.php vs. yii).

See https://www.php.net/manual/en/reserved.variables.server.php

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server […]

so i have to create a /web/index.php in the console folder? just like how i have it in my frontend? sorry, still not clear on how to fix this

No. If you are following the ‘advanced template’ pattern you already have got the yii (yii.bat also for windows) file in your application root folder. That is the entry point for all CLI commands you can create. If you don’t have any just install new application template to empty folder and study how it is organized there.

oh!! understand. i edited the yii and yii_test files in root directory, and it works! thank you!