MySQL连接无法在Perl CGI脚本中运行 [英] MySQL connection not working from within Perl CGI script

查看:72
本文介绍了MySQL连接无法在Perl CGI脚本中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Perl脚本中的DBI模块轻松地连接到远程MySQL服务器.但是,当我尝试在CGI脚本中使用相同的连接设置/属性时,连接将失败.

I can easily connect to a remote MySQL server using the DBI module in my Perl scripts. However, when I try to use the same connection settings/properties from within a CGI script, the connection fails.

尽管使用apache错误日志或浏览器,也没有记录有用的错误/警告

There are no helpful errors/warnings being logged either in the apache error log, or the browser, in spite of using

use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

奇怪的是,当从终端执行时,完全相同的脚本可以正常工作.我还尝试将CGI脚本连接到本地主机上的MySQL服务器,但没有成功.

Strangely, the exact same script works fine when executed from the terminal. I also tried connecting the CGI script to the MySQL server on localhost, but without any success.

另一方面,phpMyAdmin在计算机上运行良好.

On the other hand, phpMyAdmin works great on the machine.

我正在使用CentOS 5.8版.我怀疑这是apache用户或OS上其他任何地方的系统/特权问题,但是已经走到了尽头.

I'm using CentOS Release 5.8. I'm suspecting it is a system/priveleges issue with the apache user or anywhere else on the OS, but have hit a dead end.

任何指针将不胜感激!

非常感谢.

我正在使用以下连接字符串

$dbh = DBI->connect($ds, $uname, $pwd,{RaiseError => 1 }) or die "$DBI::errstr Could not connect: $!<br>";

推荐答案

修复了该问题.如果对Linux管理不太熟悉的人遇到类似的问题,这就是发生的事情.我的CentOS机器上的安全系统"selinux"禁止httpd建立与远程MySQL服务器的网络连接.必须使用以下命令明确启用它

Fixed it. In case anyone not too familiar with Linux administration faces similar issue, here's what had happened. The security system 'selinux' on my CentOS machine was prohibiting the httpd to establish network connection to the remote MySQL server. It had to be explicitly enabled with the following command

setsebool -P httpd_can_network_connect=1

您可以在此处阅读有关selinux的更多信息:

One can read more about selinux over here:

http://wiki.centos.org/HowTos/SELinux

这篇关于MySQL连接无法在Perl CGI脚本中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆