Tuesday, March 21, 2017

Connect to staging database from a local environment - Laravel 5

Goal

Locally on my Mac OS, I'm trying to connect to my staging database that are running and hosted on my Ubuntu VM.


Steps

In my config/database.php

'connections' => [

    'mysql'       => [
    'driver'      => 'mysql',
    'host'        => env('DB_HOST'),
    'database'    => env('DB_DATABASE'),
    'username'    => env('DB_USERNAME'),
    'password'    => env('DB_PASSWORD'),
    'unix_socket' => env('UNIX_SOCKET'), <---- Need it here 
    'charset'     => 'utf8',
    'collation'   => 'utf8_unicode_ci',
    'prefix'      => '',
    'strict'      => false,
    ]

],

In my .env I have

DB_HOST=45.55.88.88
DB_DATABASE=staging
DB_USERNAME=john
DB_PASSWORD=***
UNIX_SOCKET=/var/run/mysqld/mysqld.sock  <---- I'm not sure what to put here 

I am not sure what to PUT as my UNIX_SOCKET since database.php need it.

I kept getting

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

I believe that because my path to the UNIX_SOCKET is wrong.


Questions

How would one go about and configure something like this ?

How would one go about and debug this further ?


I'm opening to any suggestions at this moment.

Any hints / suggestions / helps on this be will be much appreciated !


Update

Base on @dparoli's answer. I update my database configuration.

'connections' => [

    'mysql'       => [

        'driver'      => 'mysql',
        'host'        => env('DB_HOST'),
        'database'    => env('DB_DATABASE'),
        'username'    => env('DB_USERNAME'),
        'password'    => env('DB_PASSWORD'),
         // 'unix_socket' => env('UNIX_SOCKET'),
        'port'        => env('DB_PORT', '3306'),
        'charset'     => 'utf8',
        'collation'   => 'utf8_unicode_ci',
        'prefix'      => '',
        'strict'      => false,
    ]

],

I commented out UNIX_SOCKET, and add this line 'port'=> env('DB_PORT', '3306'), now I got

PDOException in Connector.php line 49: SQLSTATE[HY000] [2002] Operation timed out



via ihue

Advertisement