Home » Php » Laravel 5.1. cannnot run artisan commands

Laravel 5.1. cannnot run artisan commands

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am using Laravel 5.1 and I cannot run any artisan commands.

I uploaded my project to our live server with PHP5.5.22 CLI version.

everytime I run artisan commands I am getting this error
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (146)

I changed the configuration on my .env and config/database.php files to point to our MySQL server.

.env file

DB_CONNECTION=mysql
DB_HOST=****.sddb0040291787.*****
DB_PORT=3306
DB_DATABASE=sddb0040291787
DB_USERNAME=sddbMTcyNjEy
DB_PASSWORD=**********

config/database.php

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '****.sddb0040291787.*****'),
        'database'  => env('DB_DATABASE', 'sddb0040291787'),
        'username'  => env('DB_USERNAME', 'sddbMTcyNjEy'),
        'password'  => env('DB_PASSWORD', '**********'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

even php artisan config:cache command doesn’t work and returns same error.

Appreciate any help. Thanks guys!

Answers:

This may give you some ideas, https://stackoverflow.com/a/37005818/8825233

Check if MySQL server is running.

Questions:
Answers:

Try adding –env=production to your artisan command

Please ensure that it is the right DB information which is stored in the env-file. By default it is localhost which is stored in the env.

Or you could simply delete the env() function from your config if you dont want to use enviroment variables. Like :

'mysql' => [
        'driver'    => 'mysql',
        'host'      => '****.sddb0040291787.*****',
        'database'  => 'sddb0040291787',
        'username'  => 'sddbMTcyNjEy',
        'password'  => '**********',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],