JQUERY,PHP post错误500(服务器内部错误)


JQUERY & php post error 500 (server internal error)

我在开发的web应用程序中遇到了一个错误,我确信这是相当基本的错误。

每当我在web上运行这段代码时,chromium调试器都会返回这个错误:

 POST http://my_ip/server_wrapper.php 500 (Internal Server Error) 
    PHP服务器工作正常,phpinfo()返回全部信息正确
  1. web服务器是Apache。
  2. Iptables是完全打开的,我只是在局域网下使用它。
  3. web根目录下所有文件的权限为755。

这是JQUERY, js文件片段"

this.post    = function () {
 $.post ("server_wrapper.php",
  {
   _id:          this.id,
   _question:    this.question,
   _type:        "none"
  },
  function (data, status) {
   alert ("DATA: " + data + " status: " + status);
  }
 );
}

下面是php文件:

<?php
if (isset($_POST["_question"]) && isset($_POST["_type"]) && isset($_POST["_id"])) {
$question = $_POST["_question"];
$type     = $_POST["_type"];
$id       = $_POST["_id"];
$con      = mysqli_connect ("localhost", "user", "pass", "database");
if (mysqli_connect_errno($con)) {
    echo "Failed to connecto to db";
} else {
    mysqli_query ($con, "INSERT INTO questions (id, question, type) VALUES ('$id','$question','$type')");
}
mysqli_close ($con);
 }
?>
<标题>编辑

这是日志反复返回的内容:

PHP Fatal error:  Call to undefined function mysqli_connect() in /var/www/server_wrapper.php

显示页面错误:

<?php
    ini_set('display_errors', '1');
    ini_set('error_reporting', E_ALL);
?>

首先会在页面上显示错误,而不是生成500个错误。

Second将确保报告所有错误。这包括通知。

建议:编写甚至不触发一个通知的代码

查找PHP错误日志文件:

grep error_log /etc/php.ini
grep ^error_log /etc/php.ini

在RedHat系列服务器上安装MySQL:

yum install mysql.x86_64
yum install mysql mysql-server
chkconfig --level 2345 mysqld on
service mysqld start
mysqladmin -u root password somepassword

如果你想获得最新的PHP版本,我建议你使用下面的reppos

wget http://mirrors.coreix.net/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
安装:

rpm -Uvh remi-release-*.rpm epel-release-*.rpm
/bin/rm epel-release-*.noarch.rpm remi-release-*.rpm
perl -pi -e 's/enabled=0/enabled=1/g' /etc/yum.repos.d/remi.repo
yum update (optional - not recommended unless you know what you are doing)
yum install yum-plugin-priorities

确保你在安装了repos后编辑了它们,并将enabled设置为0,这样你就可以选择性地使用它们了。

yum --enablerepo=remi,epel install whatever

看起来mysqli扩展没有安装或启用。检查php.ini中的extension=mysqli.so行,否则启用它或使用sudo apt-get install php5-mysql

安装它。