简体   繁体   中英

mssql_connect(): Unable to connect to server through Apache

I'm trying to connecto to a MSSQL server through mssql_connection from Apache in a CentOS. This is the script:

<?php

$link = mssql_connect('10.10.10.10', 'XXXXXXX', 'YYYYYYYYY');

if (!$link || !mssql_select_db('Utilities', $link)) {
    echo mssql_get_last_message();
}

If I run this script through command line, I get the connection. But when I access it as a page through Apache, I get the error

Warning: mssql_connect(): Unable to connect to server: 10.10.10.10 in /var/www/html/pruebas/pruebas/sql.php on line 4

At the beginning I thought the problem was that, being the server behind a proxy, but even when I don't configure my account to use that proxy, I still can connect through the command line but not through apache.

Most likely it's due to SELinux preventing Apache (and therefore all Apache modules) from making remote connections by default.

To check that run

$ getsebool -a | grep httpd_can_network_connect
httpd_can_network_connect --> on
httpd_can_network_connect_db --> on

and to enable them if they are not on, do

$ setsebool -P httpd_can_network_connect 1
$ setsebool -P httpd_can_network_connect_db 1

If it's not that, then check that you have php-mssql installed to begin with

yum install php-mssql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM