Home » Php » php – How to fix this symfony permission error?

php – How to fix this symfony permission error?

Posted by: admin July 12, 2020 Leave a comment

Questions:

On my live site I’m facing this problem when I load my browser:

ContextErrorException in FileProfilerStorage.php line 158: Warning:
file_put_contents(/var/www/html/var/cache/dev/profiler/c9/73/fb73c9):
failed to open stream: Permission denied

How can I fix this problem at the live site?

How to&Answers:

Run

sudo chmod -R 777 var/cache

in your project directory, later clear the cache using

app/console cache:clear

An reset permissions again

sudo chmod -R 777 var/cache

Every time the cache is cleared reset permissions of folder cache to avoid this type of problems with created files during the clear process.

Note: app/console could be bin/console

Answer:

You should try this set of permissions which are recommended by AWS:

First you need through a terminal go to your project directory and run the command:

ls -las

where you will see something like:

enter image description here

Note the columns where it says: webapp, that tells you which user/group have access to your project, so what you need to do now is go to your apache config file (normally you can find it in linux on: /etc/httpd/conf/httpd.conf) once you opened the file by using vi, vim or you favourite text editor you should look for User & Group and ensure that the user/group is the same one that the one from the image above and ensure that the user belongs to the group you have had configured or set on your httpd.conf then you should run the following command to apply the right set of permissions for users & groups by doing:

sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

and now it should work fine.

Note that /var/www is an example of where you could host your project but it depends on your configuration in the file httpd.conf

Hope this helps.