简体   繁体   English

具有MySQL连接的Ubuntu Lamp PHP脚本未使用Apache

[英]Ubuntu Lamp php script with mySQL connection not using Apache

Hi I got a strange problem with my LAMP installation 嗨,我的LAMP安装遇到了一个奇怪的问题

I'm using an Ubuntu Server with PHP5 Apache and mySQL, all runs great when accessing via http. 我正在使用带有PHP5 Apache和mySQL的Ubuntu Server,通过http访问时,它们都运行良好。

But the thing is, I also want to trigger some scripts using bash, basically so I can trigger them at will and prevent them being used via Apache/HTTP 但问题是,我还想使用bash触发一些脚本,因此基本上我可以随意触发它们并防止通过Apache / HTTP使用它们

The scripts themselves run when called with php5, all includes are found. 脚本本身在用php5调用时运行,找到了所有包含的脚本。 But for some unknown reason mySQL does not seem to initiate the Database the way it does via Apache. 但是由于某些未知的原因,mySQL似乎不像通过Apache那样启动数据库。 I just get a message back saying no database is connected. 我刚收到一条消息,说没有数据库连接。

Is there some special setup for bash related php calls? bash相关的php调用是否有一些特殊的设置?

Figured it out. 弄清楚了。 There are no special DB settings for PHP run from Bash, However because I work on several Servers I was using the $_SERVER['HTTP_HOST'] variable to determin which login credentials should be used. 从Bash运行的PHP没有特殊的数据库设置,但是因为我在多个服务器上工作,所以我使用$ _SERVER ['HTTP_HOST']变量来确定应使用的登录凭据。 Therefore it only worked on the server where the default credentials were correct. 因此,它仅在默认凭据正确的服务器上工作。

For now I just put in an extra option in the code that uses credentials based on the value of the dirname(__FILE__) variable. 现在,我只是在代码中添加了一个额外的选项,该选项基于dirname(__ FILE__)变量的值使用凭据。 Works great. 效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM