0

I recently tried to setup a dev environment for my production site and replicated the same architecture.

I've a server hosting Drupal, a second server for mysql and a memcached server. All the setup was good.

  • Exported the Prod DB
  • Installed Drush
  • Made sure the latest code is pulled
  • run Drush status

    Drupal version : 7.37
    Site URI : http://default
    Database driver : mysql
    Database hostname : ip address
    Database port : 3306
    Database username : username
    Database name : dbname
    PHP configuration : /etc/php.ini
    PHP OS : Linux
    Drush script : /usr/local/bin/drush
    Drush version : 8.1.9
    Drush temp directory : /tmp
    Drush configuration :
    Drush alias files :
    Drupal root : /path/to/root/folder
    Drupal Settings File : sites/default/settings.php Site path : sites/default

The issue is when trying to load the website I get :

PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'ip-address' (13) in lock_may_be_available() (line 167 of /var/www/cw/html/includes/lock.inc).

Any idea why this is happening ? If I run drush sqlc I'm able to connect to the remote database.

Any help will be much appreciated.

2 Answers 2

2

For anyone having the SAME error code, please check if you have SELinux enable by typing sestatus. If that's the case then your firewall is most likely blocking the connection to the db.

To allow it you can use the following command line :

setsebool httpd_can_network_connect_db=1
0

Have you created user with APP Server IP in your database. If not please create the user first.

CREATE USER ‘username’@’APP_SERVER_IP’ IDENTIFIED BY ‘password’; GRANT ALL PRIVILEGES ON . TO ‘username’@’APP_SERVER_IP’; FLUSH PRIVILEGES;

and then use this user in your drupal site to connect with database.

If it is not working then please check the MySQL Database port on DB Server. If it is not open then open it first.

1
  • It didn't work. fyi I'm able to connect using drush, so the port is not the issue. I also used the root on my settings.php and it's not working either.
    – 113408
    Commented Apr 26, 2017 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.