3

I have written an application in CakePHP 3.2 and recently uploaded to a dedicated server.

But this is giving RuntimeException error as

Cache engine Cake\Cache\Engine\FileEngine is not properly configured.

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 134

I tried with changing permission of logs and tmp directory to 777 (including sub directories) but this doesn't solve the issue.

output of ls -la

drwxr-xr-x. 13 root   root    4096 Oct 22 02:39 .
drwxr-xr-x.  4 root   root      43 Oct 12 20:12 ..
drwxr-xr-x.  2 root   root      63 Oct 21 15:08 bin
-rw----r--.  1 root   root    1499 Oct 21 15:08 composer.json
-rw----r--.  1 root   root   48701 Oct 21 15:08 composer.lock
drwxr-xr-x.  3 root   root    4096 Oct 21 15:08 config
-rw----r--.  1 root   root     329 Oct 21 15:08 .editorconfig
-rw----r--.  1 root   root     772 Oct 21 15:08 .gitattributes
-rw----r--.  1 root   root      41 Oct 21 15:08 .gitignore
-rw----r--.  1 root   root     159 Oct 22 03:02 .htaccess
-rw----r--.  1 root   root     648 Oct 21 15:08 index.php
-rw-r--r--.  1 apache apache    20 Oct 13 00:10 info.php
drwxrwxrwx.  2 root   root      46 Oct 22 02:30 logs
drwxr-xr-x.  2 root   root      10 Oct 21 15:08 mobile_scripts
-rw----r--.  1 root   root    1202 Oct 21 15:08 phpunit.xml.dist
drwxr-xr-x.  3 root   root      37 Oct 21 15:08 plugins
-rw----r--.  1 root   root    1015 Oct 21 15:08 README.md
drwxr-xr-x.  8 root   root    4096 Oct 21 15:13 src
drwxr-xr-x.  4 root   root      71 Oct 21 15:13 tests
drwxrwxrwx.  6 root   root      76 Oct 21 15:13 tmp
-rw----r--.  1 root   root     321 Oct 21 15:08 .travis.yml
drwxr-xr-x. 21 root   root    4096 Oct 21 15:14 vendor
drwxr-xr-x.  5 root   root    4096 Oct 21 15:24 webroot

What could be the cause and how to resolve it ?

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
  • Have you tried with fresh cakephp app skeleton https://github.com/cakephp/app ? – makallio85 Oct 22 '16 at 12:45
  • 1
    Make sure the logs folder exists and is writable. And why is everything root? It should be www-data or alike, never root. – mark Oct 22 '16 at 14:38
  • logs folder existed and were writable. Also group is root and this is what i was given by server administrator and I don't have right to change it. The thing that worked is disabling `SELinux` – Anuj TBE Oct 22 '16 at 14:53
  • The `tmp/cache` should also be writable. – Aefits Dec 26 '18 at 07:17

4 Answers4

4

I had the same problem. It can be due to the permission of logs and tmp directories. But sometimes, if your web server user is different from your command line user, you can have this permission error !

You can run this little command in the project's directory :

HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`  
setfacl -R -m u:${HTTPDUSER}:rwx tmp    
setfacl -R -d -m u:${HTTPDUSER}:rwx tmp    
setfacl -R -m u:${HTTPDUSER}:rwx logs
setfacl -R -d -m u:${HTTPDUSER}:rwx logs  

It will setup permission properly !! Don't forget to restart apache services :

service apache2 restart

If you want to check this : https://book.cakephp.org/3.0/en/installation.html

I hope it will be helpfull !! :D

Nico D.
  • 41
  • 4
1

I got it working. For someone if get stuck with this error can try this solution.

I am using centOS Server

disabling SELinux worked for me.

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
1

I had the same issue and it looks like it had to do with apache not having the right permissions on the project files.

I managed to solve it by recursively setting the owner and the group of the whole project directory to the web server user by:

HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1` 
sudo cd "your project directory"
sudo chown $HTTPDUSER:$HTTPDUSER -R .

Hope that helps!

0

Anuj's answer about disabling SELinux worked for me as well. I was delighted to find this after hours of trying other things. I just wanted to add that I didn't disable it, but rather changed it to 'permissive' from 'enforcing.' I am running CakePHP 2.4.2 on CentOS 7 on an AWS T2 instance.

I. Smith
  • 11
  • 1