簡體   English   中英

Openshift環境變量不存在

[英]Openshift environment variables don't exist

我在安裝中添加了一個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

有人告訴您不要對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將文件推送到服務器上 您可能像我一樣(討厭嗎?),而我的簡單網站更喜歡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可能更快。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM