Activarea afișării erorilor PHP (display_errors
) este esențială pentru dezvoltatori, deoarece permite vizualizarea rapidă a problemelor de cod în timpul testării aplicațiilor. Iată un tutorial pas cu pas despre cum să activezi display_errors
în PHP, folosind cPanel.
Cum să activezi afișarea erorilor PHP (display_errors) în cPanel
1. Autentifică-te în cPanel
- Deschide browserul și accesează cPanel introducând URL-ul:
http://yourdomain.com/cpanel
- Înlocuiește
yourdomain.com
cu numele domeniului tău. - Introdu numele de utilizator și parola pentru contul cPanel.
- Înlocuiește
2. Accesează secțiunea "Select PHP Version" sau "MultiPHP INI Editor"
Există două metode pentru a activa display_errors
, în funcție de versiunea cPanel pe care o folosești.
Metoda 1: Select PHP Version
- Derulează în jos până găsești secțiunea Software (Software).
- Click pe Select PHP Version.
Metoda 2: MultiPHP INI Editor
- Derulează în jos până găsești secțiunea Software (Software).
- Click pe MultiPHP INI Editor.
3. Activarea display_errors
Dacă folosești Select PHP Version:
- După ce ai accesat Select PHP Version, va apărea o listă cu extensiile PHP disponibile.
- În partea dreaptă a paginii, apasă pe Options (Opțiuni).
- Caută opțiunea display_errors.
- Bifează căsuța pentru a activa display_errors.
- Apasă pe butonul Save (Salvează) pentru a aplica modificările.
Dacă folosești MultiPHP INI Editor:
- Alege domeniul sau subdomeniul pentru care vrei să modifici setările.
- În secțiunea Basic Mode (Mod de bază), caută opțiunea display_errors.
- Setează display_errors pe
On
(Activat). - Apasă pe butonul Apply (Aplică) pentru a salva modificările.
4. Modificarea fișierului php.ini (Opțional)
Dacă nu ai acces la opțiunile menționate mai sus sau vrei să modifici manual fișierul php.ini
, urmează acești pași:
-
Creează sau editează fișierul php.ini:
- Poți crea un fișier
php.ini
în directorul rădăcină al site-ului tău sau poți căuta un fișierphp.ini
existent în directorul public_html.
- Poți crea un fișier
-
Adaugă următoarele linii:
display_errors = On error_reporting = E_ALL
-
Salvează fișierul.
5. Verificarea setărilor
Pentru a te asigura că display_errors
este activat, poți crea un fișier PHP simplu cu următorul cod:
phpinfo();
- Salvează acest cod într-un fișier numit
info.php
în directorul rădăcină al site-ului tău (de exemplu, în public_html). - Accesează fișierul în browser la
http://yourdomain.com/info.php
. - Caută secțiunea Core și verifică valoarea pentru
display_errors
. Aceasta ar trebui să fieOn
.
6. Securitate și recomandări
- Nu lăsa
display_errors
activat pe site-urile de producție, deoarece expunerea erorilor poate prezenta riscuri de securitate. Este recomandat să-l activezi doar pe mediile de dezvoltare sau testare. - Dezactivează-l după ce ai terminat testarea.
Prin acești pași, ai activat cu succes afișarea erorilor PHP (display_errors
) în cPanel. Acum poți vizualiza erorile și avertizările generate de aplicația ta PHP pentru a le corecta mai ușor.