0
votes

System: Ubuntu 18.10 PHP 7.2 Homestead - virtualbox

I get the following error when I try to execute any php artisan commands outside of the vm.

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = on
c_db and table_name = permissions and table_type = 'BASE TABLE')

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

I have followed recommendations listed in other questions with similar issues. Changing the DB_HOST from localhost from/to 127.0.0.1 will fix the issue but create other problems. I am unable to run phpunit tests and the site will not load for me.

Previously I was getting a permissions table not found error and corrected for it by adding a check for the table in my AuthServiceProvider.

public function boot(GateContract $gate)
{
    $this->registerPolicies();

    if (Schema::hasTable('permissions')) {
        foreach($this->getPermissions() as $permission) {
            $gate->define($permission->name, function($user) use ($permission){
                return $user->hasRole($permission->roles);
            });
        }
    }
}

protected function getPermissions()
{
    return Permission::with('roles')->get();
}

I still have to comment out the call in order to run composer dump-autoload from outside of the vm. It seems like there is an issue with the setup that I am using for role-based permissions. I followed a tutorial that used an older version of laravel and it seemed to work until I ran into these issues.

1

1 Answers

0
votes

I was fighting this for over a day but it seems the problem was a lack of sleep. I am including the solution in case anyone else runs into a similar issue. When I changed the DB_HOST to 127.0.0.1 it resolved my other issues but then my site could no longer access the database.

[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

[PDOException] SQLSTATE[HY000] [2002] Connection refused

This was due to the DB_PORT being set to 33060 still. I updated my .env to the following and it seems to have corrected all of the issues:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306