php – 同一服务器上的两个Laravel应用程序相互冲突

我在同一台服务器上运行了2个Laravel应用程序.服务器是Apache 2.4,我设置了vhost来为不同域上的每个应用程序提供服务.

一个应用程序是一个API,它的.env文件设置如下:

APP_ENV=production
APP_KEY=YYYYYYYYYYYYYYYYYY
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=https://notify.mysite.com
APP_DOMAIN=notify.mysite.com


DB_CONNECTION=MysqL
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=notify
DB_USERNAME=YYYYYYYYYYYYYYYYYY
DB_PASSWORD=YYYYYYYYYYYYYYYYYY

broADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

第二个应用程序是一个UI,其中包括使用来自第一个应用程序的API.它的.env文件设置如下:

APP_ENV=local
APP_KEY=XXXXXXXXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=https://asapps.mysite.com
APP_DOMAIN=asapps.mysite.com
APP_VERSION=1


DB_CONNECTION=MysqL
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=asapps
DB_NOTIFY_DATABASE=notify
DB_FLIGHT_DATABASE=flights
DB_USERNAME=XXXXXXXXXXXXXX
DB_PASSWORD=XXXXXXXXXXXXXX

broADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

我可以从Swagger编辑器,Postman和其他服务器向我的API发送消息,一切都按预期工作.

我的第二个应用程序本身也按预期工作.

但是,如果我的第二个应用程序向API发送请求,则API应用程序会抛出此错误

exception ‘PDOException’ with message ‘sqlSTATE[42S02]: Base table or view not found: 1146 Table ‘asapps.preprocessor_config’ doesn’t exist’
in C:\notify\vendor\laravel\framework\src\Illuminate\Database\Connection.PHP:332

WTH?

API的数据库设置为DB_DATABASE = notify,当我从其他服务器发送消息时,它确实正确地使用了该连接.那么为什么要尝试使用第二个应用程序的数据库呢?
 我从该应用程序调用API时的连接???它几乎就像它缓存数据库连接并试图继续使用同一个……如何阻止它?

Table ‘asapps.preprocessor_config’ doesn’t exist’

解决方法:

经过更多的挖掘(阅读疯狂的谷歌搜索),我找到了problem and solution here

底线,当站点A接受请求时,PHP会在http请求的整个长度上加载它的.env变量.在该请求期间,当站点A调用站点B时,由于它们位于运行相同PHP的同一服务器上,因此PHP仍然使用来自站点A的.env并且根本不单独加载站点B的.env文件.

作者的更好解释:

The .env file with the variables was created so that people would not push their credentials to github repositories and other places where they may share the source.

Now, being environment variables they become system wide for the entire duration of the http request (in this case script execution). The point is that you got a long running script.

To find a definitive solution you Could go one of the three ways.

….

‘namespace’ the ENV variables.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...