把上一篇中做完之后,坊问monitor.com结果仍是一片空白。接下来需要配置Lavarel为生产环境
1. 在sites-enable/monitor.conf中添加:
fastcgi_param APP_ENV dev;
同时确保在/var/www/monitor/目录下面有.env.production文件,该文件中 APP_ENV=production
现在再访问monitor.com有了一些变化,地址会自动变成 http://monitor.com/auth/login,说明Laravel已经在工作了,但是界面依然显示空白。
(后续补充:之后在新机器上重新安装时,为了简便直接将以前的整个monitor目录拷贝到新机器,发现浏览器空白并且地址没有任何变化,执行composer install或者php artisan migrate等命令都会报错如下:
PHP Warning: Uncaught ErrorException: require(/var/www/monitor/vendor/composer/../symfony/var-dumper/Resources/functions/dump.php): failed to open stream: No such file or directory in /var/www/monitor/vendor/composer/autoload_real.php:66
Fatal error: composerRequire9c3ebaa6f3c04183ab8f351e167ff291(): Failed opening required '/var/www/monitor/vendor/composer/../symfony/var-dumper/Resources/functions/dump.php' (include_path='.:/usr/share/php') in /var/www/monitor/vendor/composer/autoload_real.php on line 66
最后发现需要删掉 /var/www/monitor/vendor/composer目录,再重新执行composer install就能正常安装所有依赖,安装完成之后刷新浏览器网页就显示出来了)
2. 我想可能是因为数据库还没有迁移,于是开始迁移数据库。
先把.env.production中的数据库信息变成自己生产环境中的monitor数据库,执行php artisan migrate,结果报错:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin
g password: YES)
在网上找原因,看到贴子https://blog.csdn.net/zjiang1994/article/details/52585710 ,以为是没有清缓存,结果清了之后也同样报错。
homestead是.env中配置的数据库用户名,难道还在使用.env而不是.env.production?于是删除.env,但是又报错:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa
ssword: NO)
这次是forge,forge是在laravel项目下config/database.php中的值,难道forge没有被.env.production中的值覆盖?那么还是.env.production在数据库迁移时没有起作用,于是复制.env.production生成同样的.env,这回可以了。[关于此问题的补充:后来发现,在laravel项目的bootstrap/cache/config.php是一个缓存文件,所有配置均在此有一个缓存,包括.env中的数据库配置,这个缓存会导致你的改动并没有实际生效,造成一些误解,在项目移植之后,需要首先用 php artisan config:clear 命令清除掉该缓存文件。我之前看到的的这个env不生效的问题,掺杂着这个缓存没清所带来的一些问题。]
root@a-All-Series:/var/www/monitor# php artisan migrate
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> yes
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2017_06_25_062411_monitor_types
Migrated: 2017_06_25_063152_user_monitors
Migrated: 2017_06_25_063648_sender_groups
Migrated: 2017_06_25_063937_sender_people
Migrated: 2017_06_25_064408_monitor_logs
Migrated: 2017_07_08_125329_status
Migrated: 2018_08_14_112754_create_systems_table
Migrated: 2018_08_15_142824_create_sites_table
重新生成APP key: php artisan key:generate
root@a-All-Series:/var/www/monitor# php artisan db:seed
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> yes
Seeded: MonitorTypeSeeder
Seeded: AdminSeeder
Seeded: SystemTableSeeder
Seeded: SiteTableSeeder
从MYSQL workbench里面看,表格和数据都生成成功了。
可是可是,打开地址坊问仍然显示空白,还有哪里不对呢?
3. 经过摸索,原来还需要修改Bootstrap和storage的权限,修改了权限之后,我的网站就能正常访问啦。
chmod -R 777 storage bootstrap
4. 最后添加定时任务,将schedule:run 加到crontab中去,其中/var/www/monitor是项目目录。
php /var/www/monitor/artisan schedule:run