Troubleshooting "No such file or directory" when running `php app/console doctrine:schema:create`

Troubleshooting "No such file or directory" when running `php app/console doctrine:schema:create`

  1. Blog
  2. 15 November 2026
  3. 2 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding the "No such file or directory" Error in Doctrine Schema Creation

When running php app/console doctrine:schema:create, encountering a PDOException with SQLSTATE[HY000] [2002] indicates that the database driver cannot establish a connection. The specific error message, Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock), reveals exactly where the configuration has diverged from reality.

This mismatch typically occurs in local development environments, particularly on macOS using MAMP or similar stack managers. The error log shows Doctrine attempting to connect via a Unix socket at /var/mysql/mysql.sock. However, the actual MySQL installation provided by these stacks often defaults to listening on TCP/IP (port 3306) rather than via sockets, or the socket file resides in a different directory, such as /Applications/MAMP/tmp/mysql/ or /tmp/.

The root cause is almost always a misalignment between the host parameter in your config.yml and the actual state of the MySQL server. When you set the host to an empty string or localhost, Doctrine's DBAL driver interprets this as a request to connect via a Unix socket on the default system path (/var/mysql/mysql.sock). If that file does not exist, the connection fails immediately before any SQL logic is executed.

To resolve this, you must force the application to use TCP/IP connections by explicitly specifying 127.0.0.1 as the host. This forces the PDO driver to bypass the socket lookup entirely and attempt a standard network connection on port 3306.

Update your config.yml (or .yml) under the doctrine.dbal section:

doctrine:
    dbal:
        driver:   %database_driver%
        host:     127.0.0.1 # Explicitly force TCP/IP connection
        port:     3306      # Ensure the standard MySQL port is used
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%

By hardcoding 127.0.0.1, you signal to Doctrine that it should ignore the local socket configuration and connect over the network loopback interface. This is a standard workaround for environments where the socket file path is non-standard or missing.

It is worth noting that this behavior can sometimes be confusing because the parameters.ini file often contains keys like %database_host%. If you have defined %database_host% in your parameters file as an empty string, Doctrine will still default to the socket path unless explicitly overridden in the YAML configuration. Ensure that your environment variable or parameter definition does not inadvertently revert to an empty value when loading the config.

Additionally, verify that the MySQL service is actually running and listening on port 3306. You can confirm this by checking the MAMP console or using the mysqladmin command with the -h127.0.0.1 flag:

mysql -u root -p -h 127.0.0.1 -e "SELECT VERSION();"

If this command returns a version string without error, the TCP connection is valid, and the issue was strictly the socket path assumption in Doctrine's configuration. Once the host is corrected to 127.0.0.1 and the service is confirmed reachable, running php app/console doctrine:schema:create should successfully initialize the database schema as intended.

Our network