Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm fighting with this for a day now, hope someone already faced with this problem and can help me out:

I have a CentOs server

[root@XXXXX ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)

which would be a webserver with PHP enabled (already installed, php-mssql package too)

[root@XXXXX ~]# php -i
PHP Version => 5.3.3
MSSQL Support => enabled
Library version => FreeTDS

There is an index.php with

$cn = mssql_connect($dbserver,$dbusername,$dbpassword) or die("Connection Error");

$dbserver, $dbusername, $dbpassword double checked.

If I call it from the browser it throws Connection Error, but if I compile it in terminal as root it works:

[root@XXXXX ~]# php /var/www/html/index.php
<h2> Result </h2>
Connection OK!Query OK!

I guess it's a missing permission from apache's account, but which?

Thanks for your help in advance!

share|improve this question
up vote 0 down vote accepted

If you're running with SELinux enabled (and you should) you will need to allow apache to communicate with the database, this can be done with:

setsebool -P httpd_can_network_connect on
setsebool -P httpd_can_network_connect_db on

These commands will take a few seconds to run so don't worry if they don't return immediately.

share|improve this answer
Thank you! It worked like a charm :) – Pho3nixHun Jan 9 '14 at 9:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.