- 45 Views
- 26/03/2025
Executing database schema update. ERROR: SQLSTATE[HY000] [2002] No such file or directory ERROR: Failed to connect to database
It seems like you're encountering errors while trying to build Roundcube on DirectAdmin, specifically related to MySQL database connectivity. Let’s break this down and address the issue step-by-step, then explore manual installation as an alternative if needed.
### Analyzing the Errors
1. **MySQL Error: `ERROR 1045 (28000): Access denied for user 'da_roundcube'@'localhost' (using password: YES)`**
- This error suggests that the MySQL user `da_roundcube` is trying to connect from `localhost`, but the user was created with the host `42.96.18.36`. MySQL treats `localhost` and an IP address as different hosts, so the credentials don’t match.
2. **Database Connection Error: `SQLSTATE[HY000] [2002] No such file or directory`**
- This indicates that Roundcube cannot connect to the MySQL server. The "No such file or directory" error typically means the MySQL socket file (e.g., `/var/run/mysqld/mysqld.sock`) is missing, misconfigured, or inaccessible, or the MySQL server isn’t running.
### Possible Causes
- The MySQL server isn’t running or is misconfigured.
- The Roundcube configuration file is pointing to the wrong database host (e.g., `localhost` instead of `42.96.18.36`).
- The user permissions in MySQL are not correctly set up for the host Roundcube is connecting from.
- The MySQL socket path is incorrect or missing.
### Fixing the Issue
Here’s how you can troubleshoot and resolve this:
#### Step 1: Verify MySQL is Running
- Check if the MySQL service is active:
or
- If it’s not running, start it:
- If it fails to start, check the MySQL logs (e.g., `/var/log/mysql/error.log`) for clues.
#### Step 2: Check MySQL Socket
- The `[2002] No such file or directory` error often relates to the MySQL socket. Verify its location:
- Common default: `/var/run/mysqld/mysqld.sock`
- If the socket file is missing, restart MySQL:
- Ensure the socket path matches what Roundcube expects in its configuration.
#### Step 3: Fix MySQL User Permissions
- The user `da_roundcube` is tied to `42.96.18.36`, but Roundcube might be trying to connect via `localhost`. Log in to MySQL as root:
- Create or update the user for `localhost`:
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, LOCK TABLES, INDEX, REFERENCES ON da_roundcube.* TO 'da_roundcube'@'localhost';
FLUSH PRIVILEGES;
- Alternatively, if Roundcube should connect via `42.96.18.36`, ensure the configuration reflects that IP instead of `localhost`.
#### Step 4: Update Roundcube Configuration
- Edit the Roundcube config file (usually `/var/www/html/roundcube/config/config.inc.php` or similar, depending on DirectAdmin’s setup):
- Replace `localhost` with `42.96.18.36` if that’s the intended host.
- If using a socket, specify it explicitly:
#### Step 5: Test Database Connection
- Test the connection manually:
- If it fails, double-check the password, host, and database name.
#### Step 6: Run Schema Update Again
- After fixing the connection, rerun the schema update:
php bin/updatedb.sh
### Manual Installation (Build Tay)
If the DirectAdmin script keeps failing, you can install Roundcube manually:
1. **Download Roundcube**
- Get the latest version:
tar -xzf roundcubemail-1.5.2-complete.tar.gz
mv roundcubemail-1.5.2 /var/www/html/roundcube
2. **Set Permissions**
chmod -R 755 /var/www/html/roundcube
3. **Create Database and User**
- Log in to MySQL:
- Run:
CREATE USER 'da_roundcube'@'localhost' IDENTIFIED BY 'PxHgzT99sOgcN';
GRANT ALL PRIVILEGES ON da_roundcube.* TO 'da_roundcube'@'localhost';
FLUSH PRIVILEGES;
4. **Configure Roundcube**
- Copy the sample config:
- Edit `config.inc.php`:
$config['default_host'] = 'localhost';
$config['smtp_server'] = 'localhost';
$config['smtp_port'] = 25;
5. **Run Installer**
- Open your browser and go to `http://yourdomain.com/roundcube/installer`.
- Follow the steps to verify settings and initialize the database.
6. **Secure Installation**
- Remove the installer folder:
### Final Thoughts
The automated DirectAdmin script likely failed due to a mismatch in MySQL host settings or a socket issue. Fixing the user permissions and ensuring MySQL is properly configured should resolve it. If you prefer full control, the manual method avoids script-specific quirks. Let me know if you need further assistance!
