Why does the mysql CLI connect but not WordPress?

I have a Wordpress server (php-fpm / nginx), completely fresh. Powered by CentOS. I also have a docker container built from vanilla mysql server image.

MySQL configuration

It works on the port 3306, and all MySQL users are registered in MySQL with a host 172.17.0.1(for example, root@172.17.0.1), which is the gateway IP gateway. A docker container is installed using a downloadable file. All configuration parameters are parameterized, and these parameters are used everywhere, including the WordPress configuration file and environment variables that fill in things like the root password during the installation of the MySQL dock. Here, where I set up the appropriate database:

WordPress configuration:

These are two parts of which I will include the relevant ones. In my obscure play, this code sets up a WordPress user table and (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 corresponding 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 go to wp-admin, the specific problem indicated is " Warning: mysql_connect(): Permission denied in /srv/wordpress/wp-includes/wp-db.php on line 1473", entitled "Error connecting to database," status code 500.

The tangled part

When I check the wp-config.php file, the username, password, and database name are exactly the same as they should be. When I copy / paste the host, user and password from wp-config.phpto their respective locations on the command line (for example mysql -u wordpress -p -h 172.17.0.2), I can connect as well as view the Wordpress database.

Summarizing

MySQL , Wordpress . Wordpress PHP, , , , .

+6
1

Debian 9.1 MariaDB, Oracle MySQL . , PHP .

, , , Linux- ( , ), mysql_secure_installation .

, .

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
0

All Articles