Question

I have a PHP script that makes a connection to a remote SQL Server. From the command line as root I can call the freetds command: tsql –H hostname –U username and it connects just great and I can run queries.

I have a PHP script in /var/www/html/axis/public/test.php When I: sudo –u apache –s (change the user from root to apache) and then run my PHP script from the command line, it connects and runs the queries just great. But when executing the same script from the web browser, it fails - the browser returns a DB Connection error. The web browser is able to connect everywhere it is supposed to and renders all the web pages that don't need an SQL connection.

apache is the user that is running httpd. I’ve confirmed this via: ps aux | grep apache

Any ideas as to why apache can execute the PHP script fine from the command line, but when the browser attempts to connect to the very same script, it fails?

Thanks, Derrick

Was it helpful?

Solution 2

So the problem was with SELinux. The web server was forbidden from connecting outside the network (to the SQL Server). I had to run this command:

/usr/sbin/setsebool -P httpd_can_network_connect_db 1

Once that was done, all was well. This answer was provided with help from Daniel Fazekas. Thanks everyone for taking a look at this issue with me.

OTHER TIPS

As per the FreeTDS FAQ:

http://www.freetds.org/faq.html#php

Also can you post your connection code and what error's you're getting exactly?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top