Symfony - clear cache

I was a bit surprised when I learnt that the only way to clear the cache on a Symfony 4 system is to run a local command on the system, as I don't want anyone to log into a production server (deployment is automated). And when you run the command, you must run it as the user that your web server is running under.  For distros of the Red Hat family, this user is apache by default.  For the Debian family, it is www-data.

Here is how I did it.  Let's say that the user that is used for automated deployment is 'user123', here's what I did:

  1. Create a file in the /etc/sudoers.d directory (example: /etc/sudoers.d/user123_bin_console)
  2. Put this line in the file: user123 ALL=(apache) NOPASSWD: /path/to/bin/console
  3. Once this file is in place, you can log into the system and execute the sudo -l command to show what commands this user is allowed to execute via sudo and make sure the command you specified in the newly created file is present
  4. To clear the cache, execute this command as user123: sudo -u apache /path/to/bin/console -vvv cache:clear. The command will be executed as apache, so the ownership of the files created during the process will be owned by the web server, which is what you want for Symfony
This was on a RHEL 7 system. Of course, you have to change the name of the user and the path to match your requirements.

Comments

Popular posts from this blog

Postgresql tips and links

Networker automated recovery testing using the REST API - introduction

KeePass enforced configuration