beta-developper
beta-developper

Reputation: 1774

Symfony can't write in cache folder on CentOS 7 even with the right permissions

Symfony cannot write in cache folder even i give full permissions to that folder

chmod 777 -R /path/to/symfony/var

But I am always getting these error

Cache directory "/path/to/symfony/var/cache/dev" is not writable.

I am on Centos 7 and I use nginx and php7

I never had this problem on Ubuntu or Windows. It's just when i moved my application to CentOS

One suggest to me to run those commands on the var folder

chcon -R -t httpd_sys_content_rw_t /path/to/symfony/var
systemctl restart nginx

This solution worked once. But after a while i got the same problem. I tried to re-run tose commands but nothing changed.

Any ideas?

Upvotes: 2

Views: 1700

Answers (1)

beta-developper
beta-developper

Reputation: 1774

I've solved this issue. Here is how.

First, Nginx and php-fpm are running using the nginx user. This user is created automaticlly when installing Nginx.

On the /etc/nginx/nginx.conf

user  nginx;

And on the /etc/php-fpm.d/www.conf

user = nginx
group = nginx
...
...
listen.owner = nginx
listen.group = nginx
listen.mode  = 0660

Second the permissions on the symfony app are set to 755 and the owner is changed to nginx user/group (The user Nginx and php-fpm are using)

sudo chown -R nginx:nginx /path/to/symfony

sudo chmod 0755 -R /path/to/symfony

Then, I run two commands. The first is to ennable the httpd connections And the second allows the httpd process to read and write on the /path/to/symfony folder

sudo setsebool -P httpd_can_network_connect on

sudo chcon -R -t httpd_sys_content_rw_t /path/to/symfony

Finanlly, restarting the Nginx service

sudo systemctl restart nginx

Upvotes: 4

Related Questions