1
votes

I've deployed my Symfony 2.1 application on openshift and it doesn't work.

Calling app.php server return 200 OK and a white page (in my local server work well).

Log:

=> php-5.3/logs/error_log-20130306-000000-EST <== [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 3. require_once() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/app/bootstrap.php.cache:4 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 4. require() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/app/autoload.php:5 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 5. ComposerAutoloaderInit12cecca862685bdd480babbdd1b1ec7a::getLoader() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/vendor/autoload.php:7 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP Fatal error: require(): Failed opening required '/var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/vendor/kriswallsmith/assetic/src/functions.php' (include_path='.:/var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo//libs/:/var/lib/openshift/5e487f6c4a484700999d9213755b64eb/php-5.3/phplib/pear/pear/php/:/usr/share/pear/') in /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/vendor/composer/autoload_real.php on line 42 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP Stack trace: [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 1. {main}() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/web/app.php:0 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 2. require_once() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/web/app.php:7 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 3. require_once() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/app/bootstrap.php.cache:4 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 4. require() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/app/autoload.php:5 [Tue Mar 05 19:16:00 2013] [error] [client 127.5.146.1] PHP 5. ComposerAutoloaderInit12cecca862685bdd480babbdd1b1ec7a::getLoader() /var/lib/openshift/5e487f6c4a484700999d9213755b64eb/app-root/runtime/repo/php/vendor/autoload.php:7

Any idea or suggestion?

3

3 Answers

1
votes

Seems like you're missing some of the files in your gear repository. Did you add-commit-push all of your files?

You can get list of the deployed *.php files by running:

ssh <INTO-YOUR-GEAR> 'cd ~/app-root/runtime/repo/php && find ./ -name \*.php'

(obviously you need to substitute <INTO-YOUR-GEAR> with your SSH string)

1
votes

You have not "warm-up" your cache since the bootstrap.php.cache file isn't there, it seems like you just push your repo and do nothing yet on the openshift side.

You'll need to configure your symphony app first, that is download all the dependencies, fill in all the database settings, mailer settings and all other stuff.

ssh into your gear using this command rhc ssh -a <yourappname>, cd into your symfony root directory, and run php composer.phar install this will start everything that is needed to deploy your app completely

1
votes

The best way to deploy a Symfony app to Openshift is:

  1. Be sure you have a Symfony2 app working well in localhost (dev and prod)
  2. Your proyect have to be using git.
  3. Your .gitignore file is ignoring vendors, cache, bootstrap, logs, composer etc.
  4. You have committed every pending change.
  5. You need an openshift gear using PHP 5.4 and a cartridge of MySql 5.5
  6. You need rhc to be installed and configured
  7. Config your gear to public a branch called release: rhc app-configure --deployment-branch release -a <app-name>
  8. Create a new php file that will give MySQL access to your app:

<?php
# app/config/params.php
if (getEnv("OPENSHIFT_APP_NAME")!='') {
    $container->setParameter('database_host', getEnv("OPENSHIFT_MYSQL_DB_HOST"));
    $container->setParameter('database_port', getEnv("OPENSHIFT_MYSQL_DB_PORT"));
    $container->setParameter('database_name', getEnv("OPENSHIFT_APP_NAME"));
    $container->setParameter('database_user', getEnv("OPENSHIFT_MYSQL_DB_USERNAME"));
    $container->setParameter('database_password', getEnv("OPENSHIFT_MYSQL_DB_PASSWORD"));
}?>

This will tell the app that if is openshift environment it needs to load different user an database

  1. Import this file (params.php) to your app/config/config.yml file:

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: params.php }
...
  1. Commit your changes.
  2. Create a new branch that will push your changes to Openshift: git checkout -b release
  3. Add your remote repository from openshift: git remote add openshift -f <youropenshiftrepository.git>
  4. Merge the differences between both repositories git merge openshift/master -s recursive -X ours
  5. Create a 'deploy' file (the one executed in openshift after you push your app) in your new folder "/.openshift/action-hooks" (Created when you added your openshift repository):

#!/bin/bash

# Symfony deploy
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

php $OPENSHIFT_REPO_DIR/app/console cache:clear --env=dev

chmod -R 0777 $OPENSHIFT_REPO_DIR/app/cache
chmod -R 0777 $OPENSHIFT_REPO_DIR/app/logs

rm -r $OPENSHIFT_REPO_DIR/php
ln -s $OPENSHIFT_REPO_DIR/web $OPENSHIFT_REPO_DIR/php

rm -r $OPENSHIFT_REPO_DIR/php
ln -s $OPENSHIFT_REPO_DIR/web $OPENSHIFT_REPO_DIR/php

php $OPENSHIFT_REPO_DIR/app/console doctrine:schema:update --force
  1. Give this file permissions to be executed. In windows: git update-index --chmod=+x .openshift/action_hooks/deploy In Linux and Mac: chmod +x .openshift/action_hooks/deploy
  2. Add your new file to the git project and make the commit.
  3. Push to openshift: git push openshift HEAD
  4. Your console will show you every step it is working on.
  5. Come back to your master branch. git checkout master
  6. Then you can keep working normaly on your project, commit your changes and move to release branch to deploy your new changes: git checkout release git merge master git push openshift HEAD git checkout master

And that's how I work with Symfony and Openshift. (These instructions are a mix from many ways I read and I imporved with some changes. It works very well for every app I've made.