您已被告知不要对 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 可能更快。