Wrong PHP version returned in Openshift

心不动则不痛 提交于 2019-12-12 02:43:10

问题


I have created a PHP application (from scratch) using instructions available here. In /mish/make.sh, the php version is 5.5.18. After the build, the php info page confirms the version: 5.5.18.

Yet, when I log in my Openshift application with SSH, php --version returns 5.3.3 with a wrong build date:

I discovered this issue when I tried to install Composer on Openshift. I got an error message when git pushing back to Openshift:

I don't know whether the issue is related to the DYI cartridge or to Openshift itself. Does anyone know?

Update

From an email exchange with John Lamb, the solution was to include my PATH export in the build script as following (see this question):

#!/bin/bash

export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH}

export COMPOSER_HOME="$OPENSHIFT_DATA_DIR/.composer"

if [ ! -f "$OPENSHIFT_DATA_DIR/composer.phar" ]; then
    curl -s https://getcomposer.org/installer | php -- --install-dir=$OPENSHIFT_DATA_DIR
else
    php $OPENSHIFT_DATA_DIR/composer.phar self-update
fi

( unset GIT_DIR ; cd $OPENSHIFT_REPO_DIR ; php $OPENSHIFT_DATA_DIR/composer.phar install )

回答1:


Edited because I don't have enough points to comment:

Could you post your build hook script (.openshift/action_hooks/build)? laobubu's response should have solved your problem.


From my response to your bugzilla bug: The custom PHP binary should be found at $OPENSHIFT_HOMEDIR/app-root/runtime/bin/php

Here's the steps I followed to make this work:

  • # rhc app-create p55test diy-0.1 --from-code'https://github.com/laobubu/openshift-php5.5-cgi-apache.git'

    Application Options
    -------------------
    Domain:      jltest
    Cartridges:  diy-0.1
    Source Code: https://github.com/laobubu/openshift-php5.5-cgi-apache.git
    Gear Size:   default
    Scaling:     no
    
    Creating application 'p55test' ... done
    
      Disclaimer: This is an experimental cartridge that provides a way to try unsupported languages, frameworks, and middleware on OpenShift.
    
    Your application 'p55test' is now available.
    
      URL:        http://p55test-jltest.dev.rhcloud.com/
      SSH to:     xxxxxxxxxxxxxxxxxxxxxxxx@p55test-jltest.dev.rhcloud.com
    
      Git remote: ssh://xxxxxxxxxxxxxxxxxxxxxxxx@p55test-jltest.dev.rhcloud.com/~/git/p55test.git/
    
    Run 'rhc show-app p55test' for more details about your app.
    
  • # curl 'http://p55test-jltest.dev.rhcloud.com/'

    <html>
    <head>
    <title>Installed</title>
    </head>
    <body>
    <h1>Installed</h1>
    <p>You just created one amazing PHP5.5+Apache app.</p>
    <h2>Next...</h2>
    <p>
    <p>Follow the instruction on <a href=https://github.com/laobubu/openshift-php5.5-cgi-apache>https://github.com/laobubu/openshift-php5.5-cgi-apache</a>.
    <p>You can refresh this page to check if the world is ready.
    <p><a href=?doitnow>Come on, robot, you can do it automatically...</a><p>
    </p></body></html>
    
  • # curl 'http://p55test-jltest.dev.rhcloud.com/?doitnow'

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>302 Found</title>
    </head><body>
    <h1>Found</h1>
    <p>The document has moved <a href="./?working">here</a>.</p>
    <hr>
    <address>Apache/2.2.15 (Red Hat) Server at p55test-jltest.dev.rhcloud.com Port 80</address>
    </body></html>
    
  • # rhc ssh p55test

    [p55test-jltest.dev.rhcloud.com xxxxxxxxxxxxxxxxxxxxxxxx]\> top
    
  • wait for 'make.sh' to finish

  • [p55test-jltest.dev.rhcloud.com xxxxxxxxxxxxxxxxxxxxxxxx]\> $OPENSHIFT_HOMEDIR/app-root/runtime/bin/php --version

    PHP 5.5.18 (cli) (built: Jul 22 2015 10:33:49)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    

Also, since I closed the ticket, I realized you can verify the version of PHP actually running the code from your repo like so:

  • # curl 'http://p55test-jltest.dev.rhcloud.com/?phpinfo'

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>302 Found</title>
    </head><body>
    <h1>Found</h1>
    <p>The document has moved <a href="./15541_PHPINFO_TEMP.php">here</a>.</p>
    <hr>
    <address>Apache/2.2.15 (Red Hat) Server at p55test-jltest.dev.rhcloud.com Port 80</address>
    </body></html>
    
  • # curl 'http://p55test-jltest.dev.rhcloud.com/15541_PHPINFO_TEMP.php' | grep -i 'php version'

    ...snip...
    <h1 class="p">PHP Version 5.5.18</h1>
    <tr><td class="e">PHP Version </td><td class="v">5.5.18 </td></tr>
    



回答2:


The PHP version you build is not the active/used one.

You need to find out, in which folder your new PHP build lives and execute the binary over there. It seems PHP is build in the misc folder and not installed to the runtime folder. You might also alias it.

PHP should go into the runtime folder, e.g. ${OPENSHIFT_HOMEDIR}/app-root/runtime/php5/bin/php.


A quick glance at your scripts reveals:

  • you define export OPENSHIFT_RUNTIME_DIR=${OPENSHIFT_HOMEDIR}/app-root/runtime in /misc/common.sh.
  • you need to check, that PHP lands in runtime folder (is it in misc?)
  • no alias for PHP, e.g. alias php='${OPENSHIFT_RUNTIME_DIR}/php5/bin/php'.



回答3:


Running which php in your terminal will yield /usr/bin/php, which means that the PHP 5.3.3 comes from the system , not your own build.

If you want to use your own PHP, run this command:

export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH}

If you are using openshift hooks ( under .openshift/action_hooks ), try adding the command into your hook scripts.



来源:https://stackoverflow.com/questions/31478610/wrong-php-version-returned-in-openshift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!