MikeG
MikeG

Reputation: 31

PHP timeout when connecting to mssql under apache

PHP Version 5.4, Apache Version 2.4, CentOS 7.3

Trying to connect to mssql db using the following php code which works fine when I run it from the command line. However, when I place code under apache (on same server) and call through browser I get a timeout error.

Error: Connection failed: SQLSTATE[HYT00] SQLConnect: 0 [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired+

set_time_limit(30);
echo "+ Connection\n";
try {
    $pdo = new PDO("odbc:sqlsrv_msodbc", "username", "password");
    } catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    }

Upvotes: 3

Views: 1399

Answers (1)

Sean256
Sean256

Reputation: 3099

I just had the same issue. I am using CentOS 7.3 in vagrant and solved it by disabling SELinux.

If you're on a dev environment and disabling SELinux is cool you can do it by:

sudo vi /etc/sysconfig/selinux

Set

SELINUX=disabled

I found this over at serverfault: https://serverfault.com/questions/240015/how-do-i-allow-mysql-connections-through-selinux

Upvotes: 2

Related Questions