0
votes

I am deploying Symfony to a web server, and once deployed I want to clear the cache. I am using a umask of 0000 for now to get around any potential permission issues (I am doing the clear under the deploument user and running the site under the apache user).

I am using /var/symfony/cache/projectname/branchname/environment and /var/symfony/log/projectname/branchname/environment as the dirs to save the cache and logs. These are configured in the AppKernel.php file.

When I deploy (using 'php bin/console cache:clear --env=prod --no-debug') I get a message that says:

[RuntimeException] Unable to create the logs directory ()

I have done a touch to create a file in the /var/symfony/log/ dir and it worked fine, so any idea why the cache clear command is failing?

We are using a sticky bit from the /var/symfony/ dir up to set permissions as drwxrws--t so that when we do the cache clear as the deployment user, it can set user as apache and group as www with them both in the www group.

1
The user that runs the script doesn't have permissions to create those directories. You can create then beforehand or give the user permissions to create files in the parent directory. You can do this without touching the user/group for the parent using ACLs. If the server is Linux look at the setfacl and getfacl commands.solarc
No, that wasn't the problem, I have posted an answer for people for in future.MicWit

1 Answers

1
votes

It seems that Symfony will not create the directory structure to store the logs (though it seems to for the cache). This means that the log directory (in this case /var/symfony/log/projectname/branchname/environment/ needs to exist before clearing the cache.

In my case to get around this I will run the check in my deployment (shell) script to make sure the directory exists and create it if it doesn't.

NOTE: If you browse to the site (and permissions are correct) it will create the log directory. However, if you use the console clear cache command it will not create the path and will fail.