To change the location of the PHP error_log for Apache

You can customize the location for the error_log in most cases using PHP. This is useful if, for example, you are on a hosting where you do not have access to the default log file locations(here you can find an overview of the locations on Linux).

Customize location of error_log with PHP #

To change the location, you can add the following code at the beginning 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 created with your test entry. If this is not the case, the function has been disabled by your hosting provider.

Customize location of error_log with .htaccess #

Alternatively, you can change the location of the error_log file using .htaccess. For this you have to create a .htaccess file in the root directory of your website/web application and add the following lines there:

php_flag log_errors on
php_value error_log /pfad/zum/speicherort

That’s about it. Now, unless prevented by your hoster, all error messages should be written to the file you specified.

Hier klicken, um den Beitrag zu bewerten
[Gesamt: 0 Durchschnitt: 0]

Leave A Comment

Title