How To log apache errors to a custom file

Ever needed to solve a matter in your php website but you could not see the errors or didn’t have access to the error_log of your vhost?

a workarround:

create an .htaccess file in your root directory (for plesk hosting its httpdocs) and add the following lines:

# show PHP errors
php_flag    display_errors          on
php_flag    display_startup_errors  on
php_value   error_reporting         2047

# enable PHP error logging
php_flag  log_errors on
php_value error_log  /var/www/vhosts/yourdomain.tld/httpdocs/my_php_errors.log

The first part is actually used to show errors in your website, the second is for logging them , just replace yourdomain.tld with your domain name or the whole path.Then all you have to do is create an empty file for eg ([root@ httpdocs]# echo > my_php_errors.log), be sure to give ownership to the file to apache ([root@ httpdocs]# chown apache:apache my_php_errors.log), or if you are not able to do that just give it 777 permissions.