Connect DATABASE Error: "Permission denied" on Localhost
Attempting to connect a database through PHP may yield different results when executed on the terminal compared to when run locally. In the provided scenario, the error "Connect DATABASE Error TYPE: 2002: Permission denied" indicates that the web server lacks the necessary permissions to access the database.
The issue often stems from SELinux security policies. By default, the policy "httpd_can_network_connect_db" is disabled, prohibiting the web server from establishing connections with remote databases.
Solution:
Verify the SELinux status by running:
getsebool -a | grep httpd
If "httpd_can_network_connect_db" is set to "Off," enable it with:
setsebool -P httpd_can_network_connect_db 1
Once the SELinux policy is modified, the web server should be able to connect to the remote database, resolving the "Permission denied" error.
The above is the detailed content of Why am I getting a \"Permission denied\" error when connecting to my database on localhost?. For more information, please follow other related articles on the PHP Chinese website!