Django, EC2 and Ubuntu
I just write this post to not forget how I expend a big amount of hours for just running a couple of Django instances within Ubuntu. To not have the same issues in the future, keep it written somewhere will help me and well maybe help others
Help others and they will help you — Adolf Hitler
First thing to know. There is always confussion when talking about Apache in CentOS vs Apache in Debian (Ubuntu inclusive). The main issue is the sites-enables, sites-available option in the Debian distributions.
I have nothing against the sites-way of handling VirtualHosts, but I am used to the CentOS configuration and to work all the time on the httpd.conf file instead on distributed ones. Because of that I decided to go for a single-file configuration.
In Ubuntu 14 you can do it on the /etc/apache2/apache2.conf (As long as I see it works as the httpd.conf of CentOS distributions).
Second thing: I decided to go for a mod_wsgi and not for mod_python, just because I read that this is the right thing to do.
Do the right thing — Every German
So, the main thing to have in mind with wsgi is that in your virtual host you have to specify where the wsgi file of your project is located.
WSGIScriptAlias / /path-to-your-wsgi-file/wsgi.py
Require all granted
And then you have to fill the wsgi.py file with the right configuration:
os.environ[“DJANGO_SETTINGS_MODULE”] = “yourproject.settings”
### IMPORTANT ###
# this two lines where trying to import handlers, that was giving a problem
# apache was reporting errors in the logs caused by it,
# the right configuration is the two lines under
# maybe it is caused because old configurations of wsgi
# i can’t remember what i read, but seems that is because of versions
# import django.core.handlers.wsgi #wrong line
# application = django.core.handlers.wsgi.WSGIHandler() #wrong line
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
As you can see I commented a lot on the last part of the script.
I really don’t remember how or where did I found it, but most of my problems when trying to run Django was caused because of those two last lines.
I believe I read somwhere that it is related with the wsgi version, and maybe I was copy/pasting from an old version.
Besides that, there is nothing else, just include several virtual host and don’t forget to include the wsgi file.
In this article is explained how to run Django using sites-enabled in Ubuntu. As I said, I am used to work everything in one file and therefore I prefered to use apache.conf for the virtualhost. Anyways, the configuration wsgi file I did was a copy from this one.
So you too have found the Django'y goodness that is Django. You spend all this time developing some great web service…www.nickpolet.com
Another amazing source that explain how to work with virtualenv:
Things to remember:
sudo service apache2 restart
that´s the way to restart apache in Ubuntu
Here is where the apache logs are stored