简体   繁体   English

如何将PHP error_log设置为php.ini中的主目录?

[英]How do I set the PHP error_log to the home directory in php.ini?

I have access to the server-wide PHP settings on a server with shared hosting. 我可以访问具有共享主机的服务器上的服务器级PHP设置。 Currently the error_log value is simply "error_log", meaning it logs errors to a file named error_log in the same directory as the script that caused the error. 当前,error_log的值只是“ error_log”,这意味着它将错误记录到与导致错误的脚本相同目录中的名为error_log的文件中。 This results in error_log files in the web directory. 这将导致在web目录中的error_log文件。 Even though outsiders can't see the files, I'm not comfortable with them being there all the same. 即使局外人看不到文件,但我对文件都放在那也不满意。 I could specify an exact log file path, but I don't want errors of all the sites to end up in one file. 我可以指定一个确切的日志文件路径,但是我不希望所有站点的错误都以一个文件结尾。 I know that setting error_log to be "~/error_log" will not work (that is, it will NOT put the file in the home directory of whatever website generates the error). 我知道将error_log设置为“〜/ error_log”是行不通的(也就是说,它不会将文件放在任何会产生错误的网站的主目录中)。 Any suggestions on how I can accomplish that? 关于如何实现这一目标的任何建议? I suppose I need to use an auto-prepended script? 我想我需要使用自动添加的脚本吗?

Yes, I know I could override the global php.ini error_log settings with a php.ini file in every site's home directory, however there are a lot of sites, and I don't want to have to remember to do this with every site added. 是的,我知道我可以在每个站点的主目录中使用php.ini文件覆盖全局php.ini error_log设置,但是有很多站点,我不想记住每个站点都必须这样做添加。

您可以使用ini_set函数:

   ini_set("error_log", "/yourhome/yourproject.log");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM