Openshift环境变量不存在

时间:2014-06-30 09:54:10

标签: php apache openshift

我已经在安装中添加了一个MySQL盒,并且可以在通过CLI界面运行php时看到环境变量。

  

php -r'echo $ _SERVER [“OPENSHIFT_MYSQL_DB_HOST”];'   // 127.2.234.2

但是,当通过Web界面调用同一变量时,未设置变量。我通过rhc app restart重新启动了apache和整个应用程序

相关: https://stackoverflow.com/questions/24434922/apache-on-openshift-undefine-environment-variables

1 个答案:

答案 0 :(得分:0)

您被告知不要硬编码IP地址,因为它会改变。 例如https://developers.openshift.com/en/managing-environment-variables.html

但是当您在网站上运行脚本时,IP地址丢失了。

<?php
print(getenv('PHPRC'));
print('<p>');
print(getenv('OPENSHIFT_MYSQL_DB_HOST'));
?>

你明白了。 IP地址丢失。

/var/lib/openshift/xxf1b5b94382ec898b00xxxx/php/configuration/etc/php.ini

而不是

/var/lib/openshift/xxf1b5b94382ec898b00xxxx/php/configuration/etc/php.ini
127.5.nnn.nnn

这可能是因为您没有使用Git将文件推送到您的服务器。 你可能喜欢我(一个luddite?)和我的简单网站的首选sftp。

需要的步骤 - 如果您不熟悉git
查看您的OpenShift网站,“应用程序”选项卡,源代码

ssh://xxf1b5b94382ec898b00xxxx@xxxx-xxxxx.rhcloud.com/~/git/php.git/

这假设你在本地安装了git。 这需要从服务器上取下OpenShift git存储库的副本并将其放在本地计算机上。

git clone ssh://xxf1b5b94382ec898b00xxxx@pappname.rhcloud.com/~/git/php.git/

克隆到'php'......

remote: Counting objects: 19, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 19 (delta 2), reused 19 (delta 2)
Receiving objects: 100% (19/19), 18.17 KiB | 0 bytes/s, done.
Resolving deltas: 100% (2/2), done.
Checking connectivity... done.

将一些文件复制到它在本地计算机上创建的php子文件夹

$ git add .
$ git commit -m "A change to my application"]
$ git push

这将重启你的应用程序和mysql。

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 2.80 KiB | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Stopping PHP 5.4 cartridge (Apache+mod_php)
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Stopping MySQL 5.5 cartridge
remote: Stopping PHPMyAdmin cartridge
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Building git ref 'master', commit 092cd25
remote: Checking .openshift/pear.txt for PEAR dependency...
remote: Preparing build for deployment
remote: Deployment id is e7791836
remote: Activating deployment
remote: Starting MySQL 5.5 cartridge
remote: Starting PHPMyAdmin cartridge
remote: Starting PHP 5.4 cartridge (Apache+mod_php)
remote: Application directory "/" selected as DocumentRoot
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success

现在您的环境变量将正常工作。 是的,sftp可能更快。