Database connection error: Error type 2002 - Permission denied
P粉757640504
P粉757640504 2023-08-24 19:54:00
0
1
420

I am trying to connect to the database using the following script (cxn-test.php)

 

When I try it on the terminal

php cxn-test.php //Success

But when I try it on localhost, I get the following error:

curl -s http://localhost/cxn-test.php

Error: Unable to connect to MySQL. Debug error number: 2002 Debug error message: Permission denied

This is a weird issue, it doesn't work on localhost but works fine on the command line.

P粉757640504
P粉757640504

reply all (1)
P粉041881924

I ran into the same problem after getting a new CentOS 7 box running SELinux. I can connect to the remote MySQL database server via the command line, but Drupal (and the test PHP script) cannot connect.

The problem is ultimately caused by the SELinux security policy.

By default, the policyhttpd_can_network_connect_dbis disabled (meaning your web servercannotcontact the remote database).

Check with the following command:

getsebool -a | grep httpd

If httpd_can_network_connect_db is Off, please enable it through the following command:

setsebool -P httpd_can_network_connect_db 1

(The -P flag makes the changes permanent, so the settings remain in effect across reboots.)

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!