如何调试 CodeIgniter 4 中的内部服务器错误?

问题描述 投票:0回答:1

当我尝试访问已部署的 CI 应用程序时,我在浏览器控制台中看到一个带有

500 Internal Server Error
的空白页面。尽管我尝试在 CI 文档中找到解决方案,但我仍然找不到获取记录的错误消息的方法,以便我可以看到实际发生的情况。

从我设置数据库那天起,

writable/logs
中只有一个日志文件。当我运行
composer install
php spark migrate --all
时,一切都很顺利,没有错误。

阿帕奇

我还通过暂时用静态 HTML 文件替换

public/index.php
来确保我的 Apache 配置正确设置,该文件按预期工作。权限也设置正确,Apache 对所有文件具有
rX
权限,对
rwX
目录具有递归
writable
权限。

CodeIgniter 配置

.env
中定义的API基本URL与实际URL匹配,即
https://sub.domain.com

app_baseURL = 'https://sub.domain.com/'

来自 CI 文档

将您的基本 URL 设置为 $baseURL。如果您需要更大的灵活性,可以在 .env 文件中将 baseURL 设置为 app.baseURL = 'http://example.com/'。始终在基本 URL 上使用尾部斜杠!

CodeIgniter 错误设置

虽然我发现了一个类似的问题,关于 如何解决旧版本 CodeIgniter 中的 500 个错误,但我找不到在 CodeIgniter 4 中执行相同操作的方法。但我确实在

app/Config/Boot/development.php
中找到了类似的东西:

/*
 |--------------------------------------------------------------------------
 | ERROR DISPLAY
 |--------------------------------------------------------------------------
 | In development, we want to show as many errors as possible to help
 | make sure they don't make it to production. And save us hours of
 | painful debugging.
 |
 | If you set 'display_errors' to '1', CI4's detailed error report will show.
 */
error_reporting(-1);
ini_set('display_errors', '1');

我用

error_reporting(E_ALL);
尝试过,但在
development
模式下我仍然没有看到任何错误。

.htaccess

当我尝试访问某个页面时,例如

https://sub.domain.com/login
,我从 Apache 收到 404 错误,所以我猜测是
public/.htaccess
导致了错误:

# Disable directory browsing
Options -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On

        # If you installed CodeIgniter in a subfolder, you will need to
        # change the following line to match the subfolder you need.
        # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
        # RewriteBase /

        # Redirect Trailing Slashes...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

        # Rewrite "www.example.com -> example.com"
        RewriteCond %{HTTPS} !=on
        RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
        RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

        # Checks to see if the user is attempting to access a valid file,
        # such as an image or css document, if this isn't true it sends the
        # request to the front controller, index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

        # Ensure Authorization header is passed along
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
        ServerSignature Off
# Disable server signature end

我也用

RewriteBase /
尝试过,但还是同样的问题。


如果您需要更多信息,请告诉我。

php apache .htaccess mod-rewrite codeigniter-4
1个回答
0
投票

请检查您的 /writable 文件夹的权限。

在 Linux 上修复它们的最简单方法是执行以下操作:

chown -R www-数据可写

请使用您的 Apache 运行的任何用户,因为它不是 www-data

然后验证您的 .env 文件是否将 CI_ENVIRONMENT 设置为开发,并且错误将显示在日志文件中

© www.soinside.com 2019 - 2024. All rights reserved.