How to run (or run) Composer on Openshift?

I am trying to create a Skendton ZendFramework application on Openshift. I created a PHP5 application using these instructions and cloned it locally. I cloned the ZendFramework skeleton application in the repository, and then ran Composer to install the dependencies locally.

Then I moved my repository to Openshift, but I got the following error message:

Fatal error: Uncaught exception 'RuntimeException' with message
'Unable to load ZF2. Run `php composer.phar install`
or define a ZF2_PATH environment variable.' in
/var/lib/openshift/559d4d8f500446844700002b/app-
root/runtime/repo/init_autoloader.php:51 Stack trace: #0
/var/lib/openshift/559d4d8f500446844700002b/app-
root/runtime/repo/public/index.php(18): require() #1 {main} thrown in
/var/lib/openshift/559d4d8f500446844700002b/app-
root/runtime/repo/init_autoloader.php on line 51

which indicates that I need to run Composer on Openshift. How to achieve this?

In my local repository, the directory is /vendorpopulated with dependency directories. However, /vendorignored in commit. I could try to commit and push it, but is this the right way? It does not look clean.

+4
2

, composer install OpenShift.

, - use_composer .openshift/markers.

.openshift/markers/use_composer

: https://developers.openshift.com/en/php-markers.html


, composer install, , Composer, action_hooks - . bash.

. https://developers.openshift.com/en/managing-action-hooks.html

.openshift/action_hooks/build:

#!/bin/bash

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 )
+6

- , .. script, . deploy:

#!/bin/bash
# @file
#   .openshift/action_hooks/deploy

COMPOSER_DIR="$OPENSHIFT_DATA_DIR/bin"

function install_composer() {
    echo 'Installing Composer'

    if [ ! -d "$COMPOSER_DIR" ]
    then
        mkdir -p $COMPOSER_DIR
    fi

    curl -s https://getcomposer.org/installer | php -- --install-dir=$COMPOSER_DIR
}

if [ ! -x "$COMPOSER_DIR/composer" ]
then
    install_composer
fi

$COMPOSER_DIR/composer self-update
cd $OPENSHIFT_REPO_DIR
$COMPOSER_DIR/composer install

script : chmod +x .openshift/action_hooks/deploy.

+1

Source: https://habr.com/ru/post/1598356/


All Articles