Page 1 of 1

How to set display_errors On

Posted: Tue Jul 06, 2010 11:20 pm
by jcobban
I have the following php.ini file in the public_html directory on my development system but none of the settings take effect.

include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/jcobban/php"
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
magic_quotes_gpc = "0"
extension="suhosin.so"
suhosin.post.max_vars = 2000
suhosin.request.max_vars = 5000
display_errors = "On"

I have tried debugging a page by adding the line:

Code: Select all

     ini_set("display_errors", "On");
But this apparently does not get processed if the PHP processor is unable to parse the whole page. I have tried running the page under Eclipse, but no error messages are displayed there. So I apparently need to be able to set display_errors for the site, but it just doesn't take. and neither do any of the other options in my php.ini. So how do I get the php.ini to work?

Re: How to set display_errors On

Posted: Tue Jul 06, 2010 11:46 pm
by requinix
Make sure you're editing the right php.ini: phpinfo can tell you a lot about your installation.

If you're running PHP as a module then the webserver needs to be reloaded/restarted after making changes. If you're using Apache then you can add

Code: Select all

php_value display_errors 1
in your root .htaccess file.

Otherwise, if you running it as a [Fast]CGI program, you probably won't need to restart. For per-directory changes create a php.ini file and put in it whatever you'd want to see in the global php.ini file. That is,

Code: Select all

display_errors = on

Re: How to set display_errors On

Posted: Wed Jul 07, 2010 6:01 pm
by jcobban
tasairis wrote:Make sure you're editing the right php.ini: phpinfo can tell you a lot about your installation.

If you're running PHP as a module then the webserver needs to be reloaded/restarted after making changes. If you're using Apache then you can add

Code: Select all

php_value display_errors 1
in your root .htaccess file.

Otherwise, if you running it as a [Fast]CGI program, you probably won't need to restart. For per-directory changes create a php.ini file and put in it whatever you'd want to see in the global php.ini file. That is,

Code: Select all

display_errors = on
It is through running phpinfo that I know the php.ini is not taking effect. The phpinfo page and the php.ini file are in the same directory. I have restarted the server several times since adding the display_errors value. In any event, as I said, none of the values in the php.ini file are taking effect.

Note that this is only in my development web server on my own computer. The same php.ini file, missing only the display_errors setting, is in my production website. But there it works! I just copied that php.ini file from my production server to my development server and restarted the development server. Again none of the settings in the php.ini file take effect, as shown by phpinfo run in the same directory.

Re: How to set display_errors On

Posted: Wed Jul 07, 2010 6:24 pm
by jcobban
I am completely confused by the documentation of how to perform configuration. I know that on my productions server this is modified by the php.ini file in the public/html directory. But this does not work on my local server. Both are running on Linux, but when I look at the two phpinfo pages they are completely different, and I have no understanding of what is going on.

The key difference it would appear is that on my production server the "Server API" field says "CGI". But on my development server it says "Apache 2.0 Handler". I don't know why they are different, or what this difference means, but it would seem to go along with confusing statements that "on Apache you use .htaccess".

So I have tried .htaccess, and it doesn't work either! My .htaccess file consists of:

<IfModule mod_php6.c>
include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/jcobban/php"
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
magic_quotes_gpc = "0"
extension="suhosin.so"
suhosin.post.max_vars = 2000
suhosin.request.max_vars = 5000
display_errors = "On"
</IfModule>

It is just too bloody confusing to have one configuration method on my development web site and a completely different configuration method on my production web site. I want to use the same configuration method on both. Why can't I? And why is it so bloody difficult to find any configuration method that actually works!

Re: How to set display_errors On

Posted: Wed Jul 07, 2010 10:12 pm
by requinix
Okay. From the top.

Your production server is running PHP the most secure way possible and that's via CGI (likely FastCGI to be specific). It's like calling the php program with a script name every time a script needs to be run, but more efficient. You can configure PHP on a per-directory level by putting a php.ini in a directory and PHP will read and parse each one.

Your development server is running PHP the easiest way and that's via a handler in Apache. Every time Apache sees a .php file it knows to call this one module and that will handle the rest. To configure PHP there you put stuff in a .htaccess file using a php_value directive.

Both are configured from a base php.ini file somewhere. If you run phpinfo() it'll tell you right at the top of the output where this file is. There is where you need to set display_errors=on - just for the development server.
jcobban wrote:And why is it so bloody difficult to find any configuration method that actually works!
Because you're not looking in the right places. Places such as Google or the PHP manual.

Re: How to set display_errors On

Posted: Thu Jul 08, 2010 7:57 pm
by jcobban
tasairis wrote:Okay. From the top.

Your production server is running PHP the most secure way possible and that's via CGI (likely FastCGI to be specific). It's like calling the php program with a script name every time a script needs to be run, but more efficient. You can configure PHP on a per-directory level by putting a php.ini in a directory and PHP will read and parse each one.

Your development server is running PHP the easiest way and that's via a handler in Apache. Every time Apache sees a .php file it knows to call this one module and that will handle the rest. To configure PHP there you put stuff in a .htaccess file using a php_value directive.

Both are configured from a base php.ini file somewhere. If you run phpinfo() it'll tell you right at the top of the output where this file is. There is where you need to set display_errors=on - just for the development server.
jcobban wrote:And why is it so bloody difficult to find any configuration method that actually works!
Because you're not looking in the right places. Places such as Google or the PHP manual.
Thank you for the explanation of what the different Server API settings mean. However the existence of all of these different configurations is not a good reason for requiring each configuration to have a different configuration mechanism. Why could they not all use a single configuration mechanism so users would not have to know so much about how their system was configured?

In any event the documentation that you point me to is vague and incomplete. For example you point me to the PHP manual. But under configuration there are only 4 section headings, none of which, by their titles, would suggest that they describe per-directory configuration. Only when I finally get to the fourth section do I find anything that seems applicable. However this section assumes knowledge that I do not have, and that should not be expected of users of PHP, that is information on how the Server is configured. Most users of PHP are not themselves the administrators of their web server, and even if they are, for example myself with respect to the Apache server running on my own computer, that does not mean that they are knowledgeable about the server. I did not configure the Apache and PHP servers on my computer, the Ubuntu install did. So this section of the PHP manual is deficient in that it does not include an explanation of how the PHP user can determine the mode of operation of their server, and hence where the configuration options should be put.

Having determined, by using phpinfo that the Ubuntu install has configured PHP 5 to run with Server Api = 'Apache 2.0 Handler ', this 4th section of the manual directs me to the .htaccess file. So I put my PHP settings into a .htaccess file, and they still do not take effect!

I have now tried putting my options in php.ini, .user.ini, and .htaccess, and every attempt has been an unmitigated failure. The documentation is clearly at fault if a reasonably experienced programmer cannot get something this basic to work! So let's just assume that I am completely ignorant, and just explain to me why the following .htaccess file does nothing, and what I have to do to get it to work.

<IfModule mod_php5.c>
include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/jcobban/php"
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
magic_quotes_gpc = "0"
extension="suhosin.so"
suhosin.post.max_vars = 2000
suhosin.request.max_vars = 5000
display_errors = "On"
</IfModule>

Re: How to set display_errors On

Posted: Thu Jul 08, 2010 8:11 pm
by requinix
Yes, clearly the documentation on the installation and configuration of PHP into a web server should be geared towards novices who know not what they are doing. It's unfortunate that the manual is geared towards the people who should be taking care of all this instead of those who simply benefit from its existence.

Ask whoever set up your production environment to do it for your development environment too.

Re: How to set display_errors On

Posted: Mon Jul 12, 2010 9:51 am
by jcobban
My production environment is on an ISP. There is no way they will accept responsibility for the Apache server on my own home computer.

Re: How to set display_errors On

Posted: Mon Jul 12, 2010 10:21 am
by liljester
phpinfo() should give a path to the php.ini that php is using. on my ubuntu server, phpinofo gives this:

Configuration File (php.ini) Path /etc/php5/apache2
Loaded Configuration File /etc/php5/apache2/php.ini

just a few lines down from the top. the changes you make in that file should affect php after a restart of the apache2 service (or a reboot of the server)

almost forgot: i have no clue about htaccess, ive always made all of the changes to php i need via the php.ini file in linux.

Re: How to set display_errors On

Posted: Mon Jul 12, 2010 3:40 pm
by websitesca
You can't really rely on ini_set for display_errors. The reason why is from the documentation:
Note: Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.
from: http://www.php.net/manual/en/errorfunc. ... lay-errors

Does your web-hosting provider let you put it in your .htaccess file?

If you want to use php.ini but it doesn't seem to be doing anything, then use phpinfo() to see which php.ini your php is loading at runtime.

Make a file called test.php and just put this in:

Code: Select all

<?php
phpinfo();
?>
Now run that. You should see a line for "Loaded Configuration File". This is what mine says:

[text]Loaded Configuration File /etc/php5/apache2/php.ini[/text]

Now you can be sure of which file to actually edit. Your web host may not let you edit the correct one so you might need to use .htaccess. Or perhaps there is something you log in to to enable .htaccess file usage.

I hope that helps you... I know these types of configuations for your website are really frustrating!
Georges,
http://www.websites.ca

Re: How to set display_errors On

Posted: Wed Jul 14, 2010 11:40 am
by jcobban
websitesca wrote:You can't really rely on ini_set for display_errors. The reason why is from the documentation:
Note: Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.
from: http://www.php.net/manual/en/errorfunc. ... lay-errors

Does your web-hosting provider let you put it in your .htaccess file?

If you want to use php.ini but it doesn't seem to be doing anything, then use phpinfo() to see which php.ini your php is loading at runtime.

Make a file called test.php and just put this in:

Code: Select all

<?php
phpinfo();
?>
Now run that. You should see a line for "Loaded Configuration File". This is what mine says:

[text]Loaded Configuration File /etc/php5/apache2/php.ini[/text]

Now you can be sure of which file to actually edit. Your web host may not let you edit the correct one so you might need to use .htaccess. Or perhaps there is something you log in to to enable .htaccess file usage.

I hope that helps you... I know these types of configuations for your website are really frustrating!
Georges,
http://www.websites.ca
When I run phpinfo on my public website on my ISP it identifies that it has loaded the configuration from /home/jcobban/public_html/php.ini, and all of the settings from that file appear in the output.

When I run phpinfo on the Apache web server on my home Ubuntu system it states: Loaded Configuration File /etc/php5/apache2/php.ini

The reason for this, as I now understand is that the Apache web server on my home system is configured with: Server API Apache 2.0 Handler, which requires the options to be specified in the .htaccess file instead of the php.ini file. However I have put the options into a .htaccess file and they still do not take effect.

Would someone please tell me what I am doing wrong?

Re: How to set display_errors On

Posted: Wed Jul 14, 2010 10:50 pm
by liljester
ok,

so ive checked this out a few times on my personal ubuntu server running apache2 handler just like yours. If you change the php.ini as i suggested, it WILL work. ive turned erros off and back on as well as many other settings changes. so to turn on display_errors do the following:

find your php.ini file, probably "/etc/php5/apache2/php.ini." then make the changes you need. restart apache2 with "/etc/init.d/apache2 restart".