nginx-php-fpm不使用freetd,但使用php


nginx php-fpm not working with freetds but working with php

我有一个代码,它使用freetdsmssql连接。当我从命令行运行时,它工作得很好。当我通过浏览器使用nginx php-fpm运行时,它失败了。代码如下:

 <?php
  $host = "myhost";
  $user = "username";
  $pass = "password";
  $db = "database";
  $table = "user";
  try {
    $conn = mssql_connect($host, $user, $pass);
    mssql_select_db( $db, $conn );
    $query = "SELECT COUNT(*) FROM [".$db."].[dbo].[".$table."]";
    $query_result = mssql_query( $query , $conn );
    echo "The count of ".$table." is: ";
    $result =  mssql_result ($query_result,0,0);
    var_export($result);
    mssql_close($conn); // close connection
  } catch (Exception $e) {
    throw new Exception("The script exited with an exception    ===========================".PHP_EOL." ERROR TYPE ------------> ".$e);
  }
 ?>

好的,在我的情况下,问题是SELinux

确保这两个变量为ON:

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

如果它们未打开,则启用它们:

setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1