Question

How to connect laravel project in App Platform to Database Managed Cluster?

Hello everyone, I try to deploy a Laravel project in Digitalocean App platform but I have problems with database connections. My env variables are:

DB_HOST = ${db-cluster-name.DATABASE_URL}
DB_CONNECTION = mysql
DB_PORT = ${db-cluster-name.PORT}
DB_DATABASE = db_name
DB_USERNAME= db_username
DB_PASSWORD= db_password

When I try in DO console commands like:

php artisan migrate

I have the following errors:

In Connection.php line 671:
                                                                                                                                                        
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where t  
  able_schema = circle_in_family and table_name = migrations and table_type = 'BASE TABLE')                                                             
                                                                                                                                                        

In Connector.php line 70:
                                                                                                  
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known  
                                                                                                  

In Connector.php line 70:
                                                                                               
  PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known 

Any ideas?

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
February 3, 2021
Accepted Answer

Hi there @elenaRay,

The details would usually look like this:

Database details for Laravel

I could suggest watching this video by Chris on how to deploy Laravel to the app platform:

Let me know how it goes. Regards, Bobby

Thanks very much bobbyiliev! I hadn’t seen the video and it was very helpful to me. My fault was that I have DB_HOST and not DATABASE_URL.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.