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!
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.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
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 aftercomposer 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 thescripts
section of yourcomposer.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