Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
phpinfo()
PHP Version => 5.3.3
...
Configuration
...
mssql
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
<h1> SQL CONNECTION TEST: </h1>
<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

1 Answer 1

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 at 9:23

Your Answer

 
discard

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.