32

I am running nginx with php5-fpm and want to enable the display_errors. I am running a virtual host, so please help in making a way to enable display_errors , display_startup_errors.

I tried modifying /etc/php5/fpm/php.ini.

;display_errors
Default Value: On
Development Value: On
;Production Value: Off 
;display_startup_errors
Default Value: On
Development Value: On
;Production Value: Off
;error_reporting
Default Value: E_ALL
Development Value: E_ALL
;Production Value: E_ALL & ~E_DEPRECATED
;html_errors
Default Value: On
Development Value: On
;Production value: Off
;log_errors
Default Value: On
Development Value: On
;Production Value: On

Is it require to have multiple ini files for each different virtual host, does vhost makes any difference for php configuration ?

I am also trying set_ini() , but it is not showing any effect. And I restarted nginx and php5-fpm after making changes in php.ini file.

1
  • check your phpinfo() output for your php.ini - keep in mind php ini values can be overridden at "additional ini (dir) files", at php-fpm.conf file, at .user.ini files and of course inside executed php script files Commented Apr 6, 2016 at 16:10

5 Answers 5

49

The php.ini does nothing for php-fpm.

If you are using php-fpm: You must provide the configuration change in the fpm pool config associated with your web application. Where these are located depends on your system. The probably locations are:

  • /etc/php-fpm.d/mydomain.conf (if things have been set up neatly)
  • /etc/php-fpm.conf (if you are only using one conf for php-fpm)

Your config paths are different from mine, so poke around to see what you have in there. Don't make changes in /etc/php-fpm.conf if a suitable conf exists in /etc/php-fpm.d/.

If you are not using php-fpm: Update php.ini with the correct configuration.

Correct your configuration: In the configuration shown in the question, you have uncommented documentation rather than provided the correct settings. You had better undo those changes, because PHP won't understand them.

The correct lines for php-fpm are:

    ; enable display of errors
    php_flag[display_errors] = on
    php_flag[display_startup_errors] = on

The correct lines for normal php are:

    ; enable display of errors
    display_errors = On
    display_startup_errors = On

Advice: Do not use these options in a production environment. Best wishes.

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

5 Comments

Note, add these in ; FPM Configuration ; not under ; Global Options ;
Why? I add php_flag[html_errors]=off under ; FPM Configuration ;, but I find it not work:php-fpm -i |grep html_errors html_errors => On => On
For some reason, I had to use php_admin_flag instead of php_flag, hope this helps someone in the same boat as me
Is this specific to nginx or PHP 5? Or perhaps distro specific? I run apache2 + php-fpm on Rocky Linux (a CentOS derivative), in my case PHP 7, and it loads the settings in php.ini. The only difference is that restarting httpd doesn't force a reload of php.ini, and to that end you need to restart php-fpm. It seems odd to me that it would ignore this file, at least the way my system is set up the php-fpm configuration files are minimal and it still uses php.ini for most settings.
@cazort I believe php-fpm will load /etc/php/7.4/fpm/php.ini, or similar according to your distribution. Unfortunately, I am not current on this, so YMMV.
12

If you have /etc/php5/fpm/php.ini (used in Debian, Ubuntu style config) then changes to this file should take effect, and that configuration may be further overridden per pool by making changes to specific /etc/php5/fpm/pool.d/*.conf files.

Comments

7

In my case Zend errors and NGinX - php5 fpm, work like this:

Only I put in public/index.php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

Without If(){...}

But If only to put above code, display error, will give this:

Parse error: syntax error, unexpected '}', expecting ',' or ';' in /usr/local/nginx/html/ZendSkeletonApplication/module/Album/src/Album/Controller/AlbumController.php on line 12

Another thing! Set up this code:

'display_not_found_reason' => true,
'display_exceptions'       => true,

in module.config.php like this:

'view_manager' => array(
     'template_path_stack' => array(
         'album' => __DIR__ . '/../view',
         'display_not_found_reason' => true,
         'display_exceptions'       => true,
     ),
 ),

I get all errors of an error.log on screen:

Fatal error: Uncaught exception 'Zend\View\Exception\InvalidArgumentException' with message 'Invalid path provided; must be a string, received boolean' in /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/View/Resolver/TemplatePathStack.php:201 Stack trace: #0 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/View/Resolver/TemplatePathStack.php(149): Zend\View\Resolver\TemplatePathStack->addPath(true) #1 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/Mvc/Service/ViewTemplatePathStackFactory.php(38): Zend\View\Resolver\TemplatePathStack->addPaths(Array) #2 [internal function]: Zend\Mvc\Service\ViewTemplatePathStackFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'viewtemplatepat...', 'ViewTemplatePat...') #3 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(939): call_user_func(Array, Object(Zend in /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 946

I didn't touch config file as php-fpm in system (Ubuntu 14.04).

Comments

3

An update for PHP-FPM 7 (under Debian)

  1. Go to /etc/php/[VERSION]/fpm/pool.d
  2. Edit the file www.conf (or in case if you have set up other pools, edit those).
  3. You want php_flag[display_errors] = on
  4. Restart with sudo service php[VERSION]-fpm restart

Comments

0

In ubuntu 22.04 you just need to add these lines on the top of your PHP file

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

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.