Junior
Junior

Reputation: 11990

How to connect to MySQL database on port 3308 using laravel framework 5.1?

I am trying to use laravel for the first time. I opned the database.php file located in the config directory and then update the mysql config.

but every time I try to do this command php artisan migrate:install

I get this [PDOException] SQLSTATE[HY000] [2002] No connection could be made because the target machi ne actively refused it.

I have to let laravel to connect to a different port somehow.

I have tried the following and none worked.

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '10.15.1.5'),
        'port'      => '3308',
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

and this

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '10.15.1.5:3308'),
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

and this

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '10.15.1.5'),
        'port'      => env('DB_PORT', '3308'),
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

finally, I tried this

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => '10.15.1.5:3308',
        'database'  => env('DB_DATABASE', 'mydb_dev'),
        'username'  => env('DB_USERNAME', 'user'),
        'password'  => env('DB_PASSWORD', 'pass'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

this gives me a different error

Access denied for user 'homestead'@'10.xxxxxx' (using password: YES)

I am not sure where is the user homestead is coming from.

How can I tell laravel to connect to mysql on port 3308?

Upvotes: 3

Views: 16263

Answers (2)

CenterOrbit
CenterOrbit

Reputation: 6861

I know you figured it out, but of all the attempts you provided, the answer you gave wasn't clear. For those looking in the future, here is what you need:

(This is assuming Laravel 5.1 using a Postgres DB, but should work with alternate versions of Laravel, and different DBs... also, don't mind the alternate/different config settings that my database.php has as opposed to yours, these were for advanced configurations.)

Add a 'port' section to your config/database.php, that looks like follows:

'pgsql' => [
    'read' => [
        'host' => env('DB_READ', 'localhost')
    ],
    'write' => [
        'host' => env('DB_WRITE', 'localhost')
    ],
    'port'     => env('DB_PORT', '5432'),
    'driver'   => 'pgsql',
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset'  => 'utf8',
    'prefix'   => '',
    'schema'   => env('DB_SCHEMA', 'public'),
    'options'  => [
        PDO::ATTR_PERSISTENT => env('DB_PERSISTENT', false)
    ]
]

Then in your .env you can override the port setting as follows:

DB_PORT=32769

Upvotes: 3

Junior
Junior

Reputation: 11990

I figured out the issue. the file .env needs to be updated with the correct information

Upvotes: 1

Related Questions