首页 > 解决方案 > Symfony 3.4 Apache Permission WebServer unable to write file in folder non writable

问题描述

I'm running Symfony using Apache WebServer instead of built-in webserver, in order to switch from dev to production environment, following theses official instructions: https://symfony.com/doc/current/setup/web_server_configuration.html

When I try to upload an image to my site folder I got

Unable to write in the 
"/var/www/html/site/src/../public/front/cms/explanatory_rubric" directory

When I was running using Symfony built in server, using the port 8000 it was working and my folder was writable. I know it's a trouble with Apache Permissions. There are a lot of questions about that and I read carefully each of them, specially this one, explaining good practices about file permissions with Apache,and this one, this one, this one,and this one, etc

When I check my chmod owner non-writable folder I get:

ls -l
total 4
drwxr-xr-x 3 root www-data 4096 Jun  1 11:38 explanatory_rubric

I changed the chmod owner of the folder from www-data to root to give a write permission.

I also tried to give permission via my Apache configuration file.

This is my Apache configuration for SSL:

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerName www.mysite.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html/site/public>
         AllowOverride All
         Order Allow,Deny
         Allow from All
    </Directory>


    <Directory /var/www/html/site/public/front/cms/explanatory_rubric>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

标签: apachesymfonychmodchown

解决方案


已解决:我将 chown 从 ubuntu 更新为 www-data,并授予特定文件夹的 chmod 权限:我还注意到,在symfony/apache-pack包的index.php中,我们可以找到一个umask(000),它可能是我烦恼的根源

我解决它的命令是:

chown www-data:www-data -R /my/folder # with Apache2
chown apache:apache -R /my/folder # with Apache
chmod -R 777 /my/folder

推荐阅读