Thursday, February 01, 2007

PHP Apache tips

(1) How to log errors in PHP instead of displaying them on the page?
Use the following lines in php.ini:
; Print out errors (as a part of the output).
information.display_errors = off
; Even when display_errors is on, errors that occur during PHP's startup; debugging.display_startup_errors = Off
; Log errors into a log file (server-specific log, stderr, or error_log (below));
sites.log_errors = On
; Set maximum length of log_errors.
log_errors_max_len = 1024
; Do not log repeated messages.
ignore_repeated_errors = Off
; Ignore source of message when ignoring repeated messages.
ignore_repeated_source = Off
; Log errors to specified file.
error_log = "logs/errors.log"
(2) How to find backend SQL errors?
Set the following line in php.ini:
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and SQL-Errors will be displayed.
mysql.trace_mode = On

(3) How to avoid exposing index structures for a folder?
Set the following lines in httpd.conf:
## DirectoryIndex: sets the file that Apache will serve if a directory is requested.

DirectoryIndex index.php

In such a way, request for a directory will be redirected to the file "index.php".
(4) How to use logging in Apache server?
Use the following 2 settings:
## ErrorLog: The location of the error log file.
ErrorLog logs/error.log
## LogLevel: Possible values include: debug, info, notice, warn, error, crit, alert, emerg.

LogLevel warn
(5) How to do directory-level access configuration for Apache Http Server?
Here's an example:

Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

Details can be found in http://httpd.apache.org/docs/2.2/mod/core.html#options .

No comments: