What should go in my Procfile
for a Django application on Heroku?
I tried:
web: python appname.py
because I found an example like that for python apps.
Further searching didn't make things any clearer except for that I might need to use gunicorn instead of python. I found various posts suggesting various formats such as:
web gunicorn
web:gunicorn
web: gunicorn
I have no clue what should come after gunicorn, some posts have the programming language, some have an IP address, some have various other things.
Some suggest running:
heroku ps:scale web=1
but that results in an error:
Scaling dynos... !
! Couldn't find that process type (web).
I just haven't got a clue and don't know where to turn.
Since posting I have watched some videos about this and tried:
web: gunicorn appname.wsgi
in my Procfile but it still doesn't work, still resulting in:
at=error code=H14 desc="No web processes running"
Heroku's Procfile
format is quite simple. As described in the documentation:
A Procfile declares its process types on individual lines, each with the following format:
<process type>: <command>
You can see that there should be a colon after the process type, so the
web gunicorn
example in your question is not going to work properly. You'll want to start the line with web:
.
<command>
indicates the command that every dyno of the process type should execute on startup, such asrake jobs:work
For Django, in development you'd typically use python manage.py runserver
to run the application, so a reasonable attempt for Django would be
web: python manage.py runserver
This should work, but it's not appropriate for production work:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
Instead, you should use a production-grade web server in production. Gunicorn is a common choice, and you can run your Django application with Gunicorn like so:
gunicorn myproject.wsgi
Putting that all together, a Procfile
for Django on Heroku might look like
web: gunicorn myproject.wsgi
where myproject
is the name of your Django project. This is exactly what Heroku's documentation suggests for Django applications.
Note that you'll have to add Gunicorn to your project dependencies so Heroku will install it. I recommend also installing it locally so you can use heroku local
to test your application on your dev machine in a way more similar to Heroku's production environment.
heroku ps:scale
is used to change the number and type of dynos for process types you have already defined. It has nothing to do with defining those process types. That's what your Procfile
is for.