简体   繁体   中英

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

I have a code which connects with mssql using freetds . It works perfectly when I run from command line. It fails when I run using nginx php-fpm through browser. The code is as follows:

 <?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);
  }

 ?>

Ok, In my case the problem was SELinux

Make sure these two variables are ON :

# 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:

setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1

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