Abdullah Shahin Abdullah Shahin - 1 year ago 116
Apache Configuration Question

mysqli doesn't connect under apache

I have a php application based on codeigniter, and I have a database that is located on remote host with required database installed, setup proper mysql permissions and with mysql port open for remote connections, however, when I run the application it doesn't work and it returns 500 error code.

When I troubleshoot the problem, it gives below error

Message: mysqli::real_connect(): (HY000/2003): Can't connect to MySQL server on '' (13)

what I have tried so far:

1) make sure all permissions are set correctly.

2) make sure no network related issues are existed such as blocked ports/hosts

3) make sure mysqli is installed and enabled.

4) created a connection test php script and ran it from the command line and it works just fine.

5) the fun part was when I ran the application from command line and it worked correctly as root user and as apache user as
su -s /bin/sh apache -c "php index.php".

parameters I have:

1) php version is PHP 5.4.16

2) OS version: CentOS Linux release 7.2.1511 (Core) on both web and DB

3) web server version Apache/2.4.6 (CentOS)

4) mysql Ver 14.14

5) I run my app under ssl, and below is my configurations

<VirtualHost *:443>

#### Gloabl config
DocumentRoot /var/www/bein
DirectoryIndex index.php
ServerName beinmob.com
ServerAlias www.beinmob.com
#### change basic URL to /index.php/POS_Admin/Session
RewriteEngine on
RewriteRule ^/?$ index.php/POS_Admin/Session [R]
#### change url to alias for web services
Alias /web-services /var/www/bein/index.php
Alias /POS_Admin /var/www/bein/
#### Basic Authentication for /web-services url
<Location /POS_Admin>
RewriteEngine on
# Hide the application and system directories by redirecting the request to index.php
RewriteBase /index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
<Location /web-services>
AuthName bein
AuthType Basic
AuthUserFile /etc/httpd/conf.d/beinServicePass
Require valid-user
#### SSL configuration
SSLEngine on
SSLCertificateFile /etc/httpd/cert/certs/www_beinmob_com.crt
SSLCertificateKeyFile /etc/httpd/cert/certs/www_beinmob_com.key
SSLCertificateChainFile /etc/httpd/cert/certs/DigiCertCA.crt

Answer Source

Check this it should solve your problem .

Update because the link may become dead if that page moves or is deleted

Login as root and do

setsebool -P httpd_can_network_connect=1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download