Giving a default permission for cache folder - symfony

The problem is when I clear caches in my Symfony project on production environment, I should type this command for giving right permissions to cache folder:
cd app/cache
sudo chmod -R a+w *
But is there any way to not typing these commands each time?

try this
sudo setfacl -dR -m u::rwX app/cache

Related

Symfony 2 Deploying App to Web

When deploying symfony2 to the web it still thinks im using local folders for instant..
[public]$ php app/console cache:clear --env=prod --no-debug
[RuntimeException]
Unable to write in the "C:/Users/brent.french/Documents/www/clients/app/app/cache/prod" directory
I tried following http://symfony.com/doc/current/cookbook/deployment-tools.html with no success any ideas?
FROM SSH :
USING ACL ON A SYSTEM SUPPORTING chmod +a
rm -rf app/cache/*
rm -rf app/logs/*
sudo chmod +a "www-data allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "yourname allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
USING ACL ON A SYSTEM NOT SUPPORTING chmod +a
sudo setfacl -R -m u:www-data:rwx -m u:yourname:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:yourname:rwx app/cache app/logs
Without using ACL
just after your opening PHP tag in : "app/console", "web/app.php" and "web/app_dev.php" add :
umask(0002); // This will let the permissions be 0775
// or
umask(0000); // This will let the permissions be 0777
Source : Symfony Doc
Deleted the app/cache/* folder to remove any old information and this fixed it.

Unable to write cache

Hi all im working with Symfony2. I dont have problems with the project in my computer but when i upload the files in the web server, fails for cache permissions.
I set the permissions in my computer with this steps:
$ rm -rf app/cache/*
$ rm -rf app/logs/*
$ APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
As sugest The Doc.
So, upload the app/cache and app/logs (empty) folders to my webserver.
Whe in try access to the web project, Symfony says:
Fatal error: Uncaught exception 'RuntimeException' with message 'Could
not create cache directory
"/home/coleman/public_html/apps/app/cache/prod/annotations"
I check the folder with Filezilla, and the permissions are 666 (read and write for all).
I dont know that are wrong.
Any ideas ?.
See this link:
Configuration and Setup
It's pretty common issue. You need to configure permissions though ACL...
Is your project name "apps" ? If not, seems like you put your web folder content at root without modify the relative paths in your app.php

Permission problems in Symfony2 on Mac OSX using XAMPP

I am using XAMPP on Mac OSX. I followed the Symfony2 instructions to set app/cache and app/logs permission -
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"
Moreover, I also run the sudo chmod -R 777 app/cache/* and sudo chmod -R 777 app/logs/*
It worked as well. However, when I close the XAMPP and open it again. It always shows the following RuntimeException, and I have to set their permission again and again.
RuntimeException: Failed to write cache file "/Applications/XAMPP/xamppfiles/htdocs/Jobeet/app/cache/dev/classes.php".
I don't find anyone have the same problem as me.
How can I permanently set their permission?

Permissions issues on Symfony2

This question has been asked several times but none of the solutions fix it in my situation.
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.
Following the guide under "Setting up Permissions":
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?
Some preliminary explanations:
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.
Some words about Apache:
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.
Analyze of your problems:
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.
because your app/cache and app/logs folders are not writable for your Apache user and group.
Secondly, by executing:
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
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:
You are modifying ACLs, but are your kernel and your file system configured to take into account ACLs?
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:
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.
You do it recursively (-R), so all the nested folders created in the app/cache directory are also concerned by the new permissions.
Simple solution:
Delete the content of your app/cache and app/logs folders:
rm -rf app/cache/*
rm -rf app/logs/*
Give all permissions (reads and writes) to your app/cache and app/logs folders:
chmod 777 app/cache
chmod 777 app/logs
Remarks:
There are also other solutions (with a greater difficulty) like giving permission to the specific Apache user and group and using ACLs for fine tuning.
The guide under the "Setting up permissions" says that if your system doesn't support chmod +a you have to do this:
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
If that doesn't work try this:
umask(0002); // This will let the permissions be 0775
// or
umask(0000); // This will let the permissions be 0777
First solution worked for me. I hope it helps someone with the same type of issue.
rm -rf app/cache/*
rm -rf app/logs/*
APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs
Source: http://symfony.com/doc/current/book/installation.html#configuration-and-setup
The Accepted answer is great however, in my case (Centos 7 & Symfony 4.3) even after setting permissions i was still getting error. It turns out SELinux was blocking Apache.
The following worked for me(change my-project to your Symfony install folder).
sudo chcon -R -t httpd_sys_script_rw_t /var/www/my-project/var/cache/
sudo chcon -R -t httpd_sys_script_rw_t /var/www/my-project/var/log/
You can also disable SELinux but only temporarily for the current session to isolate the issue(I don't recommend this for prod)
sudo setenforce 0
Credits

I can't reinstall symfony2

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

Resources