8

Hello everyone I am really new to ubuntu? I just brought a new ubuntu 14 machine. I successfully installed apache2 and php5 but unable to see any warnings or error messages on the browser even though i am generating the errors to see them.

Every thing was working good on my old windows machine with XAMPP.

Now I have set the following values into /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini

error_reporting = E_ALL | E_STRICT display_errors = On display_startup_errors = On

It does not show any errors until I use the following ini_set on each page ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

P.S. - I have also used echo php_ini_loaded_file(); which shows /etc/php5/apache2/php.ini

Please help me :'(

6
  • did you do a /etc/init.d/apache2 restart after editing the php.ini? +1 for using ubuntu instead of windows xampp Commented Mar 19, 2015 at 22:35
  • no but i did sudo service apache2 restart Would that affect? Commented Mar 20, 2015 at 16:03
  • It should. What shows your phpinfo() output for display errors? Commented Mar 20, 2015 at 16:06
  • I did your command to just now but no use nad my phpinfo() shows that there is no effect on php.ini error_reporting : 22527, display_errors: Off and same for startup errors Commented Mar 20, 2015 at 16:10
  • take a look at the path to php.ini listed in phpinfo(). Is it exactly the file you modified? Commented Mar 20, 2015 at 16:14

4 Answers 4

13

Check for the "loaded configuration file" in php.ini. If it is the same file then there must be some duplicate "display_errors = Off" line in your php.ini file in your bottom part. The later lines are always taken for execution. So search for all "display_errors" in your php.ini file and remove duplicates. And restart apache. Check phpinfo() output again to find about the "error reporting" variables.

Sign up to request clarification or add additional context in comments.

Comments

2

Here are the steps if you're dealing with PHP 7.4. You should be able to swap out the version number you're dealing with. Step 4 is probably the one you're missing.

  1. Create a file with the line php_ini_loaded_file(); in it.
  2. Visit that file. You should see something like /etc/php/7.4/fpm/php.ini
  3. Edit that file and find display_errors. Change the value to On
  4. Go to your terminal and run sudo service php7.4-fpm restart

Comments

0

Ok i had the same prob Ubuntu 22.04 and PHP 8.1.27. (Native PHP App) But i only mentionned : ini_set('display_errors', 1); In my index.php file which is something like a router to all other pages...

<?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';
}
?>

And it worked perfectly in every file i use.

Just shared the code to explain how my index.php handle all routing so it made the error reporting work on every single page.

Comments

0

My Solution under Ubuntu 24.4

cat /etc/php//8.3/apache2/php.ini | grep display_errors
cd /etc/php/8.3/apache2
cp php.ini php.ini_alt #Zur Sicherung der alten Datei
sed -i 's/display_errors = Off/display_errors = On/' php.ini #dadurch wird on Off durch On beim Wert display_errors ersetzt
sudo service apache2 restart

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.