0

I am trying to install a Wordpress site on a local server (Ubuntu 16.04 in a docker container).

Xampp is installed and running, and I have created a database and a username with proper rights:

mysql -uroot -e "CREATE USER 'localuser'@'localhost' IDENTIFIED BY 'localpassword';";
mysql -uroot -e 'CREATE DATABASE 'localdatabase';';
mysql -uroot -e "GRANT ALL ON localdatabase.* TO 'localuser'@'localhost';";

I've also updated my wp-config.php file with the credentials above.

Still, when I try to install wordpress from there (I use wp-cli), I get the message "Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down."

I've double checked the credentials, and xampp is indeed running, so what should I check next? Could this come from a config file that is missing something?

Sulli
  • 763
  • 1
  • 11
  • 33

2 Answers2

0

What hostname are you using in the wp-config? Also did the commands finish succesfully? For creating the db you used apostrophes instead of quotes. You can try the mysql client directly with mysql -u -p -h .

  • I'm using 'localhost' in wp-config.php. Yes the commands finish successfully. I checked with SHOW DATABASES; and SHOW GRANTS; , my database has been created, my username too and the username has the rights – Sulli Nov 10 '18 at 20:23
  • Is the mysql in the same container as wordpress? If so you cannot use localhost, you have to use the ip of the musql container. – Andrei Dumitrescu-Tudor Nov 10 '18 at 20:25
  • yes they are in the same container. You're saying I can not use localhost in this case? – Sulli Nov 10 '18 at 20:42
  • If they are in the same container you can use localhost. I mistyped before. – Andrei Dumitrescu-Tudor Nov 10 '18 at 20:46
  • ah ok that's what I thought. I added the -p 4000:80 option for my docker and tried to access in my host's browser http://localhost:4000/phpmyadmin, but got the error "Access forbidden! New XAMPP security concept: Access to the requested directory is only available from the local network.This setting can be configured in the file "httpd-xampp.conf"." Is this related to my issue or is it only a because I'm accessing phpmyadmin from the host? – Sulli Nov 10 '18 at 21:04
  • I was able to access phpmyadmin using lynx in the container so this error was related to accessing phpmyadmin from outside the container. So I still have my original problem. – Sulli Nov 10 '18 at 21:27
0

In wp-config.php, use 127.0.0.1 instead of localhost for the database hostname.

Sulli
  • 763
  • 1
  • 11
  • 33