I'm taking a php course. I made a php.ini file to show errors.
I have the code below on my php.index file. But instead of the error being displayed just nothing shows up. What am I doing wrong?
index.php code:
<?php
$test="I"m a variable!";
echo $test;
?>
This my php.ini code:
display_errors = on
display_startup_errors = on
You should check your error reporting directives
error_reporting = E_ALL
display_errors = ON
But please note that PARSER errors are not being show in display errors, but in error_log.
What is 'php.index'?
Normally the index page is index.php
Where is your php.ini file located? Where is it supposed to be located?
Do you have access to php interpider (command line)?
phpinfo() can help you location the php.ini file(s)
Your file name should be index.php so your server can recognize it as a PHP file.
Make sure you are loading the php.ini file that you've created.
call phpinfo() and check the route of the php.ini to see if you are loading yours.
Related
I have in a php.ini in public_html that has
display_errors = on
error_reporting = E_ALL | E_STRICT
log_errors on
error_log /home/account/public_html/error.log
phpinfo shows that the php.ini file in public_html is being loaded. The error_log file has 755 permissions and belongs to the same group:owner as all other files in public_html.
But, when I force php errors, no errors are displayed or logged. Errors are logged in /usr/local/apache/logs/error_log. And I've restarted apache.
Any ideas?
Try changing:
log_errors on
error_log /home/account/public_html/error.log
To
log_errors = on
error_log = /home/account/public_html/error.log
Next, near the top of your script, do:
echo php_ini_loaded_file(); // to make sure that you're editing the right php.ini
echo ini_get('log_errors'); // should be '1'
echo ini_get('error_log'); // should be path from php.ini
If the settings don't match what you set (I assumed you restarted Apache), check the rest of the php.ini as well as Apache VirtualHost configuration for another setting that may be overriding yours.
When you runphpInfo(), it will sometimes show a list of ini files that get loaded (not just your basic php.ini. One of them could also contain an override.
Finally if none of that works, you could set error-logging in-script with ini_set(). Just be aware that if that script itself has an error, this setting may not have the chance to take effect so it's best to do it in a script separate from your main, and require it
main.php
require_once('./init.php);
// ... your regular script
init.php
ini_set('log_errors', '1');
ini_set('error_log', '/path/to/errors.log');
SOLUTION:
Bunyamin's comment was my solution.
display_errors for php5-fpm not working with nginx
The second answer of that question mentioned the /etc/php5/fpm/pool.d/*.conf files, in my case /etc/php5/fpm/pool.d/www.conf
There I added
php_flag[display_errors] = on
and now it works.
QUESTION:
I have already turned on error reporting in the /etc/php5/cgi/php.ini file and no errors are shown.
If I add
error_reporting(E_ALL);
ini_set('display_errors', 1);
to my PHP code, all the errors are shown.
Why doesn't it work if I turn on error reporting in the php.ini files and don't add that code snippet? Shouldn't the php.ini file do the same as the code?
Webserver: Lighttpd
OS: Raspbian Jessie
EDIT:
phpinfo() shows that display_errors is set to Off, but in the php.ini file its turned On.
My php.ini file: http://pastebin.com/1qeK310n
Output of phpinfo(): http://www.file-upload.net/download-11264468/phpinfo.htm.html
I have four suggestions.
First of all, make sure that you are editing the correct php.ini file. You can see which php.ini file is used with the function phpinfo().
Simply create a file, phpinfo.php, with the following content. When you load the page (http://yoursite.com/phpinfo.php), you can see the details about your PHP configuration.
<?php
echo phpinfo();
Secondly, make sure you set error_reporting to E_ALL to get full debug information (Suggested only in development).
Thirdly, is there anywhere in your application that you set display_errors to 0. Sometimes, especially in frameworks, this property is set to 0.
Lastly, sometimes Apache is configured in a way that a custom php.ini file located in the root directory of your webpage can override your global configuration. Then the change in global php.ini file would not affect your application.
You have to scroll down to where the display_errors is set to OFF an then turn it on (Don't uncomment and set to on, scroll down)
I have a PHP page that's erroring out somewhere (it loads blank white, no title or anything), but I cannot for the life of me get it to display errors. I have the following in my files, but the page still loads blank white. What can I do to get PHP to display errors? This is on PHP 5.5 on my own server, and I am editing the correct php.ini file (according to phpinfo()).
php.ini:
display_errors = on
error_reporting = E_ALL
.htaccess:
php_value error_reporting -1
Specific file in question:
ini_set('display_errors',1);
error_reporting(E_ALL);
Make sure to add it to the correct php.ini file. Some web hosters have configured their server such that a php.ini in the same directory as the html of php file will be executed. But this is not the default. If you are in Linux, try putting it into /etc/php5/apache2/php.ini or search on your harddisk for any php.ini.
Turns out display_errors was already set below my own edits, so php.ini was using the default value of Off instead of my value. Deleted my edits and fixed the spots that needed it, problem resolved.
I am facing a strange problem. I have set up everything in php.ini file. But i can't get any errors showing up in the browser. I googled to set up the .ini file and did all the required things. But still i am not able to get error message displaying in the browser. My PHP ini settings,
display_errors = On
display_startup_errors = On
error_reporting = E_ALL | E_STRICT
log_errors = On
track_errors = On
I tried with the following code to see error message,
<?php
require_once("sample.php");
?>
Actually the file sample is not available. So it must show Fatal error. But it is showing a blank page.
Can you point me out to fix this? I don't know what i am missing here.
You can also add custom error reporting to your php and test with that:
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
require_once( "sample.php" );
?>
If you get fatals, then something is wrong with php.ini configuration ( maybe you have multiple php.ini files? ). If you still get nothing, then php can find the file ( maybe you have some redirects set up? Maybe some strange extensions? )
I found the problem. Actually, PHP is installed with XDebug extension. So the problem is in that extension. Even i was not aware of that. Because this system was used by someone previously. I uninstalled and installed again with new supported version. It works now. Thanks and sorry for the inconvenience friends.
Try finding these words in your php.ini file
display_errors
error_reporting
change default value of display_errors from Off to On
change default value of error_reporting from XXXX to E_ERROR | E_PARSE
Restart apache server.
Mind, It'll always show errors.
I know its an old thread , yet if someone is facing the same issue with php8 installation , use the following methods .
<?php
phpinfo()
?>`
and you can find the location of php.ini in the phpinfo() page , php8 when i installed i had three directories inside /etc/php/ location 7.2 , 8.0 , 8.1 .I was using ubuntu 18.04. Run this command to find php.ini location php -i | grep "php.ini" .Try editing the php.ini in the shown location and if it does not work , follow phpinfo() page and find the php.ini location in the page.
if you have added the following script
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
require_once("sample.php");
?>
and you are able to see the error means something is overriding the php.ini.
Most likely in that case php.ini file location may be different. You might have edited the wrong php.ini file.I had to edit php.ini file in this location /etc/php/8.0/apache2. Change display_errors directive to on in the php.ini file.
i have set error reporting to 1 using php function error_reporting(1) but it has no effect on the server .actually i am working on a staging server using xampp.is there any settings which has to be enabled in server so that php error reporting settings can be changed.
just make .htaccess file and to it add
##Turn off display_errors##
php_flag display_errors off
save it into main directory
and its done
Put this line ini_set('display_errors',1); on the top of your php code.
Try changing the setting in \xampp\php\php.ini, not via the error_reporting function. Then restart the server, and you should be good to go.
You may also want to check that display_errors is set to on. (Off the top of my head, though, XAMPP should be configured to display errors by default. Weird.)
Via FTP only, you can attempt to set these variables via ini_set at the top of your script:
<?php
ini_set('display_errors', 1)
ini_set('error_reporting', 1)
?>
You may also want to try setting these variables through a .htaccess file. Create a file called .htaccess in the same directory as your script, and add these lines:
php_flag display_errors on
php_value error_reporting 1