I've got a Wordpress (php-fpm/nginx) server, totally fresh. Running on CentOS. I've also got a docker container, built from the vanilla mysql-server image.
MySQL Configuration
It's running on port 3306
, and all MySQL users are registered in MySQL with host 172.17.0.1
(e.g. root@172.17.0.1
), which is docker's gateway IP. The docker container is installed using an ansible playbook. All configuration settings are parameterized, and those parameters are used everywhere appropriate, including the WordPress configuration file and the environment variables that fill in things like root password during the MySQL docker installation. Here's where I configure the relevant database:
WordPress configuration:
This is in two parts, of which I'll include the relevant ones. In my ansible playbook, this code sets up the WordPress table and user (successfully):
- name: Create WordPress database
mysql_db:
name: '{{ wp_db_name }}'
state: present
login_user: root
login_password: '{{ mysql_root_password }}'
login_host: '{{ docker_mysql_ip }}'
- name: Create WordPress database user
mysql_user:
name: '{{ wp_db_user }}'
password: '{{ wp_db_password }}'
priv: '{{ wp_db_name }}.*:ALL'
state: present
login_user: root
host: '{{ docker_gateway_ip }}'
login_password: '{{ mysql_root_password }}'
login_host: '{{ docker_mysql_ip }}'
And the relevant wp-config.php:
define('DB_NAME', 'wordpress');
define('DB_USER', '{{ wp_db_user }}');
define('DB_PASSWORD', '{{ wp_db_password }}');
define('DB_HOST', '{{ docker_mysql_ip }}');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
When I navigate to wp-admin, the specific problem stated is "Warning: mysql_connect(): Permission denied in /srv/wordpress/wp-includes/wp-db.php on line 1473
", titled "Error establishing a database connection", status code 500.
The confusing part
When I check on the wp-config.php file, the username, password, and database name are all exactly as they should be. When I copy/paste the host, user, and password out of wp-config.php
into their respective locations on the command line (e.g. mysql -u wordpress -p -h 172.17.0.2
), I can connect, as well as view the Wordpress database.
To sum up
MySQL is able to connect properly when using the command line, but Wordpress is not able to. I'm also not very familiar with Wordpress or PHP, so any ideas on where logs relevant to the problem could be located would be appreciated.