skip to Main Content
Running multiple commands after deployment to Fortrabbit
Director of Engineering
October 16 2018

How do you run your migrations and clear your template cache on every deploy to fortrabbit?

We’ve been pretty happy with Fortrabbit as a hosting service for CraftCMS. It has a nice git based workflow, where you can push to a remote and deploy. This is great for automated builds (we use CircleCI) so that developers can focus on development, not deploying.

Often, you want to run a command after deploying. It may be that you need migrations to run. Or you might need to clear the cache. If you add an entry to your fortrabbit..yml (full docs) you can run an arbitrary command after a deploy is successful. If that command fails (or times out, a deployment can only take 10 minutes or the process is killed) the deploy doesn’t occur.

So, to run our migrations, we had a fortrabbit.yml that looked like this:

post: craft migrate/up --interactive 0

However, we wanted to clear the view cache, which you can do via the command line. It looks like this:

craft cache/flush-all

You cannot run two command as a post command in fortrabbit, unfortunately. I tried two different methods, combining them on one line:

post: craft migrate/up --interactive 0 &&
craft cache/flush-all

and having two separate post commands.

post: craft migrate/up --interactive 0 


craft cache/flush-all

Neither worked. What did work, however, was to write a small php script:

echo shell_exec('php craft migrate/up --interactive 0');
echo shell_exec('php craft cache/flush-all');

and then have that script called. The fortrabbit.yml file then looked like:

post: post.php

Echoing the results lets us see any issues that the php command. (More about the details of calling php from php.) This same strategy would work if you had to run multiple commands before deployment as well.

Culture Foundry is a next-level digital agency that helps you thrive in digital. We build, evolve and support websites and applications for clients who are graduating to the next level of complexity in their digital ventures. Our uncommon strengths are headless CMS architectures, design systems and 24/7 support. If you're not thriving in digital, you can be: Contact us to learn more.

(Psst! We also happen to be a great place to work.)

Back To Top