Heroku deploy not working
vonpupp opened this issue · 10 comments
Hello,
I'm trying to deploy this app to Heroku. I'm new to Django and Heroku. I'did this and it didn't work
- Fresh clone
- Edited env/DATABASE_URL
- make initialdeploy
I also tried locally, when I try to run it with foreman start
, I get: "This webpage is not available", and I noticed that the url changes to https instead of http.
Heroku error log:
make initialdeploy
git push heroku master
Everything up-to-date
heroku run django-admin.py syncdb --noinput
Running `django-admin.py syncdb --noinput` attached to terminal... up, run.6427
Traceback (most recent call last):
File "/app/.heroku/python/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
heroku run django-admin.py collectstatic
Running `django-admin.py collectstatic` attached to terminal... up, run.7125
Unknown command: 'collectstatic'
Type 'django-admin.py help' for usage.
heroku run django-admin.py fix_counts
Running `django-admin.py fix_counts` attached to terminal... up, run.5902
Unknown command: 'fix_counts'
Type 'django-admin.py help' for usage.
Note that if I run heroku run python manage.py syncdb
, I don't get any error on the console, but it still doesn't work at the end.
Files in env/
are only for local development. On heroku you need to create the corresponding environment variables via heroku config
. It seems your DJANGO_SETTINGS_MODULE
isn't set on heroku.
Thanks a lot Bruno.
Now I do have the environment variables on Heroku, but it still doesn't work. I'm trying to troubleshoot locally, when I try to run it with foreman start
, I get: "This webpage is not available", and I noticed that the url changes to https instead of http.
Where I can either put the certificate or change to http?
Thanks again.
Can you show:
- the list of environment variables you have
- the Foreman output when you try to access the local site
- the full URL that your browser tries to access when you get the "This webpage is not available" error message.
Locally you don't need HTTPS. Things should just work with foreman start -f Procfile.dev
.
Thanks for your reply Bruno,
I got the prior error "This webpage is not available", when I tried to change some settings on settings.py to remove SSL, but I checked out to the original settings.py to make sure I'm not modifying your original code.
If I run it locally with foreman start -f Procfile.dev
it works fine, but when I try it with the default Procfile (foreman start
) it doesn't seems to work (error below).
- List of environment variables:
cat .env
PYTHONUNBUFFERED=true
PROJ=djangopeople
APP=djangopeople
DJANGO_SETTINGS_MODULE=djangopeople.settings
DATABASE_URL=postgres://tzlaaffhkxqfkz:<removed>@ec2-54-235-192-45.compute-1.amazonaws.com:5432/d19qg79ipuc8o6
SECRET_KEY="some secret key"
API_PASSWORD=""
FROM_EMAIL="Django People <people@djangoproject.com>"
AWS_ACCESS_KEY=""
AWS_SECRET_KEY=""
AWS_BUCKET_NAME=""
- Foreman output:
foreman start
(I don't get any error)
15:23:10 web.1 | started with pid 16688
15:23:10 web.1 | 2013-07-22 15:23:10 [16688] [INFO] Starting gunicorn 0.14.6
15:23:10 web.1 | 2013-07-22 15:23:10 [16688] [INFO] Listening at: http://0.0.0.0:5000 (16688)
15:23:10 web.1 | 2013-07-22 15:23:10 [16688] [INFO] Using worker: gevent
15:23:10 web.1 | 2013-07-22 15:23:10 [16691] [INFO] Booting worker with pid: 16691
15:23:10 web.1 | 2013-07-22 15:23:10 [16692] [INFO] Booting worker with pid: 16692
15:23:10 web.1 | 2013-07-22 15:23:10 [16693] [INFO] Booting worker with pid: 16693
15:23:10 web.1 | 2013-07-22 15:23:10 [16694] [INFO] Booting worker with pid: 16694
- Full URL:
http://localhost:5000/
,http://127.0.0.1:5000/
orhttp://<local-IP>:5000/
, all or them switches automatically to https and gives the same error.
Error:
SSL connection error
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
Questions:
- Having S3/AWS is mandatory for deploying on Heroku? If yes, is there any way to avoid S3?
- Is it possible to run it with
foreman start
locally? How?
Thanks a lot for your help!
Ok, the settings assume that when you deploy you run the site over SSL:
https://github.com/brutasse/djangopeople/blob/master/djangopeople/settings.py#L189-L214
On heroku you have SSL for free on your .herokuapp.com
domain. Otherwise you have to pay them to activate SSL + get a valid certificate.
AWS is used for the staticfiles storage backend (S3) and for sending emails (SES). One way to avoid S3 would be to use dj-static instead. As for emails, you need some kind of email service.
foreman start
simulates the production environment. To run locally, use foreman start -f Procfile.dev
or python manage.py runserver
.
Thanks Bruno,
I noticed some errors on heroku logs
, the first one seems to be solved by adding heroku config:set CANONICAL_HOSTNAME=young-reaches-4943.herokuapp.com
. Later I tried adding dj-static to the requirements and changing the wsgi.py script and run make deploy
.
Now it seems to work, even that I need to tune the static files location... I will do more tests. Would it be possible to have the static files in another [sub]domain by copying the djangopeople/static folder? Something like static.anotherdomain.com? What should I change in that case?
I will also try to deploy to http://hosting4django.net/ to see if it's easier than heroku, but it doesn't seems likely.
Thanks a lot for your help.
If you want the static files on another domain:
- Set
STATICFILES_STORAGE
to its default value of'django.contrib.staticfiles.storage.StaticFilesStorage'
- Run
python manage.py collectstatic --noinput
on your development environment - Copy the files to the domain/subdomain you want
- Alter
STATIC_URL
to point to that domain.
Thanks a lot Bruno,
I will try that. So far it seems to work fine with Heroku.
I appreciate your patience, help and support.
Regards!