Welcome Guest, Not a member yet? Register   Sign In
Problem Connecting to MySQL, CentOS
#1

I'm having problems getting CodeIgniter to connect to a remote DB.

My base system is as follows:
CentOS 7 running on AWS
Apache, PHP and MySQL Client Installed
Installed php-mysql
CodeIgniter 3.0.0 installed and working with pages not using DB.

Remote database:
Amazon RDS running MySQL (separate machine).

I can connect to the DB from the base system using MySQL command line.
When I try connecting to the DB through a CodeIgniter connector, I receive the error below.
I'm using the same parameters in database.php in CI as in MySQL command line (checked a few times)

Any ideas? Thanks.

Andy

Severity: Warning
Message: mysqli::real_connect(): (HY000/2003): Can't connect to MySQL server on 'hostname' (13)
Filename: mysqli/mysqli_driver.php
Line Number: 135
Backtrace:
File: /var/www/html/application/controllers/Messages.php
Line: 72
Function: database
File: /var/www/html/index.php
Line: 292
Function: require_once

$db['default'] = array(
'dsn' => '',
'hostname' => 'hostname',
'username' => 'user',
'password' => 'pwd',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Reply
#2

Is your host really called "hostname"? Probably should be 'localhost', '127.0.0.1', or the public facing IP. You also aren't selecting a database.
Reply
#3

CroNiX: Thanks for your help. The actual host name is something like: xxxxx.rds.amazonaws.com. I just used 'hostname' in the post to keep it secret.

As an update, I installed the same code on an Ubuntu instance and it is working fine. I think the problem may be with the default configuration of CentOS, mysql.sock is not present by default.
Reply
#4

Did you make sure to add the same user to the MySQL database and give the user the proper permissions?  You will still need to do that when you move to a new MySQL instance.
Reply
#5

(06-30-2015, 11:26 AM)ad11 Wrote: CroNiX: Thanks for your help. The actual host name is something like: xxxxx.rds.amazonaws.com. I just used 'hostname' in the post to keep it secret.

As an update, I installed the same code on an Ubuntu instance and it is working fine. I think the problem may be with the default configuration of CentOS, mysql.sock is not present by default.

I had the same exact problem with Centos/7. I was using 2 virtualboxes one each for the web server and the database server. I had also installed the mysql database on my web server to be able to test local connectivity. When I used "localhost" as hostname in the database.php on the web server, it would work but once I switched it to 127.0.0.1 or 192.168.10.11(my static ip on a virtualbox linux instance on which I had installed the DB to check connectivity with remote database), I would get database connection errors. Someone on one of the forums I visited mentioned about SeLinux security settings being the issue and it was. So I had to do this on the web server to solve it:

sudo setsebool -P httpd_can_network_connect_db=1


This link provides a good explanation: https://www.axivo.com/resources/selinux-...lained.22/

Hope this helps others who are facing a similar problem.
Reply
#6

'hostname' => 'IP SERVER',
'username' => 'user',
'password' => 'pwd',
'port' => '3306',

Enable Remote Access To MySQL Database Server
Reply
#7

(02-06-2017, 06:24 AM)arjoule Wrote:
(06-30-2015, 11:26 AM)ad11 Wrote: CroNiX: Thanks for your help. The actual host name is something like: xxxxx.rds.amazonaws.com. I just used 'hostname' in the post to keep it secret.

As an update, I installed the same code on an Ubuntu instance and it is working fine. I think the problem may be with the default configuration of CentOS, mysql.sock is not present by default.

I had the same exact problem with Centos/7. I was using 2 virtualboxes one each for the web server and the database server. I had also installed the mysql database on my web server to be able to test local connectivity. When I used "localhost" as hostname in the database.php on the web server, it would work but once I switched it to 127.0.0.1 or 192.168.10.11(my static ip on a virtualbox linux instance on which I had installed the DB to check connectivity with remote database), I would get database connection errors. Someone on one of the forums I visited mentioned about SeLinux security settings being the issue and it was. So I had to do this on the web server to solve it:

sudo setsebool -P httpd_can_network_connect_db=1


This link provides a good explanation: https://www.axivo.com/resources/selinux-...lained.22/

Hope this helps others who are facing a similar problem.
this help me connect db on my webhosting from local
thanks  Heart Heart Heart
Reply




Theme © iAndrew 2016 - Forum software by © MyBB