這是runtime 的權(quán)限問題,請檢查守護(hù)進(jìn)程的啟動用戶應(yīng)該設(shè)置成www;
方法一: 命令操作:
修改目錄權(quán)限:)777 www組
/runtime
修改文件夾及子文件夾權(quán)限可以用命令: chmod -R 777 runtime
永久解決方法:
在啟動workermam時(shí)使用 sudo -u www php think workerman start —d 命令
寶塔操作:
兩種方法:
1.直接系統(tǒng)目錄文件設(shè)置權(quán)限
(1).找到知識付費(fèi)項(xiàng)目目錄
(2).點(diǎn)擊權(quán)限設(shè)置,設(shè)置權(quán)限為777,點(diǎn)擊確定
2.命令操作
(1).目錄切換到知識付費(fèi)項(xiàng)目根目錄,點(diǎn)擊終端
(2).打開終端后切到知識付費(fèi)根目錄,輸入命令執(zhí)行即可
方法二:代碼修改
由于www用戶和root用戶(比如command的cli進(jìn)程日志)都有可能對log文件進(jìn)行讀寫。
如果是由www用戶創(chuàng)建的log文件,不會出任何問題。
但是如果是先由root用戶創(chuàng)建的log文件,然后再到www用戶角色去寫,就會出問題了
因?yàn)橐话隳J(rèn)創(chuàng)建的log文件的權(quán)限是 -rw-r—r-
也就是www沒有權(quán)限去寫入root用戶創(chuàng)建的log文件。
網(wǎng)上的方法大體就是像下面代碼一樣在mkdir的時(shí)候修改目錄的權(quán)限
修改文件:\thinkphp\library\think\log\driver\File.php里的save()函數(shù)
public function save(array $log = [], $append = false){ $destination = $this->getMasterLogFile(); $path = dirname($destination); if (PHP_SAPI != 'cli') { !is_dir($path) && mkdir($path, 0755, true); }else{ !is_dir($path) && mkdir($path, 0777, true) && chmod($path, 0777); }// !is_dir($path) && mkdir($path, 0755, true);$info = [];foreach ($log as $type => $val) { foreach ($val as $msg) { if (!is_string($msg)) { $msg = var_export($msg, true); } $info[$type][] = $this->config['json'] ? $msg : '[ ' . $type . ' ] ' . $msg; } if (!$this->config['json'] && (true === $this->config['apart_level'] || in_array($type, $this->config['apart_level']))) { // 獨(dú)立記錄的日志級別 $filename = $this->getApartLevelFile($path, $type); $this->write($info[$type], $filename, true, $append); unset($info[$type]); }}if ($info) { return $this->write($info, $destination, false, $append);}return true;}
但是上面只能修改文件夾的權(quán)限,并沒有修改文件夾下具體的.log文件的權(quán)限。
修改文件:\thinkphp\library\think\log\driver\File.php里的write()函數(shù)
protected function write($message, $destination, $apart = false, $append = false){ // 檢測日志文件大小,超過配置大小則備份日志文件重新生成 $this->checkLogSize($destination); // 日志信息封裝 $info['timestamp'] = date($this->config['time_format']); foreach ($message as $type => $msg) { $info[$type] = is_array($msg) ? implode("\r\n", $msg) : $msg; } if (PHP_SAPI == 'cli') { $message = $this->parseCliLog($info); } else { // 添加調(diào)試日志 $this->getDebugLog($info, $append, $apart); $message = $this->parseLog($info); }// return error_log($message, 3, $destination);// 解決root生成的文件,www用戶沒有寫權(quán)限的問題 by Werben 20190704 begin if (!is_file($destination)) { $first = true; } $ret = error_log($message, 3, $destination); try { if (isset($first) && is_file($destination)) { chmod($destination, 0777); unset($first); } } catch (\Exception $e) { } return $ret;}
注:方法修改完成后,刪除runtime文件,前端刷新檢查。