Symfony 2 Deploying App to Web - symfony

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.

Related

Installing new symfony project

[Symfony\Component\Filesystem\Exception\IOException]
Failed to create "/var/www/html/.143986856455d2a694104cb": mkdir(): Permiss
ion denied.
I tried to execute new symfony project, how can I handle this?
Set permissions on app/logs and app/cache folders:
$ rm -rf app/cache/*
$ rm -rf app/logs/*
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo chmod +a "$HTTPDUSER 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 haven't the permission to write in the file or the folder.
For create a new project of symfony you need to do this.
sudo apt-get install curl
after that you downloading composer and symfony by this command
sudo curl -sS https://getcomposer.org/installer | php
and
sudo curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
you edit the permission of symfony.
sudo chmod a+x /usr/local/bin/symfony
and create the project
symfony new NameOfTheProject
like simple user not in root or using sudo.
you can also download the demo like that
symfony demo
i advise you to do this without the "[" , "]"
chmod -R 777 /var/www/html/[NameProjectHere]
;)

Giving a default permission for cache folder

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

Symfony filesystem ACLs on ZFS

I'm writing Symfony2-based sites on a Ubuntu 12.04 server, with the code itself hosted on a ZFS filesystem partition/zpool. However, the instructions on the Symfony 2 installation page for setting ACLs on the directories (app/logs & app/cache) do not apply, because ZFS does not support the chmod +a or setfacl commands.
Is there a ZFS-compatible version of the below commands?
sudo setfacl -Rn -m u:"$APACHEUSER":rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dRn -m u:"$APACHEUSER":rwX -m u:`whoami`:rwX app/cache app/logs
ZFS supports acls. You can set them using chmod A+, which looks something like:
chmod A+user:alister:add_file:allow /path/to/dir
Have a look at this article.
To mimic the setfacl commands, you'll at least need the following permissions:
read_data
write_data
add_file
add_subdirectory
delete_child
file_inherit
dir_inherit
The commands would look like this:
chmod A+user:`whoami`:read_data/write_data/add_file/add_subdirectory/delete_child:file_inherit/dir_inherit:allow app/cache app/logs
chmod A+user:"$APACHEUSER":read_data/write_data/add_file/add_subdirectory/delete_child:file_inherit/dir_inherit:allow app/cache app/logs
I've gathered this from the article I mentioned, but have no experience with ZFS, so you might need to tweak the commands a bit.

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

Resources