Bit of a strange one here. I'm looking through my PHP Error log and on a number of occasions I'm seeing the following line
File does not exist: /var/www/vhosts/mywebsite.org.uk/httpdocs/users/assignmnets
The reason the file doesn't exist is that the folder is spelt wrong - it should read assignments, not assignmnets.
The thing is, I've gone through all of the code on the site and this spelling mistake doesn't appear anywhere at all, so why am I getting this error? Furthermore, there are no links to the above folder - any links point directly to the php file contained within the folder - assignments/assignments.php
I can't make head nor tail of it. Is this a common issue with PHP or is there something I am getting wrong?
Thanks!
What kind of PHP error log is it? some custom logger function? Try using Tracy https://github.com/nette/tracy - enabling this debugger in your project with
Debugger::enable(Debugger::DETECT, __DIR__ . '/mylog');
will result in that all PHP errors will be logged as an HTML file with very verbose description of the error, including full stack trace (in production environment; on localhost, when development environment is detected, you will see the stack trace immediatelly in browser). From this you will be able to determine which part of code caused this problem next time it happens.
Don't forget to disable your custom error handler if any is in use, as it may be colliding with Tracy.
Related
In localhost, we can easily find the errors like missing semicolon in line number xxx, undefined variable in line number xxx,class already declared etc. But, when I upload all my files in shared hosting and try to see results in the web browser, I get to see same error page everytime and it's really really hard to detect what exactly caused the error. The project which i uploaded to the live server was written in laravel. I have tried 'Display errors On' in php.ini, error_reporting(E_ALL). I have even checked the error_log in the root directory but, those logs are usually from few days ago. error image description here
Any possible solutions ? Or should I switch to server where proc_open is enabled?
Check this:
https://laravel.com/docs/7.x/errors
Laravel handles errors and can write them in a log file.
You can customize it if you want, but I don't think it's necessary to do so.
If you dont use any frameworks or ones that don't support such a feature for that matter you could always use the native PHP function set_error_handler and catch errors and write them in a log file.
Note: BEWARE of the excessive log file size. If your project has a lot of visitors or has lots of notices and warnings, this log files can get excessively massive, unreadable, and consuming your space. Don't turn it off, it's always good to know where are the errors, but check and debug them often and delete them when not needed.
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.
EDIT: The phpinfo() output that I direct you to below, shows display_errors off but that is overridden in a Wordpress configuration file --- I think. At least I'm seeing PHP errors so I assume it is overridden.
But, as it goes, when you assume you make an ass out of you and me. I'll change it in the php.ini file and report the results in another edit.
EDIT: I set display_errors On and display_startup_errors On and produced the errors again and the cgi_error_log is still empty.
Original questions beings below ------------------------
This is pretty elementary but I'm having a problem and I'm unable to get my brain out of first gear today and I'm in need of a reality check.
I wanted to empty the cgi_error_log file and tried to replace it with an empty file via FileZilla. FileZilla reported it was uploaded but when I looked on the server, it had not been replaced.
I finally used the hosting company's File Manager and deleted the file and uploaded an empty file. That succeeded and now the cgi_error_log is empty - it has been since I uploaded the empty file December 14, 2015 at 1941 (local time).
I expected something to have been logged by now.
One of the last messages in the cgi_error_log before I deleted in and uploaded an empty file, was:
20151214T181242: www.example.com/index.php
Failed loading /usr/local/lib/ioncube/ioncube_loader_lin_5.2.so: /usr/local/lib/ioncube/ioncube_loader_lin_5.2.so: wrong ELF class: ELFCLASS32
Failed loading /usr/local/Zend/lib/ZendExtensionManager.so: /usr/local/Zend/lib/ZendExtensionManager.so: wrong ELF class: ELFCLASS32
I changed the actual URL,l in the message, to www.example.com etc, as is standard here.
Don't worry about why the error occurred, I already asked a question about that issue, got a reply, and am now waiting on my hosting company to respond to service ticket I submitted about it.
I have not changed the file that was producing the above error and thus, I would expect errors of that type to be occurring and be logged to the cgi_error_log file.
My problem right now is that nothing is in the cgi_error_log file and I'm wondering about permissions and such on the file. I submitted a service ticket about this but got the usual uninformed responds.
This my question here as a reality check. If PHP errors should be written to cgi_error_log, then something is wrong. If not, I try a different approach to determine why the cgi_error_log is still empty.
The server is running Apache.
If you want to see the output of phpinfo(), look at this file.
Assume the following error (I forced it to occur with 1/0;):
Warning: Division by zero in /hermes/bosoraweb081/b1107/myd.sugarcatsimon/public_html/pdmeoff/pdroot/welg/wp-content/themes/thingspissed/functions.php on line 3
and, this one I caused by simply typing "This will cause an error" in a PHP function:
Parse error: syntax error, unexpected 'will' (T_STRING) in /hermes/bosoraweb081/b1107/myd.sugarcatsimon/public_html/pdmeoff/pdroot/welg/wp-content/themes/thingspissed/functions.php on line 3
I know that I'm asking more than one question, below, but they are all about the same matter - what and where is logged for PHP errors.
1) Should those be logged to a file?
2) If so, are they logged to cgi_error_log or some other file?
3) If it is not cgi_error_log, where would they be written?
4)What type of errors, if not PHP, are written to cgi_error_log?
5) How can I cause a message, of any type, to be written to cgi_error_log, besides using the error_log() function?
If I don't get it all in gear, I'm going to drop my brain off at the repair shop and have them give it a good overhaul.
Thanks in advance.
The cgi_error_log replacement had the wrong permissions. It was 644 and should have been 664.
For future searches - The cgi_error_log file needs to have permissions set to 664 for logging to succeed.
I have a problem with PHP. There is an error that I have never encountered before. The home.php, which is the main page of my site, cannot be viewed. And there is nothing in error log. After there is an inclusion of a php page (a class that is a part of my API). Till that line the holl HTML (javascript and css inclusions) are echoed from php and successfully rendered in browser, but after the php kind of stops suddenly. When I delete that line(php page inclusion line), website works, but before, this inclusion didn't make any problem for me. I removed the code parts which after them I encountered this problem, but nothing works.
I am using Apache2, PHP5 with Ubuntu 11.10.
Any help will be appreciated, thanks in advance.
My first hints would be to check the following:
In your script set ini_set('display_errors', '1'); and error_reporting(E_ALL); to display all errors.
Turn on the php error log and check it for errors.
run php -l home.php on the command line to check your php file for syntax errors.
Check Apache's error log, sometimes error messages go there.
If nothing helps use a debbugger like XDebug to see where the script terminates, or alternative insert statements like die("here"); and move them around in your code, to see which parts of your scripts are passed.
Greetings and good luck.
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.