permissions error running Console/cake

2019-07-31 14:39发布

问题:

I'm trying to run the cake console application for the first time. From the cake app folder I am running Console/cake then I get the following output

PHP Warning:  SplFileInfo::openFile(/var/www/virtual_host.com/public_html/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in /var/www/virtual_host.com/public_html/lib/Cake/Cache/Engine/FileEngine.php on line 314

Warning: SplFileInfo::openFile(/var/www/virtual_host.com/public_html/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in /var/www/virtual_host.com/public_html/lib/Cake/Cache/Engine/FileEngine.php on line 314

Welcome to CakePHP v2.3.7 Console
---------------------------------------------------------------
App : app
Path: /var/www/virtual_host.com/public_html/app/
---------------------------------------------------------------
Current Paths:

 -app: app
 -working: /var/www/virtual_host.com/public_html/app
 -root: /var/www/virtual_host.com/public_html
 -core: /var/www/virtual_host.com/public_html/lib

Changing Paths:

Your working path should be the same as your application path. To change your path use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp

Available Shells:

[CORE] acl, api, bake, command_list, console, i18n, schema, server, test, testsuite, upgrade

To run an app or core command, type cake shell_name [args]
To run a plugin command, type cake Plugin.shell_name [args]
To get help on a specific command, type cake shell_name --help

Warning Error: SplFileInfo::openFile(/var/www/virtual_host.com/public_html/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in [/var/www/virtual_host.com/public_html/lib/Cake/Cache/Engine/FileEngine.php, line 314]

Warning Error: _cake_core_ cache was unable to write 'file_map' to File cache in [/var/www/virtual_host.com/public_html/lib/Cake/Cache/Cache.php, line 310]

this is the output of ls -l

drwxrwxr-x 3 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Config
drwxrwxr-x 4 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Console
drwxrwxr-x 3 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Controller
-rw-rw-r-- 1 DevinCrossman DevinCrossman  701 Jul 16 14:17 index.php
drwxrwxr-x 2 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Lib
drwxrwxr-x 3 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Locale
drwxrwxr-x 4 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Model
drwxrwxr-x 2 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Plugin
drwxrwxr-x 4 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Test
drwxrwxrwx 6 DevinCrossman DevinCrossman 4096 Jul 16 14:17 tmp
drwxrwxr-x 2 DevinCrossman DevinCrossman 4096 Jul 16 14:17 Vendor
drwxrwxr-x 9 DevinCrossman DevinCrossman 4096 Jul 16 14:17 View
drwxrwxr-x 6 DevinCrossman DevinCrossman 4096 Jul 16 14:17 webroot

I tried modifying Config/core.php with the following based on this other SO question

Cache::config('_cake_core_', array(
    'engine' => $engine,
    'prefix' => 'cake_core_',
    'path' => CACHE . 'persistent' . DS,
    'serialize' => ($engine === 'File'),
    'duration' => $duration,
    'mask' => 0666
));

Cache::config('_cake_model_', array(
    'engine' => $engine,
    'prefix' => 'cake_model_',
    'path' => CACHE . 'models' . DS,
    'serialize' => ($engine === 'File'),
    'duration' => $duration,
    'mask' => 0666
));

but it didn't change anything.

Anyone know what permissions I need to change? Is it normal to need to change the permissions on a clean install? (except for app/tmp I know that's normal)

回答1:

make the ownership DevinCrossman:www-data of your whole cake directory sudo chown -R DevinCrossman:www-data . while standing in the root of the vhost.

the webserver (member of www-data) needs to be able to write in app/tmp



回答2:

The files in app/tmp are created with mode 664, so users belonging to www-data (or the group Apache runs with) are allowed to change them. file-permissions cache

So running:

sudo adduser mich www-data
newgrp www-data

solved the problem for me.

HTH



回答3:

Maybe should also

sudo adduser www-data mich

so that cache files created by mich can be accessed by www-data