Hello, i have an issue when i try to deploy my app with the managed database on digitalocean (MYSQL 8), i have error at build time, after composer install:
SQLSTATE[HY000] [2002] No such file or directory
it’s a symfony application with doctrine.
THANKS A LOT
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!
Hi there
The error SQLSTATE[HY000] [2002] No such file or directory often occurs when your PHP application is trying to connect to a MySQL server via a Unix socket, but the socket file doesn’t exist at the specified location. When deploying to a DigitalOcean managed MySQL database, you will connect over the network (typically using a hostname and port), not a Unix socket.
When deploying applications, especially on platforms that use distinct build and deploy stages, it’s crucial to understand the appropriate time to establish database connections or perform database-related operations.
During the build stage, the primary goal is to compile, package, or prepare the application for deployment. Typically, this involves tasks like:
composer install for PHP projects)Connecting to a database during the build stage is not recommended, as:
During the deploy stage, the application is actually being launched and made ready for user traffic. This is the right time to:
Given that you’re facing the SQLSTATE[HY000] [2002] No such file or directory error during the build stage after composer install, it seems like there might be a post-install script or some logic that’s attempting to connect to the database.
Check composer.json: Look in the scripts section of your composer.json file. Ensure there aren’t any post-install or post-update scripts that are trying to connect to the database or run Symfony commands that require a database connection.
Move Database-related Operations: If there are any, consider moving them to a deployment script or another mechanism that runs during the deploy stage. Remember, the build stage should only prepare the code and assets, not interact with external services.
Environment Variables: Make sure your application knows when it’s in build mode vs. deploy mode. This way, even if there’s code that tries to connect to the database, you can prevent it from executing during the build stage.
Let me know how it goes!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.