Skip to main content

Improve Symfony3 cache/logs performance by environment

Tired of the permission errors with your cache/logs in a Vagrant environment? Me too!

After being mildly annoyed with having to manually delete /var/cache and /var/logs repeatedly during “local” development, I decided to brut force matters into my own hands and solve this little annoyance once and for all. Ironically, Symfony 3.3 is addressing some of this, so it may be obsolete by then, but in the meantime…

What are we doing here?

  1. Define cache and logs directories for a specific environment.
    1. Wouldn’t it be awesome if we could customize these as parameters in the FrameworkBundle? Yes, yes it would!
  2. Write a simple CacheCommand that overrides the default cache:clear
  3. PARTY!!!!

Customize your getCacheDir and getLogDir methods by your environment

In my case, I typically use Vagrant/Virtualbox for local development, and Docker containers/bitbucket-pipelines for “test” while Production is a variety/flavor of AWS EC2 instances which have some additional flare.

Write a CacheCommand you can love and cherish forever and ever

PARTY!!!

Now you can enjoy life and all references to cache:clear will run your new and improved command that will also work noticably faster in Vagrant development environments; thanks entirely to Benjamin Eberlei and his wonderful blog post.

Enjoy!

cd /path/to/myapp && php bin/console cache:clear

Vagrant `/sbin/ifdown eth1 2> /dev/null`

If you’re experiencing a fatal error when loading a Vagrant machine, chances are you just need to upgrade your version of Vagrant.

Specifically this error, when using ubuntu/xenial (Ubuntu 16.04 LTS)

Upgrade your local install of Vagrant to at least 1.8.5 and you’ll be set.

Must have Vagrant plugins

Landrush

If you’re a full-stack developer or otherwise involved in multi-tiered application development, you’ll often find your applications littered with various subdomains. For example apikbmail, etc. These can be incredibly cumbersome to setup locally when developing, and Landrush is the answer.

Once installed, you’ll be able to configure countless subdomains with your Vagrantfile, and minimize the headache of getting to work!

Ansible

The ansible plugin allows you to run playbooks from Vagrant, completely optimizing your ability to deploy development machines with reusable playbooks and/or roles on your workstation.

You can find more information about the plugin at the official Hashicorp documentation.