简体   繁体   中英

Cant Deploy Symfony app to Heroku

I keep trying to deploy my symfony2 app to Heroku and i keep running into these errors. I have been working on this all week. Someone please tell me what I'm doing wrong. I will include some important files. Let me know if you need me to include anything else. Thanks!

These 4 errors in particular:

[Doctrine\\DBAL\\Exception\\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory

[Doctrine\\DBAL\\Driver\\PDOException] SQLSTATE[HY000] [2002] No such file or directory

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

Script Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets handling the post-install-cmd event terminated with an exception

This is my composer.json file:

{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-0": { "": "src/", "SymfonyStandard": "app/" }
},
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "~2.5",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
            "doctrine/doctrine-fixtures-bundle": "2.2.*",
            "doctrine/doctrine-migrations-bundle": "dev-master",
            "doctrine/migrations": "dev-master",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~3.0",
    "sensio/framework-extra-bundle": "~3.0",
    "incenteev/composer-parameter-handler": "~2.0",
            "ircmaxell/password-compat": "~1.0.3",
    "friendsofsymfony/user-bundle": "~1.3"
},
"require-dev": {
    "sensio/generator-bundle": "~2.3",
            "phpunit/phpunit": "3.7.*"
},
"scripts": {
    "post-root-package-install": [
        "SymfonyStandard\\Composer::hookRootPackageInstall"
    ],
    "post-install-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
    ],
    "post-update-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
    ]
},
"config": {
    "bin-dir": "bin"
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    },
    "branch-alias": {
        "dev-master": "2.5-dev"
    }
}
}

This is my appKernel.php file

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{

public function __construct($environment, $debug){
date_default_timezone_set( 'America/Chicago' );
parent::__construct($environment, $debug);
}

public function registerBundles()
{
    $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
                    new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
                    new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new Foodoo\Bundle\FoodooBundle\FoodooFoodooBundle(),
        new Blogger\BlogBundle\BloggerBlogBundle(),
                    new FOS\UserBundle\FOSUserBundle(),
                    new Blogger\UserBundle\BloggerUserBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
    $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}

This is my config.yml file:

imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: @BloggerBlogBundle/Resources/config/config.yml }

framework:
#esi:             ~
translator:      { fallback: "%locale%" }
secret:          "%secret%"
router:
    resource: "%kernel.root_dir%/config/routing.yml"
    strict_requirements: ~
form:            ~
csrf_protection: ~
validation:      { enable_annotations: true }
templating:
    engines: ['twig']
    #assets_version: SomeVersionScheme
default_locale:  "%locale%"
trusted_hosts:   ~
trusted_proxies: ~
session:
    # handler_id set to null will use default session handler from php.ini
    handler_id:  ~
fragments:       ~
http_method_override: true

# Twig Configuration
twig:
debug:            "%kernel.debug%"
strict_variables: "%kernel.debug%"

# Assetic Configuration
assetic:
debug:          "%kernel.debug%"
use_controller: false
bundles:        [BloggerBlogBundle]
#java: /usr/bin/java
filters:
    cssrewrite: ~
    #closure:
    #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
    #yui_css:
    #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

# Doctrine Configuration
doctrine:
dbal:
    driver:   "%database_driver%"
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database_name%"
    user:     "%database_user%"
    password: "%database_password%"
    charset:  UTF8
    # if using pdo_sqlite as your database driver:
    #   1. add the path in parameters.yml
    #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
    #   2. Uncomment database_path in parameters.yml.dist
    #   3. Uncomment next line:
    #     path:     "%database_path%"

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host:      "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
encryption: ssl
# spool:     { type: memory }

# configuration for fos user bundle
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: demo_fos_login
user_class: Blogger\UserBundle\Entity\User

And this is the error log from heroku:

-----> PHP app detected
-----> Resolved composer.lock requirement for PHP to version 5.6.4.
-----> Installing system packages...
   - PHP 5.6.4
   - Apache 2.4.10
   - Nginx 1.6.0
-----> Installing PHP extensions...
   - zend-opcache (automatic; bundled)
-----> Installing dependencies...
   Composer version 1.0.0-alpha9 2014-12-07 17:15:20
   Loading composer repositories with package information
   Installing dependencies from lock file
     - Installing doctrine/lexer (v1.0)
       Downloading: connection...    Downloading: 0%               Downloading: 80%      Downloading: 100%

     - Installing doctrine/annotations (v1.2.3)
       Downloading: connection...    Downloading: 0%               Downloading: 10%    Downloading: 20%    Downloading: 30%    Downloading: 40%    Downloading: 50%    Downloading: 60%    Downloading: 70%    Downloading: 80%    Downloading: 90%    Downloading: 100%

     - Installing twig/twig (v1.16.3)
       Downloading: connection...    Downloading: 0%               Downloading: 5%    Downloading: 10%    Downloading: 15%    Downloading: 20%    Downloading: 25%    Downloading: 30%    Downloading: 35%    Downloading: 40%    Downloading: 45%    Downloading: 50%    Downloading: 55%    Downloading: 60%    Downloading: 65%    Downloading: 70%    Downloading: 75%    Downloading: 80%    Downloading: 85%    Downloading: 90%    Downloading: 95%    Downloading: 100%    Downloading: 100%

     - Installing psr/log (1.0.0)
       Downloading: connection...    Downloading: 0%               Downloading: 15%    Downloading: 30%    Downloading: 45%    Downloading: 60%    Downloading: 75%    Downloading: 100%

     - Installing doctrine/inflector (v1.0.1)
       Downloading: connection...    Downloading: 0%               Downloading: 60%    Downloading: 100%

     - Installing doctrine/collections (v1.2)
       Downloading: connection...    Downloading: 0%               Downloading: 35%    Downloading: 70%    Downloading: 100%

     - Installing doctrine/cache (v1.3.1)
       Downloading: connection...    Downloading: 0%               Downloading: 20%    Downloading: 25%    Downloading: 40%    Downloading: 45%    Downloading: 65%    Downloading: 85%    Downloading: 100%

     - Installing doctrine/common (v2.4.2)
       Downloading: connection...    Downloading: 0%               Downloading: 5%    Downloading: 10%    Downloading: 15%    Downloading: 20%    Downloading: 25%    Downloading: 30%    Downloading: 35%    Downloading: 40%    Downloading: 45%    Downloading: 50%    Downloading: 55%    Downloading: 60%    Downloading: 65%    Downloading: 70%    Downloading: 75%    Downloading: 80%    Downloading: 85%    Downloading: 90%    Downloading: 95%    Downloading: 100%

     - Installing symfony/symfony (v2.6.1)
       Downloading: connection...    Downloading: 0%               Downloading: 5%    Downloading: 10%    Downloading: 15%    Downloading: 20%    Downloading: 25%    Downloading: 30%    Downloading: 35%    Downloading: 40%    Downloading: 45%    Downloading: 50%    Downloading: 55%    Downloading: 60%    Downloading: 65%    Downloading: 70%    Downloading: 75%    Downloading: 80%    Downloading: 85%    Downloading: 90%    Downloading: 95%    Downloading: 100%    Downloading: 100%

     - Installing doctrine/doctrine-cache-bundle (v1.0.1)
       Downloading: connection...    Failed to download doctrine/doctrine-cache-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/doctrine-cache-bundle (v1.0.1)
       Cloning e4b6f810aa047f9cbfe41c3d6a3d7e83d7477a9d

     - Installing jdorn/sql-formatter (v1.2.17)
       Downloading: connection...    Failed to download jdorn/sql-formatter from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing jdorn/sql-formatter (v1.2.17)
       Cloning 64990d96e0959dff8e059dfcdc1af130728d92bc

     - Installing doctrine/dbal (v2.5.0)
       Downloading: connection...    Failed to download doctrine/dbal from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/dbal (v2.5.0)
       Cloning 71140662c0a954602e81271667b6e03d9f53ea34

       Skipped installation of bin bin/doctrine-dbal for package doctrine/dbal: name conflicts with an existing file
     - Installing doctrine/doctrine-bundle (v1.3.0)
       Downloading: connection...    Failed to download doctrine/doctrine-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/doctrine-bundle (v1.3.0)
       Cloning 3beb3a780485ab01f86941f4892cd23ef8c39c6b

     - Installing doctrine/data-fixtures (v1.0.0)
       Downloading: connection...    Failed to download doctrine/data-fixtures from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/data-fixtures (v1.0.0)
       Cloning b4a135c7db56ecc4602b54a2184368f440cac33e

     - Installing doctrine/doctrine-fixtures-bundle (v2.2.0)
       Downloading: connection...    Failed to download doctrine/doctrine-fixtures-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/doctrine-fixtures-bundle (v2.2.0)
       Cloning c811f96f0cf83b997e3a3ed037cac729bbe3e803

     - Installing doctrine/migrations (dev-master 96f838b)
       Downloading: connection...    Failed to download doctrine/migrations from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/migrations (dev-master 96f838b)
       Cloning 96f838b4fa93693d19196c8e24ed5f1c3972ba87

     - Installing doctrine/doctrine-migrations-bundle (dev-master 81575a4)
       Downloading: connection...    Failed to download doctrine/doctrine-migrations-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/doctrine-migrations-bundle (dev-master 81575a4)
       Cloning 81575a4316951125ce408c70f30547c77d98f78a

     - Installing doctrine/orm (v2.4.7)
       Downloading: connection...    Failed to download doctrine/orm from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing doctrine/orm (v2.4.7)
       Cloning 2bc4ff3cab2ae297bcd05f2e619d42e6a7ca9e68

       Skipped installation of bin bin/doctrine for package doctrine/orm: name conflicts with an existing file
       Skipped installation of bin bin/doctrine.php for package doctrine/orm: name conflicts with an existing file
     - Installing friendsofsymfony/user-bundle (v1.3.5)
       Downloading: connection...    Failed to download friendsofsymfony/user-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing friendsofsymfony/user-bundle (v1.3.5)
       Cloning d66890ad3489e18be153502c5ccc3f2bf5cce442

     - Installing incenteev/composer-parameter-handler (v2.1.0)
       Downloading: connection...    Failed to download incenteev/composer-parameter-handler from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing incenteev/composer-parameter-handler (v2.1.0)
       Cloning 143272a0a09c62616a3c8011fc165a10c6b35241

     - Installing ircmaxell/password-compat (v1.0.4)
       Downloading: connection...    Failed to download ircmaxell/password-compat from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing ircmaxell/password-compat (v1.0.4)
       Cloning 5c5cde8822a69545767f7c7f3058cb15ff84614c

     - Installing sensiolabs/security-checker (v2.0.0)
       Downloading: connection...    Failed to download sensiolabs/security-checker from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing sensiolabs/security-checker (v2.0.0)
       Cloning 5b4eb4743ebe68276c911c84101ecdf4a9ae76ee

       Skipped installation of bin security-checker for package sensiolabs/security-checker: name conflicts with an existing file
     - Installing sensio/distribution-bundle (v3.0.14)
       Downloading: connection...    Failed to download sensio/distribution-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing sensio/distribution-bundle (v3.0.14)
       Cloning dc20d5ab3251587b047859ca2fc06c1b88a38d00

     - Installing sensio/framework-extra-bundle (v3.0.4)
       Downloading: connection...    Failed to download sensio/framework-extra-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing sensio/framework-extra-bundle (v3.0.4)
       Cloning b3bc3e67c8b6b68b18d727012183520d35ee762a

     - Installing kriswallsmith/assetic (v1.2.1)
       Downloading: connection...    Failed to download kriswallsmith/assetic from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing kriswallsmith/assetic (v1.2.1)
       Cloning b20efe38845d20458702f97f3ff625d80805897b

     - Installing symfony/assetic-bundle (v2.5.0)
       Downloading: connection...    Failed to download symfony/assetic-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing symfony/assetic-bundle (v2.5.0)
       Cloning 90ea7fb66d6d5245fd4afc16e4c8070214254fec

     - Installing monolog/monolog (1.12.0)
       Downloading: connection...    Failed to download monolog/monolog from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing monolog/monolog (1.12.0)
       Cloning 1fbe8c2641f2b163addf49cc5e18f144bec6b19f

     - Installing symfony/monolog-bundle (v2.7.0)
       Downloading: connection...    Failed to download symfony/monolog-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing symfony/monolog-bundle (v2.7.0)
       Cloning e8f71c91a3784f3fa1a75fb1f7f4d4826c5f2773

     - Installing swiftmailer/swiftmailer (v5.3.1)
       Downloading: connection...    Failed to download swiftmailer/swiftmailer from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing swiftmailer/swiftmailer (v5.3.1)
       Cloning c5f963e7f9d6f6438fda4f22d5cc2db296ec621a

     - Installing symfony/swiftmailer-bundle (v2.3.8)
       Downloading: connection...    Failed to download symfony/swiftmailer-bundle from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing symfony/swiftmailer-bundle (v2.3.8)
       Cloning 970b13d01871207e81d17b17ddda025e7e21e797

     - Installing twig/extensions (v1.2.0)
       Downloading: connection...    Failed to download twig/extensions from dist: Could not authenticate against github.com
       Now trying to download from source
     - Installing twig/extensions (v1.2.0)
       Cloning 8cf4b9fe04077bd54fc73f4fde83347040c3b8cd

   Generating optimized autoload files
   Updating the "app/config/parameters.yml" file
   Clearing the cache for the prod environment with debug false



     [Doctrine\DBAL\Exception\ConnectionException]                                     
     An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory  






     [Doctrine\DBAL\Driver\PDOException]               
     SQLSTATE[HY000] [2002] No such file or directory  






     [PDOException]                                    
     SQLSTATE[HY000] [2002] No such file or directory  

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets   
handling  the post-install-cmd event terminated with an exception       

[RuntimeException]                                                            
An error occurred when executing the "'assets:install '\''web'\'''" command.  

!     Push rejected, failed to compile PHP app

似乎您没有将cleardb插件添加到您的heroku实例中

 heroku addons:add cleardb:ignite

Here is what i did to fix this issue:

My config_prod.yml file imported my config.yml file which imported the parameters.yml file which included my database configuration info for my local server.

When you upload it to the live server (heroku, or any other server) you need to have that parameters.yml file configured for the new database.

Option 1 (easy fix): You can either change your database config in your parameters.yml file to match the cleardb:ignite database for heroku. but then it won't work on your local server unless you change the database config info back.

Option 2: You can create another parameters.yml file and name it something different. ie production_parmaeters.yml , and import that file in your config_prod.yml file. and make sure your c onfig_dev.yml file includes your original parameters.yml file which has your local development database config in it.

Then delete the

- { resource: parameters.yml } 

in your main config.yml file.

Thanks guys for your help!

If you just search for the "SQLSTATE[HY000] [2002] No such file or directory" message on Google, you'll quickly find an explanation: a connection to MySQL through a Unix domain socket failed because that socket, eg /var/sock/mysql.sock , does not exist (MySQL does that if you try to connect to localhost , while it uses a TCP/IP socket if you connect to 127.0.0.1 ).

Your problem then, most likely, is that you have database credentials set up for the prod environment somewhere, but these credentials are invalid, as they try to connect to a localhost MySQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM