This time to everyone to bring lumen timezone how to do time zone settings, lumen timezone time zone settings to note what, the following is the actual case, take a look.
Based on the experience of Laravel 4.x and 5.0, just go to config/app.php to set the ' timezone ' parameter to ' PRC ' and find the Lumen Config directory in/vendor/laravel/lumen -framework/config path, but there is no timezone parameter option in the config/app.php parameter options, manual Plus is not valid.
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 ', ' Forge '), ' username ' = env (' db_username ', ' Forge '), ' password ' => ; Env (' Db_password ', '), ' charset ' = ' utf8 ', ' collation ' = ' utf8_unicode_ci ', ' prefix ' and 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 problem resolution. Because the project has the. 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 ($bas Epath = 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 the App_timezone and Db_timezone parameter values respectively.
Enable the. env configuration file
Rename the. env.example file under the lumen root directory to. Env, edit/bootstrap/app.php, and uncomment the following line of code
Dotenv::load (DIR. '/.. /');
Add:
Because Lumen uses Greenwich time by default, it needs to be converted to Beijing.
Add in. env
APP_TIMEZONE=PRC db_timezone=+08:00
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP implementation of statistics in binary 1 number of algorithm steps in detail
PHP Development Remote control server steps in detail