2017-05-19 30 views
0

我已经尝试了几乎所有可用于运行laravel应用程序的应用程序,但它仍然无法正常工作,并且出现错误,当我尝试拨打php artisan migrateshippable.yml看起来是这样的:Laravel应用程序不能在Shippable上运行 - SQLSTATE [HY000] [2002]没有这样的文件或目录

language: php 

php: 
    - 7.0 

services: 
    - mysql 

addons: 
    hosts: 
    - example.org 

before_script: 
    - sudo apt-get update 
    # - php -i 
    - composer self-update -n 
    - composer install #downloads vendor 
    - composer install --prefer-dist -n # no idea 
    - mysql -e "CREATE USER [email protected] identified by 'password';GRANT ALL ON *.* TO [email protected] IDENTIFIED BY 'password'; FLUSH PRIVILEGES;" #creating shippable user 
    - mysql -e "create database if not exists sample;" # create database 
    - mysql -e "show databases;" # lists databases 
    # - mysql -e "show variables like '%sock%';" 
    - cp .env.shippable .env # creates .env file 
    - php artisan key:generate # generates secure key 
    - php artisan config:cache # caches config (without it laravel throws error that secure key is not there) 
    - cp ci/database.php resources/config/database.php 
    - php artisan --verbose migrate --env=testing --force #creates database table 
    - php artisan db:seed # seeds database with seeders' 
script: 
    - phpunit --log-junit shippable/testresults/junit.xml --coverage-xml shippable/codecoverage 

ci/database.php看起来是这样的:

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | PDO Fetch Style 
    |-------------------------------------------------------------------------- 
    | 
    | By default, database results will be returned as instances of the PHP 
    | stdClass object; however, you may desire to retrieve records in an 
    | array format for simplicity. Here you can tweak the fetch style. 
    | 
    */ 

    'fetch' => PDO::FETCH_CLASS, 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Database Connection Name 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may specify which of the database connections below you wish 
    | to use as your default connection for all database work. Of course 
    | you may use many connections at once using the Database library. 
    | 
    */ 

    'default' => env('DB_CONNECTION', 'mysql'), 

    /* 
    |-------------------------------------------------------------------------- 
    | Database Connections 
    |-------------------------------------------------------------------------- 
    | 
    | Here are each of the database connections setup for your application. 
    | Of course, examples of configuring each database platform that is 
    | supported by Laravel is shown below to make development simple. 
    | 
    | 
    | All database work in Laravel is done through the PHP PDO facilities 
    | so make sure you have the driver for your particular database of 
    | choice installed on your machine before you begin development. 
    | 
    */ 

    'connections' => [ 

     'sqlite' => [ 
      'driver' => 'sqlite', 
      'database' => storage_path('database.sqlite'), 
      'prefix' => '', 
     ], 

     'mysql' => [ 
      'write' => [ 
       'host' => env('DB_HOST', '127.0.0.1') 
      ], 
      'read' => [ 
       'host' => env('DB_HOST_SLAVE', '127.0.0.1') 
      ], 
      'dump_command_timeout'   => 60 * 5, // 5 minute timeout 
      'dump_using_single_transaction' => true, 
      'driver'      => 'mysql', 
      'unix_socket'      => '/var/run/mysqld/mysqld.sock', 
      'database'      => env('DB_DATABASE', 'sample'), 
      'username'      => env('DB_USERNAME', 'shippable'), 
      'password'      => env('DB_PASSWORD', 'password'), 
      'charset'      => 'utf8', 
      'collation'      => 'utf8_unicode_ci', 
      'prefix'      => '', 
      'strict'      => false, 
     ], 

     'pgsql' => [ 
      'driver' => 'pgsql', 
      'host'  => env('DB_HOST', 'localhost'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'charset' => 'utf8', 
      'prefix' => '', 
      'schema' => 'public', 
     ], 

     'sqlsrv' => [ 
      'driver' => 'sqlsrv', 
      'host'  => env('DB_HOST', 'localhost'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'charset' => 'utf8', 
      'prefix' => '', 
     ], 

    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | Migration Repository Table 
    |-------------------------------------------------------------------------- 
    | 
    | This table keeps track of all the migrations that have already run for 
    | your application. Using this information, we can determine which of 
    | the migrations on disk haven't actually been run in the database. 
    | 
    */ 

    'migrations' => 'migrations', 

    /* 
    |-------------------------------------------------------------------------- 
    | Redis Databases 
    |-------------------------------------------------------------------------- 
    | 
    | Redis is an open source, fast, and advanced key-value store that also 
    | provides a richer set of commands than a typical key-value systems 
    | such as APC or Memcached. Laravel makes it easy to dig right in. 
    | 
    */ 

    'redis' => [ 

     'cluster' => false, 

     'default' => [ 
      'host'  => env('REDIS_HOST', '127.0.0.1'), 
      'port'  => 6379, 
      'database' => 0, 
     ], 

    ], 

]; 

最后我.env.shippable,我复制到.env看起来是这样的:

APP_ENV=testing 
APP_DEBUG=true 
APP_KEY=key 

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=sample 
DB_USERNAME=shippable 
DB_PASSWORD=password 

CACHE_DRIVER=array 
SESSION_DRIVER=array 
QUEUE_DRIVER=sync 
MAIL_DRIVER=log 

当它达到了php artisan migrate我不断收到此错误步骤:

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


Exception trace: 
() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55 
PDO->__construct() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55 
Illuminate\Database\Connectors\Connector->createConnection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24 
Illuminate\Database\Connectors\MySqlConnector->connect() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11857 
Illuminate\Database\Connectors\ConnectionFactory->createReadPdo() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11852 
Illuminate\Database\Connectors\ConnectionFactory->createReadWriteConnection() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11838 
Illuminate\Database\Connectors\ConnectionFactory->make() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11747 
Illuminate\Database\DatabaseManager->makeConnection() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:11702 
Illuminate\Database\DatabaseManager->connection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:171 
Illuminate\Database\Migrations\DatabaseMigrationRepository->getConnection() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:139 
Illuminate\Database\Migrations\DatabaseMigrationRepository->repositoryExists() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:404 
Illuminate\Database\Migrations\Migrator->repositoryExists() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:103 
Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase() at /root/src/github.com/fashionvalet/warehouse/vendor/orchestra/kernel/src/Database/Console/Migrations/MigrateCommand.php:40 
Orchestra\Database\Console\Migrations\MigrateCommand->fire() at n/a:n/a 
call_user_func_array() at /root/src/github.com/fashionvalet/warehouse/bootstrap/cache/compiled.php:1257 
Illuminate\Container\Container->call() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Console/Command.php:169 
Illuminate\Console\Command->execute() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Command/Command.php:256 
Symfony\Component\Console\Command\Command->run() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Console/Command.php:155 
Illuminate\Console\Command->run() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:794 
Symfony\Component\Console\Application->doRunCommand() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:186 
Symfony\Component\Console\Application->doRun() at /root/src/github.com/fashionvalet/warehouse/vendor/symfony/console/Application.php:117 
Symfony\Component\Console\Application->run() at /root/src/github.com/fashionvalet/warehouse/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107 
Illuminate\Foundation\Console\Kernel->handle() at /root/src/github.com/fashionvalet/warehouse/artisan:35 

可别人谁以前做过这个,请帮助?在我的智慧结束。

+0

什么是mysql.sock文件路径? –

+0

这就是这个'/ var/run/mysqld/mysqld.sock'我通过查询数据库可查询数据库进行检查 –

+0

[PDOException SQLSTATE \ [HY000 \] \ [2002 \]没有这样的文件或目录](http:// stackoverflow.com/questions/20723803/pdoexception-sqlstatehy000-2002-no-such-file-or-directory) – SolidTerre

回答

0

也许尝试更换readwrite主机部分ci/database.php配置只有一个host如下所示。

'host' => env('DB_HOST', 'localhost'), 

尝试删除unix_socket以及。请记住,在运行测试时(使用phpunit),配置环境设置为testing(以防万一您有测试击中数据库)。

下面是我工作的shippable.yml。但是请注意,这是Laravel 4.2的,但我认为这种情况没有太大的区别。

language: php 

php: 
    - 5.6 

env: 
    - APP_ENV=testing 

services: 
    - mysql 

build: 
    ci: 
    - sudo apt-get update 
    - mkdir -p shippable/{testsresults,codecoverage} 
    - mysql -e "CREATE DATABASE test;" 
    - mysql -e "GRANT ALL ON test.* to [email protected] identified by 'password'; FLUSH PRIVILEGES;" 
    - echo "memory_limit = 256M" >> $HOME/.phpenv/versions/$(phpenv version-name)/etc/php.ini 
    - cp .env.example.php .env.testing.php 
    - composer self-update -n 
    - composer install 
    - php artisan migrate 
    - vendor/bin/phpunit --log-junit shippable/testresults/junit.xml --coverage-xml shippable/codecoverage 

希望这会有所帮助。

相关问题