Search code examples
phpmysqlcodeigniterrhel7

Cannot connect to remote DB via CodeIgniter


I am running a CodeIgniter application on a RHEL7 virtual machine. I am trying to connect it to a another remote DB server. I get a Message: mysqli::real_connect(): (HY000/2002): Permission denied

I have tried the following:

  1. Successfully connected to DB server via command line on App server using,
    mysql -u username -p -h host.domain.edu -P 1234, and then the password. I get to the MySQL CLI. Success
  2. Successfully connected to DB server via CI application from my local server.
    I set the config/database.php with the credentials on my local app and I am able to connect to the remote DB.
  3. Wrote a vanilla PHP script to connect to DB and rand it on the App server and it works fine too.
  4. But, unable to connect CI application on remote server to DB server.

The port is already open and listening to traffic from my App server IP, the firewall is not the issue (I think). What am I doing wrong?


Solution

  • After looking around the internet, I learnt that SELinux was preventing httpd to connect to remote servers. I had to set the below 2 flags to true and that worked for me.

    setsebool -P httpd_can_network_connect 1 
    setsebool -P httpd_can_network_connect_db 1
    

    Source