Search code examples
phpmysqllaravelremote-mysql

Accessing remote mysql database laravel in server


PHP 7.2.10 Laravel 5.6.39

I have multiple remote mysql database and one mysql database in my server.

In my localhost, I am able to connect to all the databases, but in production / testing server, I am unable to connect to remote databases, showing error

Database [mysqlRemoteOne] not configured.", exception: "InvalidArgumentException

But in both local and testing, .env file that contains the settings and config/databse.php are same. Permission for both Testing server and local server is same.

Is there anything, I am missing?

Update:

Using tinker, I tried mysqli connection and pdo connection and I get

ubuntu@ip-172-31-30-158:/var/www/html/app$ php artisan tinker
Psy Shell v0.9.9 (PHP 7.2.10-0ubuntu0.18.04.1 — cli) by Justin Hileman
>>> mysqli_connect('myhost', 'user', 'password', 'db')
=> mysqli {#3054
     +affected_rows: null,
     +client_info: null,
     +client_version: null,
     +connect_errno: null,
     +connect_error: null,
     +errno: null,
     +error: null,
     +error_list: null,
     +field_count: null,
     +host_info: null,
     +info: null,
     +insert_id: null,
     +server_info: null,
     +server_version: null,
     +stat: null,
     +sqlstate: null,
     +protocol_version: null,
     +thread_id: null,
     +warning_count: null,
   }
>>> new PDO('mysql:host=myhost;dbname=db', 'user', 'password');
=> PDO {#3053
     inTransaction: false,
     attributes: {
       CASE: NATURAL,
       ERRMODE: SILENT,
       AUTOCOMMIT: 1,
       PERSISTENT: false,
       DRIVER_NAME: "mysql",
       SERVER_INFO: "Uptime: 1136758  Threads: 27  Questions: 95411  Slow queries: 0  Open                                                                   s: 4155  Flush tables: 1  Open tables: 413  Queries per second avg: 0.083",
       ORACLE_NULLS: NATURAL,
       CLIENT_VERSION: "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7534543                                                                   ae0acafe387 $",
       SERVER_VERSION: "5.7.24-0ubuntu0.16.04.1",
       STATEMENT_CLASS: [
         "PDOStatement",
       ],
       EMULATE_PREPARES: 1,
       CONNECTION_STATUS: "myhost via TCP/IP",
       DEFAULT_FETCH_MODE: BOTH,
     },
   }
>>>

Solution

  • Did you try php artisan config:clear to clear the cached config?

    Maybe you have cached the old config file on your testing server.