Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 190 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why can mysql CLI connect, but not WordPress?

#1
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. `[email protected]`), 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.
Reply

#2
I just had this problem on Debian 9.1 using MariaDB, but this should be the same in Oracle MySQL. I could log in easily from the command line, but PHP could not access the database.

It took me a few minutes to figure out, but I remembered from when I used to use Arch Linux on an old server (a dumb idea by the way) that the command `mysql_secure_installation` was needed to get it to accept connections.

Try it out, this worked for me.

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!
Reply

#3
IN **MySQL container** use MySQL native password for authentication with this environment:

MYSQL_DEFAULT_AUTH=mysql_native_password

Then restart or rebuild MySQL container.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through