Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Establishing Database Connection (a possible solution to this) #66

Open
tden012 opened this issue Dec 23, 2015 · 3 comments
Open

Comments

@tden012
Copy link

tden012 commented Dec 23, 2015

I tried using the nginx recipe of this cookbook today on an ubuntu 14.04 machine and it all installed beautifully. BUT...

When I tried to run Wordpress nothing happened. This turned out to be an easy fix - nginx wasn't running, so I had to type:

sudo service nginx start

This started nginx, even though there was no output from the console.

The second problem I ran into was that on accessing the main web page, I got the error: "Error Establishing Database Connection"

Took me a while to figure out - and after some googling, I came across the cause. Turns out that Wordpress doesn't like the database host being referred to as 'localhost'. Instead, you have to use '127.0.0.1'.

Changing this is quite easy. You have to do this from within your cookbook:

If you are using your own cookbook, you can set the host in recipes/default.rb like this:

node.default['wordpress']['db']['host']  = "127.0.0.1"

or alternatively, you can set it in attributes/default.rb like this (useful if you follow the wrapper cookbook pattern):

default['wordpress']['db']['host'] = "127.0.0.1"

This allows everything to work as expected. But I'm curious - does anyone know why using 'localhost' doesn't work?

@burtlo
Copy link

burtlo commented Feb 13, 2016

  • Centos 6.7
  • Amazon EC2

I left everything standard. Applied the cookbook. See this error.

Wrapped the cookbook to replace the db host value to 127.0.0.1 and I still see this error.

@burtlo
Copy link

burtlo commented Feb 13, 2016

The user 'wordpressuser' was created in the database with no password. I was able to login without being prompted:

$ mysql -u wordpressuser
mysql> \q

So I updated the password for the 'wordpressuser' by setting to the password value I found in /var/www/wordpress/wp-config.php.

$ mysql -u wordpressuser
mysql> SET PASSWORD FOR 'wordpressuser'@'localhost' = OLD_PASSWORD('PASSWORD_FOUND_IN_WPCONFIG');
mysql> \q
$ mysql -u wordpressuser -p

burtlo pushed a commit to burtlo/wordpress-wdrt that referenced this issue Feb 13, 2016
The user 'wordpressuser' was created in the database with no password. I was able to login without being prompted:

$ mysql -u wordpressuser
mysql> \q
So I updated the password for the 'wordpressuser' by setting to the password value I found in /var/www/wordpress/wp-config.php.

$ mysql -u wordpressuser
mysql> SET PASSWORD FOR 'wordpressuser'@'localhost' = OLD_PASSWORD('PASSWORD_FOUND_IN_WPCONFIG');
mysql> \q
$ mysql -u wordpressuser -p
http://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_old-password

brint/wordpress-cookbook#66
@burtlo
Copy link

burtlo commented Feb 17, 2016

Actually upon further examination it looks like wordpres is still using the USER@'localhost' even if I specified the following default['wordpress']['db']['host'] = "127.0.0.1". So I tried to drop back to not specifying the value of the database host and it generated a user with no password again.

+---------+-----------+-------------------------------------------+
| User    | Host      | Password                                  |
+---------+-----------+-------------------------------------------+
| root    | localhost | *5AE22F70B5073B1582E0D3511BB225FB0E218E89 |
| root    | 127.0.0.1 | *5AE22F70B5073B1582E0D3511BB225FB0E218E89 |
| wp_user | localhost |                                           |
+---------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

Looking through the cookbooks I found that the database cookbook has the resource responsible for the generation of the user. When I debug and step my way through it it seems to create the correct repair sql here.

"CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'PASSWORD'"

Before the connection is closed on the mysql adapter I check to make sure that the user has been created with the password:

repair_client.query("SELECT User,Host,Password from mysql.user").to_a
=> [{"User"=>"root", "Host"=>"localhost", "Password"=>"*5AE22F70B5073B1582E0D3511BB225FB0E218E89"},
 {"User"=>"wp_user", "Host"=>"localhost", "Password"=>""},
 {"User"=>"root", "Host"=>"127.0.0.1", "Password"=>"*5AE22F70B5073B1582E0D3511BB225FB0E218E89"}]

It seems that the value is set correctly but then when the execution of the run completes it is no longer present. Which leads me to believe that something is taking place when it comes time to grant permissions to the user.

When granting permissions to the user it looks like the database password is necessary again. And because it is missing in the definition in the wordpress::database recipe it essentially clears that password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants