php Codeigniter 空白页和 apache 日志中的错误 500?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15588813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter blank page and error 500 in apache log?
提问by LF4
I spent over 5 hours yesterday trying to figure out whats wrong with my setup. In the ci213/application/controllers and views directories I have a simple site.php controller and test.php view. I'm out of ideas as to why this site wont load. Anyone have suggestions on what I could look for next? Maybe logging it's working properly? If I could get better log errors I could have more to work with.
昨天我花了 5 个多小时试图找出我的设置有什么问题。在 ci213/application/controllers 和 views 目录中,我有一个简单的 site.php 控制器和 test.php 视图。我不知道为什么这个网站不会加载。有人对我下一步可以寻找什么有建议吗?也许记录它工作正常?如果我能得到更好的日志错误,我就可以有更多的工作。
I figured it has to be something with codeigniter since I have an index.php and index.html at apaches root (/var/www) and also an index2.php at the sites root (/var/www/vhosts/srp-local/htdocs), when I go to localhost/index.(php|html) or srp-local/index2.php the pages load and display properly so php and apache are working.
我认为它必须与 codeigniter 有关,因为我在 apaches 根 (/var/www) 处有一个 index.php 和 index.html,在站点根 (/var/www/vhosts/srp-local) 处也有一个 index2.php /htdocs),当我转到 localhost/index.(php|html) 或 srp-local/index2.php 时,页面加载并正确显示,因此 php 和 apache 正在工作。
Trying to load the site I get a blank page so I figured it has to be something with CI. I'm tailing all the log files and the only one that gets an update is the site access.log with the following error.
尝试加载网站时,我得到了一个空白页面,所以我认为它必须与 CI 相关。我正在跟踪所有日志文件,唯一获得更新的是站点 access.log,但出现以下错误。
127.0.0.1 - - [23/Mar/2013:09:00:28 -0600] "GET / HTTP/1.1" 500 381 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0"
config.php
配置文件
$config['base_url'] = 'http://srp-local/'; # My hosts file is configured for this.
$config['log_threshold'] = 4;
$config['log_path'] = '/var/www/vhosts/srp-local/logs/ci_error.log';
controllers/site.php
控制器/site.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller
{
public function index()
{
$this->load->view('test');
}
}
views/test.php
意见/test.php
<html>
<head>
</head>
<body>
<?php echo "PHP is working and the 'test' view was loaded"; ?>
</body>
</html>
Apache Root
阿帕奇根
/var/www/vhosts
$ ll
drwxrwsr-x 6 krizzo www-data 4096 Mar 22 10:45 it355
drwxrwsr-x 6 krizzo www-data 4096 Mar 22 17:45 srp-local
htdocs is the webroot for srp-local and it's index.php is referred to the ci213 folder.
htdocs 是 srp-local 的 webroot,它的 index.php 被引用到 ci213 文件夹。
/var/www/vhosts
$ ll srp-local/
drwxrwsr-x 2 krizzo www-data 4096 Mar 22 17:06 cgi-bin
drwxrwsr-x 4 krizzo www-data 4096 Mar 22 17:14 ci213
drwxrwsr-x 2 krizzo www-data 4096 Mar 22 17:19 logs
drwxrwsr-x 5 krizzo www-data 4096 Mar 22 17:26 htdocs
All log locations/permissions
所有日志位置/权限
/var/log/apache2/
-rw-rw-rw- 1 www-data adm 0 Mar 23 08:52 php_errors.log
-rw-r----- 1 root adm 12191 Mar 23 09:32 access.log
-rw-r----- 1 root adm 4858 Mar 23 09:32 error.log
/var/www/vhosts/srp-local/logs/
-rw-r--r-- 1 root www-data 3227 Mar 22 19:42 error.log
-rw-rw-r-- 1 krizzo www-data 0 Mar 23 09:37 ci_error.log
-rw-r--r-- 1 root www-data 12983 Mar 23 09:38 access.log
php.ini file settings
php.ini 文件设置
error_reporting = E_ALL & ~E_DEPRECATED
log_errors = On
error_log = /var/log/apache2/php_errors.log
回答by LF4
I finally found something that pointed me in the right direction. These two posts mentioned how CI uses the @ in the database module might be causing that issue.
我终于找到了一些指向正确方向的东西。这两篇文章提到 CI 如何在数据库模块中使用 @ 可能会导致该问题。
php return 500 error but no error log
CodeIgniter project loads blank webpage
php 返回 500 错误但没有错误日志
CodeIgniter 项目加载空白网页
I disabled auto-loading the database module and the site works. Now I just have to figure out the database error I was getting that might be causing CI to fail. I'll update this answer once I figure it out.
我禁用了自动加载数据库模块,站点正常工作。现在我只需要弄清楚我得到的可能导致 CI 失败的数据库错误。一旦我弄清楚了,我会更新这个答案。
Update:I checked the account/password and access for the database everything was working. The issue was the php mysql driver was not installed. This is my first time really using an Ubuntu system and I thought that the mysql driver would be installed with the default php package, which I was incorrect about.
更新:我检查了帐户/密码和数据库访问权限,一切正常。问题是未安装 php mysql 驱动程序。这是我第一次真正使用 Ubuntu 系统,我认为 mysql 驱动程序将与默认的 php 包一起安装,我错了。
After installing php5-mysqlnd and enabling the database library in CI's autoload everything works properly now. The fact that I was not getting any errors is really making me consider changing frameworks.
安装 php5-mysqlnd 并在 CI 的自动加载中启用数据库库后,现在一切正常。我没有收到任何错误这一事实确实让我考虑更改框架。
回答by jahackbeth
Posting this, just in case it helps somebody...
If you are on a shared hosting platform and do not have access to directories other than where you are supposed to host your files: the trick was to force php to throw all errors even if apache could not.
发布这一点,以防万一它可以帮助别人......
如果你是一个共享的主机平台上,并没有获得比你应该在哪里托管文件的其他目录:诀窍是力的PHP抛出即使所有错误阿帕奇不能。
Open "index.php" that resides in the root folder of your codeigniter installation;
打开位于 codeigniter 安装根文件夹中的“index.php”;
define('ENVIRONMENT', 'development');
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
/*added line below*/
ini_set('display_errors', '1');
break;
......
Making the above change immediately started displaying what was wrong with the code and I was able to fix it and get it up and running.
进行上述更改后立即开始显示代码的问题,我能够修复它并启动并运行它。
Don't forget to set your codeigniter environment to "production" once you're done fixing it.
完成修复后,不要忘记将 codeigniter 环境设置为“生产”。
回答by Aswin Kumar
Here is another reason why errors might not be visible:
这是错误可能不可见的另一个原因:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENTvariable defined in index.phpwas set to 'production'. This caused error_reportingto be set to 0 (no logging). Just set it to 'development'and you should start seeing error messages in apache log.
我遇到过同样的问题。就我而言,我从生产环境复制了源代码。因此,中ENVIRONMENT定义的变量index.php设置为'production'。这导致error_reporting设置为 0(无日志记录)。只需将其设置为'development',您就应该开始在 apache 日志中看到错误消息。
Turned out the 500 was due to a semi colon missing in database config :-)
原来 500 是由于数据库配置中缺少一个分号:-)
回答by alemol
In my case (a cart class) it was a matter of URL, look at
在我的情况下(购物车类)这是一个 URL 问题,看看
/var/log/apache2/error.log
if you have something like
如果你有类似的东西
[client 127.0.0.1] File does not exist: ...
Then you have to prefix your class name by '/index.php/' like this
然后你必须像这样在你的类名前加上'/index.php/'
http://localhost/codeigniter/index.php/cart
回答by Ando
I was also struggling with this issue.
我也在为这个问题而苦苦挣扎。
On my new server i didn't have the php mb_stringmodule installed.
在我的新服务器上,我没有php mb_string安装该模块。
yum install php-mbstringand then service httpd restart
yum install php-mbstring进而 service httpd restart
回答by Regolith
回答by Shashank Saxena
I checked the php version which was 7.0.xx so I downgraded to php 5.6.xx and used the following steps to get it working for me.
我检查了 7.0.xx 的 php 版本,所以我降级到 php 5.6.xx 并使用以下步骤让它为我工作。
sudo a2dismod proxy_fcgi proxy; sudo service apache2 restart
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0


