I am using nginx/1.20.1, PHP 7.2.34, mysqld 8.0.27 on CentOS7. I can open the wordpress index page but the installation always failed. I am sure that my username, password, and hostnames are correct (even if I add more users or reset the passwords), but it says:
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 tried to create my own wp-config.php file and set the configuration, then it would be a HTTP ERROR 500. The log says: PHP Warning: require_once(/var/www/html/wp-config.php): failed to open stream: Permission denied in /var/www/html/wp-load.php on line 50 I don't know why mine is line 50 but others are 37. Howeverm, I already change the ownership of html(and even www) folder fo to nginx, and changed all the files in them to 777, but it is still not working.
I think MySQL is not connected to the wordpress but the 3306 port is open:
tcp6 0 0 :::3306 :::* LISTEN 31913/mysqld
and it still did not work when I did:
define( 'DB_HOST', '127.0.0.1:3306' );
in wp-config.php
I tired WP-DEBUG but it did not show because of the HTTP ERROR 500. What else can I do now
CodePudding user response:
Are you sure you entered the username and password correctly for the MySQL user?
If you're still unsure:
- create a new database
- define a new user in the database
- and then retest.
Here are instructions for creating a new user and granting permissions
CodePudding user response:
I read and learned this from somewhere else: Running a test PHP program to connect MySQL
<PHP
<?PHP
$connect =mysqli_connect("localhost","username","password","dbname");
if (!$connect) {
die('error'. mysqli_error());
}
echo 'success';
mysqli_close($link);
?>
and it returns:
PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /home/test.php on line 4
PHP Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in /home/test.php on line 4
PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/test.php on line 7
My current PHP does not support the verification method demanded(caching_sha2_password), the default for PHP is mysql_native_password. I altered it with
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
And it worked.