【问题标题】:Openshift environment variables don't existOpenshift 环境变量不存在
【发布时间】:2014-06-30 09:54:10
【问题描述】:

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

【问题讨论】:

    标签: php apache openshift


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 2019-09-13
      相关资源
      最近更新 更多