Heroku init

How can a Yii2 advanced-template application be deployed on Heroku? The Heroku file-system is read only so any changes made by opening a bash session and running php init are overwritten. I feel like I must be missing something because I’ve seen plenty of people mention successfully deploying. I’ve tried using the Heroku release-phase but the changes still seem to be overwritten.

The way to solve this is with a post install script in composer. In your composer file add a scripts key and use the post-install-cmd key to specify the script you want to run:




"require":{},

"scripts": {

    "post-install-cmd": "sh post-install-cmd.sh"

}



Your post-install-cmd.sh file should look like this:




#!/bin/sh

if [ -n "$DYNO" ]  && [ -n "$ENV" ]; then

    php init --env=$ENV --overwrite=All

    php yii migrate/up --interactive=0

    php yii cache/flush-all

    php yii cache/flush-schema --interactive=0

fi



Heroku will run composer automatically and so your migrations will also be run - don’t forget to include any migrations that need to be run for any extensions you may be using.