简体   繁体   English

Openshift MySQL环境vars在PHP中不起作用

[英]Openshift MySQL Environment vars not working in PHP

I cant seem to get the MySQL Vars for Openshift to work in my PHP application. 我似乎无法使MySQL Vars for Openshift在我的PHP应用程序中工作。 I created a test.php file to try to get to the bottom of it. 我创建了一个test.php文件以尝试深入研究它。

test.php test.php

<?php
define( "DB_SERVER", getenv('OPENSHIFT_MYSQL_DB_HOST'));
echo "Host1 define: ".DB_SERVER;
echo "<br>Host2 getenv: ". getenv('OPENSHIFT_MYSQL_DB_HOST');
echo "<br>Host3 _env: ". $_ENV['OPENSHIFT_MYSQL_DB_HOST'];
echo "<br>Host4 _server: ". $_SERVER['OPENSHIFT_MYSQL_DB_HOST'];
echo "<br>Openshift App Name: ". $_ENV['OPENSHIFT_APP_NAME'];
?>

Output in browser: 在浏览器中输出:

Host1 define: Host1定义:
Host2 getenv: Host2 getenv:
Host3 _env: Host3 _env:
Host4 _server: Host4 _server:
Openshift App Name: web Openshift应用名称:web

I added in the Openshift App Name Var to show that some Openshift Vars are indeed working, but the MySQL ones are not for some reason. 我在Openshift应用程序名称Var中添加了代码,以表明某些Openshift Vars确实有效,但MySQL出于某些原因却没有。

PHP Cartridge version: 5.4 MySQL version: 5.5 PHP Cartridge版本:5.4 MySQL版本:5.5

Any ideas on how to further debug? 关于如何进一步调试的任何想法? I have started from a clean install, so this is very strange. 我是从全新安装开始的,所以这很奇怪。

Note: 注意:

Running echo $OPENSHIFT_MYSQL_DB_HOST in the Openshift SSH console DOES give me an IP address for the host. 在Openshift SSH控制台中运行echo $OPENSHIFT_MYSQL_DB_HOST确实为我提供了主机的IP地址。 I have also tried restarting the cartridge from the Openshift admin page, no luck. 我也尝试过从Openshift管理员页面重新启动墨盒,但不走运。

More than happy to give more info, I'm very keen on writing clear SO questions. 我非常乐于提供更多信息,我非常热衷于编写清晰的SO问题。

Finally found it! 终于找到了! Do a git push to trigger the mysql vars to work. 做一个git push触发mysql vars工作。

Create a dummy file in your git directory (example below for linux), commit, then push: 在您的git目录中创建一个虚拟文件(对于Linux以下示例),提交,然后推送:

touch test
git add test
git commit -m "Test file for triggering git push deploy process"
git push

Remember to delete the test file in your next commit. 记住在下一次提交时删除测试文件。

Even though I had tried to restart the cartridge from the Openshift web control panel, the thing that solved it was to push 'something' to git, and something in that deploy process allowed those variables for mysql to work. 即使我尝试从Openshift Web控制面板重新启动盒式磁带,解决该问题的方法是将“ something”推送到git,并且在该部署过程中有一些操作使mysql的那些变量能够正常工作。

I found a answer here ( https://stackoverflow.com/a/26898911/339803 ) that suggested to push to git at least once, but I didnt try that as I had already pushed to git to change the PHP DB config file from static values to $_ENV values. 我在这里找到了一个答案( https://stackoverflow.com/a/26898911/339803 ),该答案建议至少推送到git一次,但是我没有尝试过,因为我已经推送到git来更改PHP DB配置文件。静态值转换为$ _ENV值。 So I assumed that doing it again wouldnt help. 因此,我认为再次这样做将无济于事。

Nevertheless, as soon as I created a test file and pushed to git, the mysql variables worked. 不过,一旦我创建了一个测试文件并将其推送到git,mysql变量就起作用了。

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

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