I have installed a PHP application onto a shared hosting web server. I am getting a 500 Internal Server Error
. I don't seem to have access to any log files so I would like the error page to temporarily give details of the error.
5 Answers
try:
error_reporting(E_ALL);
ini_set('display_errors', '1');
at the top of the file.

- 3,314
- 23
- 23
-
3Also check file permissions. Often times if a file is not executable it will throw a 500 error. – Jeremy Morgan Nov 17 '09 at 20:42
If Jeremy Morgan's solution doesn't work, try creating your own log file using set_error_handler()
. Usually some information about the state of the application ($GLOBALS and so on) can be enough information, but PHP will (at least try to) pass you all sorts of information about where the error occurred and what type of error it is.
Also, try using the "Divide And Conquer" method of debugging. Start with about half of your file, and then expand upward if it's still crashing or downward if it runs umtil that point. If you don't want to remove your code, either /* comment out */
the code to be cut, or use the __halt_compiler()
special directive to have PHP ignore all remaining data in the file.
Finally, one thing that drove me mad trying to fix it is what's called a Byte Order Mark. PHP was evaluating that BOM at the beginning of the file, causing it to send output, and causing problems while trying to send headers and the like. Probably not what your issue is, but knowledge worth having.

- 9,939
- 3
- 35
- 51
-
1another +1 for the BOM. That gave me fits way back when I first started out! – Jeremy Morgan Nov 19 '09 at 08:20
I doubt you're getting that error from PHP. On shared hosting it's more likely that the application's default .htaccess config is causing the error.
My guess would be a mod_rewrite without a RewriteBase
set.

- 17,549
- 10
- 60
- 91
-
This is entirely possible, and `.htaccess` is usually my first culprit when debugging, but he never said he was using Apache. – Dereleased Nov 17 '09 at 20:49
-
@Dereleased - PHP + SharedHosting, I just did the math. I'd be surprised if it's IIS. – Tim Lytle Nov 17 '09 at 21:35
look at the values in phpinfo();
to see if anything sticks out... put it somewhere in the code and it should display a bunch of php version information

- 5,831
- 29
- 93
- 126
An "Internal Server Error" is not a PHP error (as the name says). Therefore, you either have to look at your server logs (which you do not have access to, as it seems) or you can't do anything about it from PHP.

- 11,353
- 8
- 48
- 70
-
2-1, depending on server configuration and software PHP errors may be presented as 500s. – Dereleased Nov 17 '09 at 20:44
-
Correct, in fact for security reasons a lot of shared hosts turn a php error into a 500 as part of supression. – Jeremy Morgan Nov 17 '09 at 20:45