1. Locate the php.ini File
The php.ini file contains configuration settings for PHP. The location depends on the PHP version and your server setup. Common locations include:
/etc/php/<version>/apache2/php.ini
(for Apache)
/etc/php/<version>/cli/php.ini
(for the CLI)
Replace <version> with your PHP version, such as 8.2.
To find the exact location:
2. Edit the php.ini
File
Use a text editor like nano
to edit the file:
3. Enable Error Reporting
Search for the following settings and modify them accordingly:
- Display Errors
- Error Reporting Level For all errors (including warnings, notices, and strict standards):
Save and exit the editor (Ctrl + O, then Ctrl + X in nano).
4. Enable Error Reporting for Development (Optional)
To display errors directly in your scripts for development purposes, you can add this code at the start of your PHP files:
5. Restart Apache
Apply the changes by restarting the Apache server:
6. Verify Error Reporting
Create a PHP script (e.g., test.php) with the following content to test error reporting:
Access the script in your browser (http://your-domain/test.php). You should see the error message.
Notes:
- Security Consideration: Avoid enabling error display on production servers, as it might expose sensitive information. Instead, log errors to a file using:
- Advanced Error Reporting: You can also use debugging tools like Xdebug for more detailed error analysis.