Search code examples
phpapachewebservercpanelerror-log

How can I set up error_log by folder?


My company has a large hosting, but it’s not managed by us, we don't see configuration files, but I want to reply this feature on our local test server.

I’m new in my company and want to start some debug of applications to fix some minors and majors issues to clients, but the amount of files is so big that single error_file is huge.. and there are many people working on this so each time I check log (like 30 secs to 1 min) has hundreds of added lines.

I don’t know if this is set up on Apache, through .htaccess files or in php.ini.

I am talking about PHP errors, but I don't know if this is set in PHP, Apache, or maybe using a third-party library.

I'm not talking about setting a specific folder error_log. I'm talking about if errors are logged in the scripts folder.

Example: I create a folder named test1. Inside it I make some buggy PHP script that throws some errors. When I run the script I can see an error_log file created in the folder. So it works on the fly.

I have tried to ask the hosting company support how they do this, but they haven’t answered me.


I don't know if maybe could be some kind of cPanel setting (BTW, the hosting support stuff doesn't understand this question either, but well.. usually level 1 of support can’t handle technical stuff).


Solution

  • I found it.

    You have to set a directive in the php.ini file as follows, string "error_log". On the right side is the file name you want for the log,

    error_log = error_log
    

    This will generate a PHP error log in the folder where script executed are,

    I'll try to explain.

    Script test.php in folder /www/site/lib:

    include "./db_conn.php";
    

    If file db_conn.php is not located in the same directory, this will fire a warning and error. Usually this will be lead to the servers/vhost log, but using this directive you will get an error_log file under the /www/site/lib directory.

    Why was I looking or this? Well, as I wrote, I'm working on a huge application, with thousands of files many fires warnings, notices, etc. I'm not the only one in the project and the site error_log file was so huge it was hard to keep tracking debug evolution for one or just some files. Now I just have to track the log from directories where I'm working.