skip to Main Content

I am trying to deploy yii-2 application on digital ocean droplet(CentOS 7) with Nginx web server. I have set the www folder perimission to:

chmod -R 775 /var/www

and ownership is tested with www/apache user. But still getting permission denied to create cache folder:

Exception – yiibaseException
Failed to create directory "/var/www/html/frontend/runtime/cache": mkdir(): Permission denied
Caused by: yiibaseErrorException
mkdir(): Permission denied
in /var/www/html/vendor/yiisoft/yii2/helpers/BaseFileHelper.php at line 628

Please guide me, am i doing something wrong ?

2

Answers


  1. You need to let selinux know what directories you’re going to allow the http process to write to. think of it as another set of permissions.
    use chcon to set or change these permissions

    here’s my quick list of dirs a typical yii app needs to write to

    chcon -Rt httpd_sys_content_rw_t /var/www/*/frontend/runtime
    chcon -Rt httpd_sys_content_rw_t /var/www/*/backend/runtime
    chcon -Rt httpd_sys_content_rw_t /var/www/*/console/runtime
    chcon -Rt httpd_sys_content_rw_t /var/www/*/frontend/web/assets
    chcon -Rt httpd_sys_content_rw_t /var/www/*/backend/web/assets
    

    note that the wildcard (*) in the above paths applies to all directories in www

    project specific paths that need write access (file/image upload folders) need to be applied individually

    chcon -R -t httpd_sys_content_rw_t /var/www/some-project/uploads/*
    

    you could also read more about contexts here

    if it’s a new setup, you will probably need to set the following flags for things to work properly

    setsebool -P allow_httpd_anon_write 1
    setsebool -P httpd_can_network_connect 1
    setsebool -P httpd_can_network_connect_db 1
    

    if all of that just isn’t your cup of tea you ca enable permissive mode

    setenforce 0
    
    Login or Signup to reply.
  2. I think you should give: sudo chmod -R 777 /var/www/html/frontend/runtime

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search