I have an application written in PHP using Fuelphp 1.6.3 and want to deploy it on Openshift

As the framework required composer, when I access my app at http://audit-manhthang.rhcloud.com/public/, it showed the error

Composer is not installed. Please run "php composer.phar update" in the root to install Composer

I have Google it and found an article here: https://www.openshift.com/content/support-for-git-clone-on-the-server-aka-support-php-composerphar I've tried to follow the instruction, create the file name deploy in .openshift/action_hooks folder and added following:

unset GIT_DIR
cd $OPENSHIFT_REPO_DIR/libs
wget -qN http://getcomposer.org/composer.phar
php composer.phar install

But it doesn't work. I have tried to revise install by update

unset GIT_DIR
cd $OPENSHIFT_REPO_DIR/libs
wget -qN http://getcomposer.org/composer.phar
php composer.phar update

But nothing change. I use PHP 5.3 Cartridge on Openshift

有帮助吗?

解决方案 3

I figure it out. With openshift, I can access via SSH and go to app-root(or something like that)/repo/php and then type /usr/bin/php composer.phar update. That's it.

其他提示

When I did composer update

cd app-root/runtime/repo/php
/usr/bin/php composer.phar update

I received error like this

[RuntimeException]                                                                                        
  /var/lib/openshift/52d3b7bd500446f4300001a5/.composer/cache/vcs does not exist and could not be created.

Composer is using $HOME variable to find root path. So to fix that I did.

export HOME=/var/lib/openshift/52d3b7bd500446f4300001a5/app-root/runtime/repo/php

and then

/usr/bin/php composer.phar update

worked.

After update was done I reverted $HOME

export HOME=/var/lib/openshift/52d3b7bd500446f4300001a5 

Looks like there have been some changes how openshift works now. I know that this is quite ugly workaround. If I will find something better, I will update this answer. Still, hope this will help someone.


EDIT

Got it! :)

Create new file under .openshift directory:

.openshift/action_hooks/deploy

and mark it as executable.

#!/bin/bash
# Run composer install

cd app-root/runtime/repo/php

export HOME_ORIGIN=$HOME
export HOME=$HOME/app-root/runtime/repo/php

/usr/bin/php composer.phar install

export HOME=$HOME_ORIGIN

After that on every push composer will be updated to current composer.lock place. Perfect! :)

Also make sure vendor/ path is empty. Better add to .gitignore so it not messed up by your local setup.

Here is a slightly better solution than the others mentioned: http://stanlemon.net/2013/03/22/composer-on-openshift/

The deploy script mentioned in the blog post:
a. downloads composer if not present and stores it in the data directory so that it persists across git pushes
b. enables composer to use cached versions of packages in the .composer dir stored in the persistent data directory, thus decreasing the time required when doing frequent pushes

There was a small issue with the script - that the php version it was referring to was being complained as being too old by composer

remote: #!/usr/bin/env php
remote: Some settings on your machine may cause stability issues with Composer.
remote: If you encounter issues, try to change the following:
remote:
remote: Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended.
remote: Composer works with 5.3.2+ for most people, but there might be edge case issues.

So I changed the paths to use the latest present on the system

[domain.rhcloud.com action_hooks]\> php --version  
PHP 5.4.16 (cli) (built: Dec  6 2013 01:17:01)  
[domain.rhcloud.com 5316aa83e0b8cdb61b00023a]\> which php  
/opt/rh/php54/root/usr/bin/php

The script in my .openshift/action_hooks/deploy is

#!/bin/bash
# Run composer install

cd app-root/runtime/repo/
export COMPOSER_HOME="$OPENSHIFT_DATA_DIR/.composer"
if [ ! -f "$OPENSHIFT_DATA_DIR/composer.phar" ]; then
    curl -s https://getcomposer.org/installer | /opt/rh/php54/root/usr/bin/php -- --install-dir=$OPENSHIFT_DATA_DIR
else
    /opt/rh/php54/root/usr/bin/php $OPENSHIFT_DATA_DIR/composer.phar self-update
fi

( unset GIT_DIR ; cd $OPENSHIFT_REPO_DIR ; /opt/rh/php54/root/usr/bin/php $OPENSHIFT_DATA_DIR/composer.phar install )

As the blog post suggests - create an empty hot_deploy file in the markers subdirectory to further speed things up by saying that the servers should not be restarted during a push -

touch .openshift/markers/hot_deploy
git add .openshift/markers/hot_deploy
git add .openshift/action_hooks/deploy
git commit -m "Speeding up composer installs across pushes"
git push origin master

And watch your git pushes be fast even when using composer.

For reference, OpenShift comes with built-in support for Composer. Adding the use_composer marker file, simply an empty file named use_composer, in your OpenShift project's .openshift/markers directory will automatically enable Composer install/update on deployment.

More specifically, each time you git push to your OpenShift git repo...

When in 'production' mode (default):

echo -n "Checking composer.json for Composer dependency... "
if [ -f ${OPENSHIFT_REPO_DIR}composer.json ]; then
    echo
    composer install --no-interaction --no-ansi --no-scripts --optimize-autoloader --working-dir=${OPENSHIFT_REPO_DIR} || \
    echo -e "\nSkipping Composer errors..\n\n  Please, fix the errors either locally or in development mode.\n"
    if [ ! -f ${OPENSHIFT_REPO_DIR}composer.lock ]; then
        echo -e $composer_lock_msg
    fi
else
    echo "File not found."
fi

When in 'development' mode:

if [ -f ${OPENSHIFT_REPO_DIR}composer.lock ]; then
    echo "Ignoring composer.lock file (development mode)"
fi
echo -n "Checking composer.json for Composer dependency... "
if [ -f ${OPENSHIFT_REPO_DIR}composer.json ]; then
    echo
    composer update --no-interaction --no-ansi --no-scripts --optimize-autoloader --working-dir=${OPENSHIFT_REPO_DIR}
    echo -e $composer_lock_msg
else
    echo "File not found."
fi

Check out the code beginning at line #142 of the OpenShift PHP Cartridge.

Check out the Developer Portal article on enabling PHP 'development' mode for more details.

Check out the Laravel 5 QuickStart for example-use or for an easy way to get started.

I do not have enough points to comment on wormhit's answer, so I will append it here:

The zend/php-*/etc/php.ini file needed an update for OpenShift to work with the latest version of composer.phar as described here:

extension=phar.so
extension=ctype.so

Adding these extensions to it fixes PHP's complaints about composer.phar


The next fix required using relative pathing:

php composer.phar install

INSTEAD of absolute pathing:

/usr/bin/php composer.phar install

to allow the extensions to load.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top