大家好,我是 ubuntu 的新手吗? 我刚刚带来了一台新的 ubuntu 14 机器。 我成功安装了 apache2 和 php5,但无法在浏览器上看到任何警告或错误消息,即使我生成错误来查看它们。
在我的旧 Windows 机器上使用 XAMPP 一切都运行良好。
现在我已将以下值设置为
/etc/php5/apache2/php.ini and /etc/php5/cli/php.ini
error_reporting = E_ALL | E_STRICT
display_errors = On
display_startup_errors = On
在每个页面上使用以下 ini_set 之前,它不会显示任何错误
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
附注- 我还使用了
echo php_ini_loaded_file();
显示
/etc/php5/apache2/php.ini
请帮助我:'(
检查php.ini中是否有“加载的配置文件”。如果是同一个文件,那么底部的 php.ini 文件中一定有一些重复的“display_errors = Off”行。后面的行总是被执行。因此,在 php.ini 文件中搜索所有“display_errors”并删除重复项。并重新启动阿帕奇。再次检查 phpinfo() 输出以查找“错误报告”变量。
如果您使用的是 PHP 7.4,请执行以下步骤。您应该能够交换正在处理的版本号。第 4 步可能是您所缺少的。
php_ini_loaded_file();
。/etc/php/7.4/fpm/php.ini
display_errors
。将值更改为 On
sudo service php7.4-fpm restart
好吧,我也有同样的问题 Ubuntu 22.04 和 PHP 8.1.27。 (本机 PHP 应用程序) 但我只提到: ini_set('display_errors', 1); 在我的 index.php 文件中,它就像所有其他页面的路由器......
<?php
ini_set('display_errors', 1);
$request = strtok($_SERVER['REQUEST_URI'], '?');
$viewDir = 'views/';
// Define routes with regular expressions to capture dynamic parts
$routes = array(
'' => array(
'view' => 'home.php',
'pattern' => '/^\/\/?$/'
),
'/home' => array(
'view' => 'home.php',
'pattern' => '/^\\/home$/'
),
'/about' => array(
'view' => 'about.php',
'pattern' => '/^\\/about$/'
),
....
function matchRoute($request, $routes)
{
foreach ($routes as $route => $details) {
if (preg_match($details['pattern'], $request, $matches)) {
return array('view' => $details['view'], 'matches' => $matches);
}
}
return null;
}
// Match the request URI to a route
$routeMatch = matchRoute($request, $routes);
if ($routeMatch !== null) {
$view = $routeMatch['view'];
require $viewDir . $view;
} else {
// Handle 404
http_response_code(404);
require $viewDir . '/404.php';
}
?>
它在我使用的每个文件中都完美运行。
刚刚分享了代码来解释我的index.php如何处理所有路由,以便它使错误报告在每个页面上工作。