Home » Php » php – How to run a Symfony application on a read-only system, where 'var/cache' can't be written into?

php – How to run a Symfony application on a read-only system, where 'var/cache' can't be written into?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m trying to configure my Symfony 5 application to be run in a read-only system.

But despite configuring it to use Memcached instead of the filesystem for the cached data that is usually written in the application var/cache directory
(according to the documentation, all I need to do is to change the cache adapter for the system cache pool and for the app cache pool if desired), I find that Symfony continues writing to var/cache.

What am I missing? How can I deploy the application in a read only system?

How to&Answers:

If you configure the system not to use a filesystem based cache, you only need to run php bin/console cache:warmup, on deployment and then deploy all the generated code (including the contents of var/cache) to the execution environment.

From here:

In the prod environment (i.e. when APP_ENV is prod and APP_DEBUG is 0), as long as you run php bin/console cache:warmup, no cache files will need to be written to disk at runtime. The only exception is when using a filesystem-based cache, such as Doctrine’s query result cache or Symfony’s cache with a filesystem provider configured.

You’ll also need to make sure that you are not logging to disk.

Nowadays, since Symfony 4, var/cache is mostly meant to store long term artefacts like compiled container files, compiled translations, and/or Doctrine proxies. Not for temporary cache files.

Following these practices, a well configured application should be able to be deployed on read-only environments.