Search code examples
phpmysqllaravel-4ibm-cloud

Laravel Database Migrations with IBM Bluemix


I'm trying to put my app to a production server using IBM Bluemix. Actually I'm on free tier and just testing Bluemix out. My app is built on Laravel 4.2.

I already created a CLEARDB MYSQL DATABASE and I edited my database.php like this

First I added the following lines to the top

<?php

$services = json_decode(getenv('VCAP_SERVICES'), true);
$sqlCreds = $services['cleardb'][0]['credentials'];

return array(...

Then I adjusted the MYSQL Configurations

'mysql' => array(
                'driver'    => 'mysql',
                'host'      => $sqlCreds['hostname'],
                'database'  => $sqlCreds['name'],
                'username'  => $sqlCreds['username'],
                'password'  => $sqlCreds['password'],
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
        ),

I also edited the composer.json file to migrate the database while pushing the project.

"scripts": {
        "post-install-cmd": [
            "php htdocs/artisan clear-compiled",
            "php htdocs/artisan optimize",
            "php htdocs/artisan migrate --force"
        ],
        "post-update-cmd": [
            "php htdocs/artisan clear-compiled",
            "php htdocs/artisan optimize"
        ],
        "post-create-project-cmd": [
            "php htdocs/artisan key:generate"
        ]
    },

However when I push the project, I get the following error;

 [PDOException]         
  could not find driver  
migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]
Script php htdocs/artisan migrate --force handling the post-install-cmd event returned with an error
  [RuntimeException]                                                                                                  
  Error Output:                                                                                                       
    [PDOException]                                                                                                    
    could not find driver                                                                                             
  migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]  
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [--ignore-platform-reqs] [packages1] ... [packagesN]
-----> Composer command failed
Traceback (most recent call last):
  File "/tmp/buildpacks/php-buildpack/scripts/compile.py", line 51, in <module>
    .from_build_pack('lib/additional_commands')
  File "/tmp/buildpacks/php-buildpack/lib/build_pack_utils/builder.py", line 189, in extensions
    process_extension(path, ctx, 'compile', process, args=[self])
  File "/tmp/buildpacks/php-buildpack/lib/build_pack_utils/utils.py", line 69, in process_extension
    success(getattr(extn, to_call)(*args))
  File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 420, in compile
    return composer.compile(install)
  File "/tmp/buildpacks/php-buildpack/lib/extension_helpers.py", line 154, in compile
    self._compile(install)
  File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 173, in _compile
    self.run()
  File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 305, in run
    *self._ctx['COMPOSER_INSTALL_OPTIONS'])
  File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 350, in run
    shell=True)
  File "/tmp/buildpacks/php-buildpack/lib/build_pack_utils/runner.py", line 109, in stream_output
    raise CalledProcessError(retcode, cmd)
build_pack_utils.runner.CalledProcessError: Command '<open file '<fdopen>', mode 'w' at 0x7f738ce24810>' returned non-zero exit status 1
Staging failed: Buildpack compilation step failed

FAILED
BuildpackCompileFailed

I'm pretty new to Bluemix and couldn't figure out the problem yet. I belive in stackoverflow community. Any help will be appreciated :)


Solution

  • The error indicates the PDO driver is missing. You may need to enable the PHP extension by creating the file .bp-config/options.json in the root of your app and including the extension in the options.json file (and any others required by your app):

    { "PHP_EXTENSIONS": ["pdo", "pdo_mysql"] }

    CF doc: http://docs.cloudfoundry.org/buildpacks/php/gsg-php-config.html#php-extensions