This is a secure method to debug your apache from within php
For debugging without checking error_log/access_log files
- create a file called phpinfo.php in your / directory
- the contents of phpinfo.php
<?php phpinfo(); ?>
- Use this for your .htaccess file.
Options +FollowSymLinks ErrorDocument 404 /phpinfo.php
- Security Enhancing with htaccess
- SEO Redirects without mod_rewrite
- Log all .htaccess/.htpasswd logins
- Links to htaccess tutorials and articles
- PHP htaccess tips and tricks
- htaccess HTTPS / SSL Tips, Tricks, and Hacks
- Control htaccess Basic Authentication with PHP and mod_rewrite
- Make phpBB SEO friendly with htaccess
Now instead of getting a 404 error you will see debug information which will help you find out what the problem is.
Add security to phpinfo.php
Cd-MaN pointed out a security problem this method has, it reveals sensitive info to anyone who requests phpinfo.php.
Also, you better use it only as a temporary measure, because it reveals many sensitive information about your server (eg. delete it after you done debugging)
Here is a fix for this.
Secure phpinfo.php with .htaccess
This only allows the user from IP address 2.3.65.6, everyone else is redirected to http://www.domain.com
ErrorDocument 403 http://www.domain.com Order deny,allow Deny from all Allow from 2.3.65.6
Secure phpinfo.php with php
Same thing only uses .htaccess. Change your phpinfo.php file to the following
<?php
function debug() {
ob_start();
phpinfo();
$debugger = ob_get_clean();
if ($_SERVER['REMOTE_ADDR'] == '2.3.65.6') echo $debugger;
?>
Related Articles
01.08.07 at 3:38 am
The documentation for phpinfo can be found here: http://www.php.net/phpinfo
Also, you better use it only as a temporary measure, because it reveals many sensitive information about your server (eg. delete it after you done debugging)