英文:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database
问题
I'm trying to setup a Laravel 10 application on DigitalOcean with a Managed Database. I have an nginx server up and running on the droplet and can access the website by its domain name. However, I can't connect to the Managed Database as can be seen in the screenshot below when I try to migrate the tables.
英文:
I'm trying to setup a Laravel 10 application on DigitalOcean with a Managed Database. I have an nginx server up and running on the droplet and can access the website by it's domainname. However I can't connect to the Managed Database as can be seen in the screenshot below when I try to migrate the tables:
What I have so far is:
- Configured the server according to: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-22-04
- Installed LEMP stack according to: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-22-04, but skipped the installation of MySql as in the prerequisites of the “How to Set Up a Scalable Laravel 6 Application using Managed Databases and Object Storage” tutorial.
- Installed the MySQL client, created a Mysql user and database according to https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-laravel-6-application-using-managed-databases-and-object-storage#step-2-creating-a-new-mysql-user-and-database
- Installed Composer, NodeJS and NPM
- Created a Managed Database in the DO control panel. ( In the same VPC as the droplet)
- Added the droplet to the trusted sources.
- Added domains and dns settings in the DO control panel
- Installed LetsEncrypt SSL certificate.
These are the settings I use:
.env
Which come straight from the DO control panel:
/config/database.php
Location of the CA certificate;
Furhtermore I'm able login the mysql server inside the droplet and create database users and tables .
I really would appreciate any help on this. I'm currently kind of clueless after searching for hours on the internet.
答案1
得分: 1
经过长时间的搜索和调试,我发现在 /etc/environment 中已经定义了数据库变量。我猜想在创建Droplet并选中“添加托管数据库”复选框时,DigitalOcean会将其放在那里。然而,我最终删除了它并创建了另一个托管数据库。因此,我应用程序中的 .env 文件中的数据库被 /etc/environment 文件中定义的数据库覆盖了。
英文:
After very long searching and debugging I found that there were already database variables defined in /etc/environment.
I guess DigitalOcean puts it there when you create your droplet and have the "add a managed database" checkbox checked. However I ended up deleting it and creating another managed database.
So the database in my .env file in my application were overruled by the ones defined in the /etc/environment file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论