Symfony2 上的权限问题 [英] Permissions issues on Symfony2

查看:16
本文介绍了Symfony2 上的权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被问过好几次了,但没有一个解决方案能解决我的情况.

This question has been asked several times but none of the solutions fix it in my situation.

我在 Mac OSX Lion 上运行 Apache.这个 http://localhost/Symfony/web/config.php URL 触发了 2 个主要问题:

I am running Apache on Mac OSX Lion. This http://localhost/Symfony/web/config.php URL triggers 2 major problems:

Change the permissions of the "app/cache/" directory so that the web server can write into it.
Change the permissions of the "app/logs/" directory so that the web server can write into it.

遵循设置权限"下的指南:

rm -rf app/cache/*
rm -rf app/logs/*
sudo chmod +a "_www allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

这并不能解决问题,所以我尝试了:

That doesn't solve the problems, so then I tried:

sudo chmod -R 777 app/cache

那也行不通.任何想法如何解决这个问题?

That doesn't work either. Any ideas how to fix this?

推荐答案

一些初步的说明:

  • 为了提高您网站的性能,Symfony2 需要缓存大量数据,它通过将编译文件写入您的 app/cache 目录来实现这一点.
  • 为了提供强大的调试和监控工具,Symfony2 需要跟踪您的网站行为,它通过将跟踪文件写入您的 app/logs 目录来实现这一点.
  • In order to enhance the performance of your website, Symfony2 needs to cache a lot of data and it does this by writing compiled files into your app/cache directory.
  • In order to propose powerful debugging and monitoring facilities, Symfony2 needs to track your website behavior and it does this by writing trace files into your app/logs directory.

关于 Apache 的一些话:

Some words about Apache:

  • Apache 在特定的 user 和特定的 group 下运行(通常是 www-data,但您必须检查您的安装以找到用过的,比如在Linux中搜索/etc/apache2/envvars,就会有两个变量APACHE_RUN_USER=www-dataAPACHE_RUN_GROUP=www-data).
  • 这意味着当你在 Symfony2 的肩膀上构建你的网站并在 Apache 下运行它时,每次写入和读取都是代表 Apache usergroup.
  • Apache runs under a specific user and a specific group (usually www-data for both, but you have to check your installation to find the used ones. For example, if you search in the /etc/apache2/envvars in Linux, you will have two variables APACHE_RUN_USER=www-data and APACHE_RUN_GROUP=www-data).
  • It means that when you build your website upon Symfony2 shoulders and you run it under Apache, every writes and reads are made on behalf of the Apache user and group.

分析您的问题:

  • 首先,您会遇到以下错误:

  • First of all you have errors like:

Change the permissions of the "app/cache/" directory so that the web server can write into it.
Change the permissions of the "app/logs/" directory so that the web server can write into it.

因为你的 app/cacheapp/logs 文件夹对于你的 Apache usergroup 是不可写的.

because your app/cache and app/logs folders are not writable for your Apache user and group.

其次,通过执行:

sudo chmod +a "_www allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

您正在修改 app/cacheapp/logs 文件夹的访问控制列表 (ACL) 以授予某些权限whoami(基本上是你)和 _www.这种方法不起作用,可能有两个来源:

you are modifying the Access Control List (ACL) of the app/cache and app/logs folders in order to grant some permissions to whoami (basically you) and to _www. This approach does not work and can have two origins:

  1. 您正在修改 ACL,但您的内核和文件系统是否配置为考虑 ACL?

  1. You are modifying ACLs, but are your kernel and your file system configured to take into account ACLs?

您正在向 whoami_www 授予一些权限,但是您是否检查过您的 Apache 实例是否在这些用户之一下运行?

You are giving some permissions to whoami and to _www, but have you checked that your Apache instance runs under one of these users?

  • 第三,你的同事通过执行:

  • Thirdly your colleagues solve the problem by executing:

    sudo chmod -R 777 app/cache 
    

    这种方法之所以有效,有两个原因:

    This approach works because of two reasons:

    1. 您将所有权限(读取和写入)授予您系统上的每个用户 (777),因此您确定至少您的 Apache 用户和组也具有写入 <代码>应用程序/缓存.
    2. 您以递归方式 (-R) 执行此操作,因此在 app/cache 目录中创建的所有嵌套文件夹也受到新权限的影响.
    1. You give all permissions (reads and writes) to every user on your system (777), so you are sure that at least your Apache user and group have also the needed permissions to write in app/cache.
    2. You do it recursively (-R), so all the nested folders created in the app/cache directory are also concerned by the new permissions.

  • 简单的解决方案:

    1. 删除app/cacheapp/logs文件夹的内容:

    rm -rf app/cache/*
    rm -rf app/logs/*
    

  • 为您的 app/cacheapp/logs 文件夹授予所有权限(读取和写入):

  • Give all permissions (reads and writes) to your app/cache and app/logs folders:

    chmod 777 app/cache
    chmod 777 app/logs
    

  • 备注:

    • 还有其他解决方案(难度更大),例如授予特定 Apache 用户和组的权限以及使用 ACL 进行微调.

    这篇关于Symfony2 上的权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆