LoginSignup
1
3

More than 5 years have passed since last update.

CakePHP Error Warning: file_put_contents(/var/www/html/logs/error.log)

Posted at

表題のエラー

Warning: file_put_contents(/var/www/html/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133

上記エラーが発生しページが表示されないなどの状態になったばあい、

原因再現

サーバーへあげてる、cakePHPのプロジェクトをsftpにより取得します。

そのごvagrant でファイル共有を行う。

Vagrantfile 

下記項目がコメントアウトされてるのでパスを整えて編集し直します。

config.vm.synced_folder "./html", "/var/www/html/" 前項がローカルの共有したいディレクトリーのパス、 後項がvagrant 環境の共有させたいパスになります。

これを行うことにより、ローカル環境にてAtomや、GUIエディターでの編集が可能になります。

便利です。

これを行った際に発生しました。

SELinux が原因などの記事が多いですが、

実際はパーミッションなので、権限を変更するだけで解決できます。

/var/www/html/logs/error.log

とありますので、

/var/www/html/logs 左記権限を変更することにより解決できます。

logs ディレクトリーの権限を777に変更
logs直下のemptyを 664に変更
logs直下のerror.log を644に変更します。

chmod 0777 ./logs
chmod 664 ./logs/empty
chmod 644 ./logs/error.log

これで表題のエラーは解決できます。

これを解決すると、掲題の方法にて共有させますと、下記エラーが発生する可能性が高いと思われます。

私の場合発生しました。

下記ログになります。

Error: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

上記も権限のエラーになるので、権限を書き換えます。

chmod 666 debug_kit.sqlite
drwxrwxrwx. 1 vagrant vagrant      170 Sep  9 12:44 cache
-rw-rw-rw-. 1 vagrant vagrant 10407936 Sep 16 08:53 debug_kit.sqlite
drwxr-xr-x. 1 vagrant vagrant      102 Sep  9 12:44 sessions
drwxr-xr-x. 1 vagrant vagrant      102 Sep  9 12:44 tests

権限を与えることによりこのエラーも解決できます。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3