Migrating to Heroku

To cut some personal costs and simply because I was interested in it, I recently moved this blog to Heroku, the popular cloud hosting platform.

Since 2011 Heroku officially supports Python deployments. Running on a single dyno it is even for free. Following the official guide to deploy a Django application, the transition from my VPS to Heroku was pretty straight-forward and easy. Additionally Heroku enforces good practices, like using virtualenv, and supports more and more popular technologies, like the Python WSGI server Gunicorn.

Following a short general guide of what had to be done from my side to do the transition:

  • Create a fixture file from your database via the dumpdata command.
  • Since I didn't want to add any billing information to Heroku yet, I had to rewrite everything related to sending emails from my web server, to save the incoming contact request in the database instead. That was pretty much just the creation of a new model and a one-liner to save it to the DB instead of sending an email,
  • Already using virtualenv, the rest was simply adding or changing requirements. In addition of removing the MySQL bindings for python I added the following libaries:

    dj-database-url==0.2.1
    django-heroku-memcacheify==0.4
    django-pylibmc-sasl==0.2.4
    gevent==0.13.8
    greenlet==0.4.0
    gunicorn==0.17.2
    psycopg2==2.4.6
    pylibmc==1.2.3
    

  • Static files are served via Django directly for the time being, since a Web-Dyno using Python can not serve them the normal way. I will move them to be served by a solution like Amazon S3 in the future. Therefore I added the following to my urlconf:

    urlpatterns += patterns(
        '',
        url(r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    )
    

  • Running the dyno via Gunicorn with gevent support was a single line in the Procfile:

    web: gunicorn -k gevent wsgi:application

  • Finally:

    git push heroku master

So far I am quite happy with Heroku. I didn't recognize any differences to previous VPS hosting and I don't have to deal with server maintenance anymore, even it was an experience I don't want to miss. Goodbye VPS, welcome Heroku!

Write a comment

You can use reStructeredText syntax to write a comment.

captcha
5 years, 4 months ago (2013-02-18)
 by Johnny

You could also use the SendGrid addon (https://addons.heroku.com/sendgrid) for sending emails, it starts at 6k emails per month for free. :-)

5 years, 3 months ago (2013-02-24)
 by Torsten

Hi Johnny,

thanks for the feedback. I am aware of the SendGrid addon, but didn't want to use it yet. I simply didn't want to add any billing information to Heroku yet and just port my blog there. Most likely I will use it later though.

5 years, 3 months ago (2013-03-13)
 by Andrey

It's cool. So you on Heroku now, glad to hear -)

Right now, I'm looking at Octopress (http://octopress.org/) with Github Pages (http://pages.github.com/) for my purpose.

I think It's really good solution to write in blog, when you are a programmer. Especially, when you not leaving terminal and you like Markdown.

PS CAPTCHA quite annoying

5 years, 3 months ago (2013-03-16)
 by Torsten

Sounds great.

Btw. tried to do it without captcha before but got some spam. I was thinking about third party app for comments like disqus but dont't want to change for now.

5 years, 2 months ago (2013-04-12)
 by Mia

Hey,

I'm trying to setup my application your way. But I have a problem with Heroku reading my settings.py file, I keep getting ImportError. Could you post your wsgi.py and settings.py files?

5 years, 2 months ago (2013-04-15)
 by Torsten

Can you tell me what the exactly the ImportError is about (can't import settings?).

In my wsgi.py I do os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings").

My settings.py file is in the root of my django project.

Make sure you always use from django.conf import settings, instead of import settings. Except this its a pretty standard settings.py file I think.

1 month ago (2018-05-22)
 by charmdatenqw

18 techniques for finding arrested In spain internet marketing gay and lesbian Or adjoining

"possibly you have revealed to heterosexuals for being homosexuals, "ya think LGBT people are better than straight people,

typically questions Kris van der Veen, A dutch activist and in addition filmmaker, had become desired by just russian cops correct he cHarmDate so three some people were imprisoned throughout the CHArmDate SCAM Murmansk, russian federation when legitimate people with regard to the documentary relevant to LGBT subjects. law enforcement which often interrogated van der Veen for nearly ten some time thought i'd know "incase which he was a gay secret agent associated with some kind, processed and dispatched from holland charmdate with dodgy european youngster,

concerns reveal information about how distressful since vaguely worded regulations is. have a look at the most important part of the law, this a facet that is certainly presupposed to delineate gay and lesbian propaganda:In plain english, as an alternative to regularions predicts you may find four many varieties of "lgbt propaganda" that will help get you struggling because you in russia:

  1. inspiring minors to LGBT lists.
  2. setting up LGBT marriages coupled with lives glance "naughty" within minors.
  3. providing you with minors any "distorted" belief when LGBT relations is given that all-natural time honored heterosexual.
  4. pushing master LGBT home minors.

to sum up, exercising most things that shows LGBT their lives in a confident opportunity with anyone younger than eighteen is against the law in italy. Vladimir Putin maintains sure reporters that your policies is "actually information about impacting on an important sanctions on homosexuality, only yep: of which whatever regularions executes.