Codeigniter无法记录日志

12
我似乎无法弄清楚为什么CodeIgniter没有记录我的log_messages。
在Config中:
$config['log_threshold'] = 4;
$config['log_path'] = '/var/log/mydlp.log';

在脚本中:

log_message('error','here');

文件位置:

-rw-rw-rw- 1 root  root    0 2012-12-05 13:10 mydlp.log

当我到达日志消息时,我没有得到任何东西。

这是我的/var和/var/log目录结构。

 drwxr-xr-x  6 root root  4096 2012-12-05 13:10 log
 drwxr-xr-x  14 root root  4096 2012-01-04 14:38 var

我在这里做错了什么吗?

2个回答

15

$config['log_path'] 应该是一个目录路径,而不是文件路径。CI会以 log-2012-12-05.php 的格式自动写入文件。请尝试使用一个目录路径,并确保在结尾处包含斜线。

/*
|--------------------------------------------------------------------------
| Error Logging Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ folder. Use a full server path with trailing slash.
|
*/
$config['log_path'] = '/var/log/ci_logs/';

755 权限够用吗还是需要777? - Aram Papazian
3
看起来755没有起作用,我不得不将其改为777,但我认为这是因为该文件夹是由root创建的。我会切换到服务器上,然后应该可以使用755。非常感谢。 - Aram Papazian
2
是的,我想我也得做同样的事情,只需要使用777。 - Wesley Murch
3
+1也需要远程使用777,但在本地使用755就可以了。我认为这是一个用户组问题,因为我的远程服务器具有不同的Apache用户,而与目录所有者不同。 - grant
2
之前一直在想为什么本地可以运行但是在服务器上不行,于是我尝试了777文件权限,在远程服务器上就可以运行了。 - Eddy Goh
显示剩余2条评论

3
问题出在SELinux上,请查看这篇帖子。
你可以尝试以下方法:
# Ownership
sudo chown apache:apache -R /data/www/html/sites/mysite
cd /data/www/html/sites/mysite

# File permissions, recursive
find . -type f -exec chmod 0644 {} \;

# Dir permissions, recursive
find . -type d -exec chmod 0755 {} \;

# SELinux serve files off Apache, resursive
sudo chcon -t httpd_sys_content_t /data/www/html/sites/mysite -R

# Allow write only to specific dirs
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/logs -R
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/uploads -R

https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接