I am using Symfony 2.0.12 in a Mac Os X Lion (10.7.4).
For some reason, every time I clear cache (php app/console cache:clear), the permissions of cache/* folder are lost.
The result is that I try to enter my application and it start to give me a bounch of errors like "unable to write in app/cache/dev/XXX folder".
So there starts a "fight" against the machine. No sooner I give permissions for that folder, quickly I get an error message for the next YYY folder. And that happens during about 8 or 9 folders until it's me the winner and everything apparently starts to works normally again.
Did anyone pass through this? How can I manage to conserve the permissions when clearing the cache?
in the documentation there are some alternative commands on how to set up the permissions. but i dunno if they work for mac. Check the Setting up Permissions box.
http://symfony.com/doc/current/book/installation.html
on my ubuntu system the following commands made the permissions permanent
sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
making the webserver run as your user is not a good idea in my opinion because the webserver should not have access to your personal files and so on...
If you're running the commands as a different user than the php process that create the cache files then this will happen. You'll either have to run the commands as the web server user, make the web server run as your user, or chown/chmod the app/cache app/logs directories after you run commands.
Related
I am setting up a new server and installed Ubuntu 18.04 in combination with Apache2. My project is stored in /var/www/project. In apache2.conf I added
<Directory /var/www/project/>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
In my virtualhosts file I point to /var/www/project/public
When I go to the Ip address of my server I see my project and everything works, except one thing:
whenever I clear the cache with php bin/console cache:clear the permissions of my directory var are messed up which results in errors in the production environment.
I can fix this with:
chmod -R 777 var/
But the problem returns wheneven I clear the cache again. I tried with different users including root, but always the same problem. I do not understand what is causing this. In the documentation on file permissions it says:
In Symfony 3.x, you needed to do some extra work to make sure that your cache directory was writable. But that is no longer true! In Symfony 4, everything works automatically
Well not for me, but what could cause the problem?
The problem
The cache directory is owned by the user executing the cache:clear command.
Lets say your project files are owned by www-data.
Clearing the cache with root user
Cache is owned by root
www-data can't write in cache directory
Solution
execute cache:clear using the user owning the files.
Login as www-data: su www-data -s /bin/bash
clear the cache ./bin/console cache:clear
Depending on your settings, your www-data user may be different
The solution that worked for me (using Symfony 3.x and Ubuntu 18.04) is the one explained in the official site, here:
https://symfony.com/doc/3.4/setup/file_permissions.html#using-acl-on-a-system-that-supports-setfacl-linux-bsd
Maybe that solution work also with Symfony 4?
Extract:
3. Using ACL on a System that Supports setfacl (Linux/BSD)
Most Linux and BSD distributions don't support chmod +a, but do
support another utility called setfacl. You may need to install
setfacl and enable ACL support on your disk partition before using it.
Then, use the following script to determine your web server user and
grant the needed permissions:
HTTPDUSER=$(ps axo user,comm | grep -E
'[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1
| cut -d\ -f1)
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
Note:
The first setfacl command sets permissions for future files and
folders, while the second one sets permissions on the existing files
and folders. Both of these commands assign permissions for the system
user and the Apache user.
setfacl isn't available on NFS mount points. However, storing cache
and logs over NFS is strongly discouraged for performance reasons.
Personal hint:
sudo apt-get install setfacl may says "unable to find setfacl".
If so:
check if setfacl is present: setfacl -h
setfacl is part of the acl package, so install acl if missed
It took me quite a while to solve the problem in Symfony 4.4 that only was present in PROD but not in DEV. I still don't know what difference between PROD and DEV caused it, however. At least it's working now.
If ACL is present, the first solution in https://symfony.com/doc/4.4/setup/file_permissions.html#permissions-required-by-symfony-applications should work. I just manually set the HTTPDUSER since the given code returned the wrong one. Else, setting the permissions after every single cache:clear should do the job, too:
sudo chown -R "$local_user":"$webserver_group" "$app_dir/var/"
sudo chmod -R 0777 "$app_dir/var/"
Maybe you have to manually delete old files in var/ bevore first by rm -rf var/*
at our company we're using Docker and most of the developers used Ubuntu. I now switched to Fedora and set everything up except for the access rights through ACL.
In Ubuntu we did a simple setfacl -R -m g:www-data:rwX -m u:$USER:rwX {folderList}, however in Fedora26 the group www-data does not exist.
Welp, I could simply create the group but this doesn't fix the problem I guess, because it somehow still needs to be "connected" to docker, right?
The problem I'm having is, that the Symfony application can't write into the cache folders because It doesn't have rights. This is what we use setfacl for, but I have no idea how to fix this in Fedora.
I solved this by connecting into my docker machine, making an cat /etc/passwd | grep www-data and saw, that the id of this user/group is 33 (the same, the php-fpm child process pools are created) and then simply used
setfacl -R -m g:www-data:rwX -m u:$USER:rwX {folderList}
I want to clear the cache, but I got an error that file is not writable, so I choose to delete cache folder manually, but that too doesn't work.
I have all permissions to delete files but I didn't understand what's the problem.
may be ACL can help you, try this:
sudo chmod -R 777 app/cache
sudo setfacl -dR -m u::rwX app/cache
Symfony2 doc has clear instructions how to setup your cache in proper way "Setting up Permissions" http://symfony.com/doc/current/book/installation.html
I'm new to Linux (using Debian). How to make writeable dir for user and for web-server?
I connect to server via ssh, upload my files. And run next commands:
sudo chown -R www-data:www-data writeable/
sudo chmod -R g+rw writeable/
Then nginx and php (running by www-data user) writes files to writeable. Auter that i do not able to edit or delete those files.
Please help me. I know what that question was asked a million times, but i could not to find solution.
Thanks!
not sure to understand, but I guess you want your dir to be writable for user "www-data" and for another user, let's call it "medvedev".
You can put both users in a group, and grant write permissions for owner (www-data) and group.
useradd -G medvedev www-data
I am using symfony2 standard version, on linux mint 12.
I created a symfony2 project 2 days and everything went well, i installed a wrong bundle and messed up the project so i decided to delete the Symfony folder, and reinstall symfony.
And now, if i do php app/check.php i get the timezone error, although my timezone is set correctly, and the configuration page looks like this
i tried
rm -rf app/cache/*
rm -rf app/logs/*
and i tried
chmod -R 777 app/cache app/logs
could not fix it
Edit
php bin/vendors install --reinstall fixed the issue (Hakan Deryal thank you sir). However, I found out that if you rename the Symfony folder to symfony or any other name, you'll get the error, or everything goes normal but when you press Configure your Symfony Application online you'll get this error
Server error
The website encountered an error while retrieving http://localhost/mysite/web/app_dev.php/_configurator/. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
So my next question is how to change of the symfony2 project , say you have 2 symfony2 project on localhost, they can't have the same name
Hi some time just clearing cache is not enough.
Event I came across the same type of problem, after clearing the cache, try to rebuild it.
commands are:
$ sudo php app/console cache:clear
$ sudo php app/console cache:warmup
$ sudo chmod 777 -R app/cache app/logs
The best way to set permission is to use ACLs:
sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
You could also try a chown www-data app/logs
Symfony reinstall at this point is not very relevant