If you can already see your errors in DirectAdmin, that usually means PHP or Apache or Nginx errors are being logged and made available through the control panel (often in error_log inside your domain's directory). However, if you want to manually create or redirect errors to a specific error.log file, here's how to do it:
Option 1: PHP error logging via .htaccess If you're using Apache or Nginx with PHP as a module, you can configure PHP error logging with .htaccess: Go to your website's root directory (e.g., public_html/). Edit or create a .htaccess file. Add the following lines:
php_flag log_errors On
php_value error_log error.log
OR
php_flag log_errors On
php_value error_log /home/username/domains/yourdomain.com/public_html/error.log
Replace /home/username/domains/yourdomain.com/public_html/ with your real path. This will create an error.log file (if it doesn't already exist) and start logging PHP errors there.
Option 2 (in cPanel): PHP error logging via php.ini or .user.ini (if .htaccess doesn’t work) If .htaccess changes don’t work (common on servers using PHP-FPM), use .user.ini or a custom php.ini: In your public_html/, create a file called .user.ini (or edit it if it exists). Add: log_errors = On error_log = /home/username/domains/yourdomain.com/public_html/error.log Save and wait a few minutes (PHP-FPM reads .user.ini on a schedule, usually every 5 mins).
Option 3: Log errors inside a specific PHP file If you want to do it programmatically inside a script (e.g., index.php), you can use:
ini_set("log_errors", 1);
ini_set("error_log", "/home/username/domains/yourdomain.com/public_html/error.log");
error_log("Test error message!");
This is useful for debugging and custom logging within scripts.
How to test if it works? Add this code temporarily to a PHP file:
Then check your error.log file to confirm it was created and the error is recorded. Bonus: View logs from DirectAdmin You can still check: Domain Logs: Go to User Level → Site Summary / Statistics / Logs → Error Log Or browse: /home/username/domains/yourdomain.com/logs/ (if SSH/FTP access is available).
If you're using our services and you are on hybrid Nginx/Apache, these steps should work, but if you're using pure Nginx with PHP-FPM, .htaccess won’t be supported – so prefer the .user.ini or script-based options.
Bonus: You can also see the errors by the system with:
For WordPress in the wp-config.php file:
define('WP_DEBUG_DISPLAY', false );
define('WP_DEBUG', false); define('WP_DEBUG_LOG', false );
AND
@ini_set( 'display_errors', 0 ); @ini_set('log_errors', 'On');