3

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();
    }
2
  • Please use set_time_limit(0); Commented Feb 7, 2017 at 10:48
  • Hi - tried that but got same error result. Commented Feb 7, 2017 at 10:53

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Sean256! That worked. Wow - never thought of it.
No problem! Mind giving a brother a correct answer mark?
Trying! Don't have the reputations yet!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.