For PHP error handling with the aim of "only admin sees the warnings, errors etc.";
I applied the steps below:
- I deleted
error_reporting(-1);
command from myindex.php
- I added rows below into my
.htaccess
which is just underpublic_html
folder - I created
error_modes
folder in mypublic_html
folder - I created
.htaccess
file inerror_modes
folder - I set the permissions of the
error_modes
folder as777
, writable. - intentionally, I wrote
<?php 'should see this error in log file' ?>
in myfooter.inc.php
page. Please note that I didn't wrote;
character at the end.
Despite the intentional php syntax error in my footer.inc.php
page, no php_error.log
file is created!
and I saw that should see this error in log file string
is printed in my footer.inc.php
page. So php worked despite a syntax error !?
I also added my whole .htaccess
code below. (this is the one that is just under public_html
)
fyi: I don't have access to php.ini
and I don't have any pre-set .log
file. PHP version is 5.4.
Can you please correct me? Thanks. Best Regards.
added commands into public_html > .htaccess for error handling
php_flag log_errors on
php_flag display_errors off
php_value error_log /home/my_user_number/public_html/error_modes/php_error.log
php_value error_reporting -1
codes in error_modes > .htaccess
Order allow,deny
Deny from all
whole codes in public_html > .htaccess
RewriteEngine On
RewriteBase /
#always use www - redirect non-www to www permanently
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# hotlink protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.p.ht [NC]
RewriteRule \.(jpg|jpeg|png|gif|css|js)$ - [NC,F,L]
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# File caching is another famous approach in optimizing website loading time
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# disable directory browsing
Options All -Indexes
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# secure password file
<Files .mypassword>
order allow,deny
deny from all
</Files>
# secure spesific files
<Files secret.php>
order allow,deny
deny from all
</Files>
# secure spesific files
<Files secret2.php>
order allow,deny
deny from all
</Files>
#SEO friendly linking
RewriteRule ^sitemap.xml$ sitemap.php [L]
RewriteRule ^articles/(.+)/(.+)$ index.php?page=articles&subject=$1&object=$2 [L]
RewriteRule ^articles/(.+)$ index.php?page=articles&subject=$1 [L]
RewriteRule ^labels/(.+)$ index.php?page=labels&subject=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)$ index.php?page=$1 [L]
#error handling
php_flag log_errors on
php_flag display_errors off
php_value error_log /home/my_user_number/public_html/error_modes/php_error.log
php_value error_reporting -1
Please try to do the following:
In .htaccess
In php file
Instead of intentional mistake in you wrote in your php file you can try doing something like:
Worked good with me)
Hope it'll help.