Trouble Connecting to Database: Error Code 2002 (Permission Denied)
In an attempt to connect to a database, a PHP script encountered the error "Connect DATABASE Error TYPE: 2002: Permission denied." This issue arose when executing the script from localhost, but not from the command line.
Upon investigation, it was discovered that the error stemmed from SELinux security policies. By default, the policy "httpd_can_network_connect_db" is disabled, prohibiting web servers from establishing connections with remote databases.
To resolve the issue:
getsebool -a | grep httpd
setsebool -P httpd_can_network_connect_db 1
Restarting the web server after making these changes should allow for successful database connections from localhost.
The above is the detailed content of Why Am I Getting a \'Permission Denied\' Error When Connecting to My Database from Localhost?. For more information, please follow other related articles on the PHP Chinese website!