Based on the experience of Laravel 4.x and 5.0, simply go to the config/app.php set under the ' timezone ' parameter for ' PRC ' and find the Lumen Config directory under the /vendor/laravel/lumen-framework/config
path, but config/ There is no timezone parameter option in the app.php parameter option, and it is not valid after manual addition.
Then think of the. env file of Laravel 5 and found that there are no options in lumen. env file for timezone settings.
Go back to the Config directory and see the settings in config/database.php, the default configuration for MySQL is as follows:
' MySQL ' = [' Driver ' =' MySQL ',' Host ' = env (' Db_host ',' localhost '),' Port ' = env (' Db_port ',3306), ' database ' + env ( ' Db_database ', ' username ' = env ( db_ USERNAME ', ' Forge '), ' password ' = env ( Db_password ', ' charset ' = ' collation ' = utf8_ Unicode_ci ', ' prefix ' = env ( ' Db_prefix ', ' timezone ' = env ( ' Db_timezone ', ' +00:00 '), ' strict ' = false,],
Here is a database of the timezone settings, the default +00:00, that is, UTC time, changed to +08:00
solve the problem. Because the project has a .env
configuration file enabled, a line is eventually added to the. env file
DB_TIMEZONE=+08:00
Database timezone problem resolution.
The timezone problem of the database is solved, but the timezone problem of the app has not been solved, the global search Lumen project, find the place of timezone, /vendor/laravel/lumen-framework/src/Application.php
find the code of initializing lumen timezone part in the file
/** * Create a new Lumen application instance. * * @param string|null $basePath * @return void */public function __construct($basePath = null){ date_default_timezone_set(env(‘APP_TIMEZONE‘, ‘UTC‘)); $this->basePath = $basePath; $this->bootstrapContainer(); $this->registerErrorHandling();}
The. env parameter used in the code is App_timezone, the value is UTC, where UTC is changed to PRC, or added in an. env file
APP_TIMEZONE=PRC
Lumen PHP time zone setting problem resolved.
Lumen Time Zone Settings summary
Edit. env file Add configuration
APP_TIMEZONE=PRCDB_TIMEZONE=+08:00
If the. env configuration file is not enabled, edit
/vendor/laravel/lumen-framework/config/database.php/vendor/laravel/lumen-framework/src/Application.php
Modify APP_TIMEZONE
and DB_TIMEZONE
parameter values respectively.
Enable the. env configuration file
Rename the file under the Lumen root directory .env.example
to .env
, edit /bootstrap/app.php
, and uncomment the following line code
Dotenv::load(__DIR__.‘/../‘);
转自:http://www.widlabs.com/article/lumen-set-timezone
Lumen Time zone settings