08-06-2023, 03:35 PM
I've got a Laravel project on a server, and a Laravel Lumen 8 project on another server, they're both virtual machines and are clones of one another so have the same hardware and OS.
I have a domain, which for the purposes of this Stackoverflow we'll call foo.com, it goes through Cloudflare, both servers are ipv6 servers and when pinging each other via ssh they can see each other just fine.
The problem I have is with connecting to the MySQL (Maria DB) database from my Lumen project on the other server.
I've tried using:
- The domain of the server where the DB exists
- The ipv6 domain
- The VM's local ipv4 address since both servers exist on the same network this is how they can see each other
I'm testing the connection using Tinker and running:
```bash
DB::connection()->getPdo();
```
And I'm unable to connect for some reason, these are the combinations and errors I've encountered and would like to know what I'm missing:
### Attempt 1
```
DB_CONNECTION=mysql
DB_HOST=local ipv4
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=user
DB_PASSWORD=pass
```
> PDOException with message 'SQLSTATE[HY000] [2002] No route to host
### Attempt 2
```
DB_CONNECTION=mysql
DB_HOST=ipv6 address
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=user
DB_PASSWORD=pass
```
> PDOException with message 'SQLSTATE[HY000] [2002] Invalid argument'
### Attempt 3
```
DB_CONNECTION=mysql
DB_HOST=api.foo.com
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=user
DB_PASSWORD=pass
```
> PDOException with message 'SQLSTATE[HY000] [2002] Connection timed out'
How can I get my Lumen project to connect to my Laravel database on another server, I'm pretty sure I've tried every combination here.
I have a domain, which for the purposes of this Stackoverflow we'll call foo.com, it goes through Cloudflare, both servers are ipv6 servers and when pinging each other via ssh they can see each other just fine.
The problem I have is with connecting to the MySQL (Maria DB) database from my Lumen project on the other server.
I've tried using:
- The domain of the server where the DB exists
- The ipv6 domain
- The VM's local ipv4 address since both servers exist on the same network this is how they can see each other
I'm testing the connection using Tinker and running:
```bash
DB::connection()->getPdo();
```
And I'm unable to connect for some reason, these are the combinations and errors I've encountered and would like to know what I'm missing:
### Attempt 1
```
DB_CONNECTION=mysql
DB_HOST=local ipv4
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=user
DB_PASSWORD=pass
```
> PDOException with message 'SQLSTATE[HY000] [2002] No route to host
### Attempt 2
```
DB_CONNECTION=mysql
DB_HOST=ipv6 address
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=user
DB_PASSWORD=pass
```
> PDOException with message 'SQLSTATE[HY000] [2002] Invalid argument'
### Attempt 3
```
DB_CONNECTION=mysql
DB_HOST=api.foo.com
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=user
DB_PASSWORD=pass
```
> PDOException with message 'SQLSTATE[HY000] [2002] Connection timed out'
How can I get my Lumen project to connect to my Laravel database on another server, I'm pretty sure I've tried every combination here.