Home > Database > Mysql Tutorial > body text

Why Am I Getting a \'Permission Denied\' Error When Connecting to My Database from Localhost?

Mary-Kate Olsen
Release: 2024-11-01 13:02:02
Original
721 people have browsed it

Why Am I Getting a

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:

  1. Verify the status of the policy using the command:
getsebool -a | grep httpd
Copy after login
  1. If "httpd_can_network_connect_db" is set to "Off," enable it permanently:
setsebool -P httpd_can_network_connect_db 1
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
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!