【问题标题】:Symfony Project, can't fixing file permissionsSymfony 项目,无法修复文件权限
【发布时间】:2017-02-08 02:46:33
【问题描述】:

当我尝试更新 composer 或清除我的 symfony 项目的缓存时,我经常遇到文件权限错误。 然而我的文件是根据 symfony 的文档正确设置的:http://symfony.com/doc/current/setup/file_permissions.html

我在linux下,Manjaro Budgie版(最后一个稳定版) 服务器 apache 最新版本

例如:

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

 // Clearing the cache for the dev environment with debug true                                                          

  [Symfony\Component\Filesystem\Exception\IOException]                                                                                                                                                
  Failed to remove file "/srv/http/PetitMur/var/cache/de~/annotations/1a/5b504d5c506c6174666f726d42756e646c655c456e746974795c41727469636c652474616773405b416e6e6f745d5d5b315d.doctrinecache.data": .  

此文件具有以下权限:

pierre $ la /srv/http/PetitMur/var/cache/de~/annotations...data
-rw-rw-r--+ 1 http http 234 29.09.2016 18:13 /srv/http/PetitMur/var/cache/de~/annotations...data

我知道,这个问题经常出现。但是我已经按照symfony的doc设置了权限文件。目前我必须在超级用户上运行命令才能使其工作,这是不正常的。

你有想法吗?

编辑:

php bin/symfony_requirements

Symfony Requirements Checker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> PHP is using the following php.ini file:
  /etc/php/php.ini

> Checking Symfony requirements:
  .............................WW......


 [OK]                                         
 Your system is ready to run Symfony projects 


Optional recommendations to improve your setup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 * intl extension should be available
   > Install and enable the intl extension (used for validators).

 * a PHP accelerator should be installed
   > Install and/or enable a PHP accelerator (highly recommended).


Note  The command console could use a different php.ini file
~~~~  than the one used with your web server. To be on the
      safe side, please check the requirements from your web
      server using the web/config.php script.

【问题讨论】:

  • 你试过用 rm -rf var/cache/* 清除吗?
  • 是的,但过一段时间问题又回来了。
  • 哪个网络服务器?是阿帕奇吗?
  • 还有,请问是哪个 Linux 发行版。
  • 文件归用户htttp所有,您的clearCache命令是否在root下运行?...可能是用户权限问题,而不是文件权限问题

标签: php composer-php symfony


【解决方案1】:

我怀疑权限和用户组设置可能不正确。

进入您的 Apache httpd.conf 文件以检查用户/组设置。你会看到这样的行:

User apache
Group apache

以上来自我的 CentOS 6 系统,httpd.conf 在/etc/httpd/conf/ 文件夹下。你的可能在不同的位置,可能是用户httpd(检查一下)。

然后为您的 Symfony3 项目设置正确的用户/组:

sudo chown -R apache:apache /srv/http/PetitMur

上述命令将 user:group 都设置为apache,您可能必须使用httpd

现在删除您的旧缓存文件和日志,因为它们之前可能是用错误的用户创建的:

sudo rm -rf var/cache/*
sudo rm -rf var/logs/*

然后再次运行 setfacl,确保剪切和粘贴(有一个大写 X)并使用正确的用户(apache 或 httpd):

$ sudo setfacl -R -m u:apache:rwX -m u:`whoami`:rwX var
$ sudo setfacl -dR -m u:apache:rwX -m u:`whoami`:rwX var

然后测试您的系统,看看问题是否得到解决。

【讨论】:

  • 在我的情况下,用户和组在我的 hhtpd.conf 中是“http”。我告诉你我之前已经尝试过这个......但是对你来说我再试一次 => pierre $ composer update 使用包信息加载作曲家存储库更新依赖项(包括 require-dev) 没有安装或更新 [ErrorException] file_put_contents (/srv/http/PetitMur/vendor/composer/installed.json):打开流失败:权限被拒绝
  • And => pierre $ la /srv/http/PetitMur/vendor/composer/installed.json -rw-r--r-- 1 http http 81281 29.09.2016 19:50 /srv/ http/PetitMur/vendor/composer
  • 你试过了吗:sudo composer update???您可能必须指向作曲家的位置。使用whereis composer 找到它。
  • 从上面引用“目前我必须在超级用户上运行命令才能使其工作,这不正常。”我的二进制作曲家有这个权利:-rwxr-xr-x 1 root root 1704783 17.09.2016 13:56 /usr/bin/composer*
  • 是的,我有完全相同的问题,这就是我发布问题的原因。我的生产环境中也存在同样的问题。我有一个单独的开发环境,我使用 root 用户登录。我也使用 Eclipse 作为 IDE,但它在开发环境中使用 root 用户。然后我使用 SCP 将文件从开发环境复制到我的home 目录中的生产机器。然后在生产机器上,我从我的home 目录复制到 apache DocumentRoot,之后我是sudo chmod -R apache:apache /var/www/html/SymfonyRoot。这工作正常。
【解决方案2】:

我已经尝试过这个“sudo chown -R http:pierre Myproject”,目前这适用于清除缓存,但不适用于作曲家。

【讨论】:

    猜你喜欢
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 2012-03-06
    相关资源
    最近更新 更多