To change the location of the PHP error_log for Apache

Marc Wag­ner

Novem­ber 8, 2022

1 min read|

You can cus­to­mi­ze the loca­ti­on for the error_log in most cases using PHP. This is useful if, for exam­p­le, you are on a hos­ting whe­re you do not have access to the default log file loca­ti­ons(here you can find an over­view of the loca­ti­ons on Linux).

Customize location of error_log with PHP #

To chan­ge the loca­ti­on, you can add the fol­lo­wing code at the begin­ning of your PHP file.

// Aktiviert das Speichern von Fehlermeldungen in der Log-Datei.
ini_set("log_errors",1);
// Ändert den Pfad der error.log Datei
ini_set("error_log", "pfad/zum/speicherort");
// Schreibt eine Test Meldung in die Log Datei
error_log("Hallo, ich bin ein Test");

When you call the PHP file, a file should now be crea­ted with your test ent­ry. If this is not the case, the func­tion has been dis­ab­led by your hos­ting pro­vi­der.

Customize location of error_log with .htaccess #

Alter­na­tively, you can chan­ge the loca­ti­on of the error_log file using .htac­cess. For this you have to crea­te a .htac­cess file in the root direc­to­ry of your website/web appli­ca­ti­on and add the fol­lo­wing lines the­re:

php_flag log_errors on
php_value error_log /pfad/zum/speicherort

Tha­t’s about it. Now, unless pre­ven­ted by your hos­ter, all error mes­sa­ges should be writ­ten to the file you spe­ci­fied.

88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar