Cannot connect to MySQL from PHP(Permission Denied), even if commandline or other programs works

  • If your PHP code (e.g. adminer) cannot connect to your MySQL database (Error: Permission Denied), yet you can connect successfully via other program, like HeidiSQL or even command line, this is for you.
  • Reference: https://serverfault.com/a/667930/253676
    • It said even if you have SELinux disabled, Apache server still cannot connect to MySQL
      • Noted what I wrote: Apache cannot connect to MySQL
    • So you need to run (either one, not both):
      • Permanent:
        • `setsebool -P httpd_can_network_connect_db on`
      • Temporary:
        • `setsebool httpd_can_network_connect_db=1`
  • Then you tried again, you should be fine.

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

How to fix fancy box/Easy Fancybox scroll not work in mobile

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services