简体   繁体   English

Ubuntu上的PHP从命令行加载MSSQL扩展,但在通过Apache运行时不加载

[英]PHP on Ubuntu loads MSSQL extension from command line but NOT when run through Apache

I've been searching and trying for quite a while to find an answer, so will finally ask here. 我一直在寻找并尝试了很长一段时间才找到答案,所以最后会问这里。

I have a UBUNTU install from Turnkey LINUX, PHP Ver 5.6.23. 我从Turnkey LINUX安装了UBUNTU,PHP Ver 5.6.23。 I have compiled and enabled mssql.so as I require to connect to a MSSQL server. 我已经编译并启用了mssql.so,因为我需要连接到MSSQL服务器。

My simple connect PHP script is so: 我的简单连接PHP脚本是这样的:

$server = 'rslocal';

$connect = mssql_connect($server, 'sqluser', 'sqlpassword');

if (!$connect) {
    echo 'can not connect';
}

I can run the above PHP script from the command line and it is successful. 我可以从命令行运行上面的PHP脚本,但它很成功。
I can also run the FreeTDS tsql utility and connect and query the server from the command line 我还可以运行FreeTDS tsql实用程序,并从命令行连接并查询服务器

When I run it from the browser through Apache, it tells me Fatal error: Call to undefined function mssql_connect() ... 当我从浏览器通过Apache运行它时,它告诉我致命错误:调用未定义的函数mssql_connect()...

I have checked that php --ini (cli) and phpinfo() (browser) both report the same ini file in use. 我已经检查过php -ini(cli)和phpinfo()(浏览器)都报告了正在使用的相同ini文件。

I am not running SELinux so the setbool commands are not relevant here, however the problems stated by others where SELinux WAS the issue are exactly the same as mine, so perhaps this is a place to start. 我没有运行SELinux,所以setbool命令在这里不相关,但SELinux WAS问题的其他人所说的问题与我的完全相同,所以也许这是一个开始的地方。

My feeling is that it is a security policy or something stopping the extension from loading any function that wants to communicate with an outside server, but I am stuck. 我的感觉是,它是一个安全策略或某些东西阻止扩展加载任何想要与外部服务器通信的功能,但我被卡住了。

Any help would be appreciated. 任何帮助,将不胜感激。

I found the "answer". 我找到了“答案”。 On this distro, Ubuntu 14.x, the command 在这个发行版,Ubuntu 14.x,命令

sudo apachectl restart

doesn't seem to be enough to reload php. 似乎不足以重新加载PHP。 The php.ini change, specifically adding extension=mssql.so had not been not applied when run through apache. php.ini更改,特别是添加extension = mssql.so时,在通过apache运行时尚未应用。 This raises the question how to "hard" restart Apache so php.ini changes take, but that's a different question. 这提出了一个问题,如何“硬”重启Apache,所以php.ini更改了,但这是一个不同的问题。 I only noticed that it worked after a reboot. 我只注意到重启后它才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM