Nella programmazione, si sa, gli errori sono “estremamente importanti”.
Senza di essi non sapremmo cosa non funziona, ma se questi son pubblici si rischia di rivelare informazioni sensibili (eg: dati del database, percorso degli script ecc…). Meglio prestare attenzione!
Proprio in questi giorni, post cambio migrazione hosting, mi son ritrovato col dover nascondere gli errori al pubblico, e far sì che questi fossero però presenti da qualche parte affinché, in caso di evidenti problemi (script che non fanno quello che dovrebbero), almeno mi faccio un’idea di come poter rimediare.
Nei precedenti hosting o c’era il solito click e via (eg: niente errori pubblici e file “error_log” nella directory dove si verifica il problema = error_log sparsi un po’ ovunque e spesso nemmeno te ne accorgi!), o – semplicemente – gli errori erano presenti anche al grande pubblico senza che io potessi fare molto.
Qui, invece, posso “giocare” col php.ini, e quindi ho cercato una soluzione un po’ migliore.
L’idea era quella di nascondere, ovviamente, gli errori al pubblico, e di salvarli nel file error_log, ma “tutti nello stesso error_log” (e quindi niente più file sparsi un po’ ovunque).
Dopo qualche ricerca, questo il risultato (php.ini): Testato e qui attivo!
; disable display of startup errors display_startup_errors =false ; disable display of all other errors display_errors =false ; disable html markup of errors html_errors =false ; enable logging of errors log_errors =true ; disable ignoring of repeat errors ignore_repeated_errors =false ; disable ignoring of unique source errors ignore_repeated_source =false ; enable logging of php memory leaks report_memleaks =true ; preserve most recent error via php_errormsg track_errors =true ; disable formatting of error reference links docref_root =0 ; disable formatting of error reference links docref_ext =0 ; specify path to php error log error_log =/home/***homedir***/public_html/error_log ; specify recording of all php errors error_reporting =-1 ; disable max error string length log_errors_max_len =0 ;; da qui in poi è altra roba...; ; hidden php info from header expose_php =Off ;set memory limit to... memory_limit =512M ; enable opcache zend_extension = opcache.so ; enable memcache extension = memcache.so ; disable unwanted functions disable_functions =exec,system,pcntl_exec,popen,proc_open,shell_exec
Teoricamente anche tramite .htaccess, ma non l’ho provato: (untested)!
# disable display of startup errors php_flag display_startup_errors off # disable display of all other errors php_flag display_errors off # disable html markup of errors php_flag html_errors off # enable logging of errors php_flag log_errors on # disable ignoring of repeat errors php_flag ignore_repeated_errors off # disable ignoring of unique source errors php_flag ignore_repeated_source off # enable logging of php memory leaks php_flag report_memleaks on # preserve most recent error via php_errormsg php_flag track_errors on # disable formatting of error reference links php_value docref_root 0 # disable formatting of error reference links php_value docref_ext 0 # specify path to php error log php_value error_log /home/***homedir***/public_html/error_log # specify recording of all php errors php_value error_reporting -1 # disable max error string length php_value log_errors_max_len 0
Adesso è molto meglio!
Tutte le segnalazioni in quell’unico file (in realtà io ho dato un altro nome…).
File che quindi ho sempre “sott’occhio” e non c’è rischio che, in caso di problemi, gli utenti possano ritrovarsi con info sensibili nell’errore.
Questo era l’ultimo tassello per portare il mio ipb a: “nessuna raccomandazione di sicurezza da fare” 🙂
È tutto, spero possa tornarvi utile!