← back to the blog
fousa blog
Staging environment on Heroku
Sometimes you want to test your application on one of your production servers so you can let your clients test your application in real life!
What I wanted to do is point the master branch to dev.testapp.com and the production branch to testapp.com. The subdomain dev.testapp.com is my staging environment where the clients can play with the application!
STAGING ENVIRONMENT
This is how you setup your Heroku staging environment from your current master branch.
WATCH OUT: Make sure you have a config/environments/staging.rb file.
git checkout masterheroku create dev-testapp --remote staging
heroku config.add RACK_ENV=staging --app dev-testapp
git push staging master
heroku rake db:migrate --app dev-testapp
PRODUCTION ENVIRONMENT
This is how you setup your Heroku production environment from your current production branch.
WATCH OUT: Make sure you have a config/environments/production.rb file.
git checkout productionheroku create testapp --remote production
heroku config:add RACK_ENV=production --app testapp
git push production production:master
heroku rake db:migrate --app testapp
With every Heroku command you execute you'll have to specify your application on which you want to use the command.
SMALL EXPLANATION
--remote stagingAdds a git remote repository staging instead of the default heroku repository you would normally use to push to the Heroku servers. (git push heroku becomes git push staging)
RACK_ENV=stagingSet the environment in which your application has to be deployed. BE AWARE: development environment is not recommended, because it slows down your application...
REFERENCE
Thanks to this reference: Deploying Multiple Environments on Heroku.
Send me some feedback!