To change the location of the PHP error_log for Apache

Marc Wagner, November 8, 2022

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.

Avatar of Marc Wagner
Marc Wagner

Hi Marc here. I'm the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.

Similar Topics

Comments

Leave A Comment