Deploying Django + Apache on Ubuntu
I have looked through many links on this topic about deploying Django and Apache on an Ubuntu server. Finally, I found this link Installing Django Deployement on an Ubuntu 12.04 server which took me beyond any other tutorial. So now I'm at this location - I've installed all software and dependencies, enabled mod_WSGI, installed the Python and Django environment, started a new project, etc. I called my domain dynamics "dynamics". So my
file in the folder
now looks like this:
*:80> ServerAdmin root@dynamics ServerName dynamics Alias /site_media/ /srv/my_project/app/webapp/site_media/ Alias /static/ /srv/my_project/venv/lib/python2.7/site-packages/django/contrib/admin /static/ Alias /robots.txt /srv/my_project/app/webapp/site_media/robots.txt Alias /favicon.ico /srv/my_project/app/webapp/site_media/favicon.ico CustomLog "|/usr/sbin/rotatelogs /srv/my_project/logs/access.log.%Y%m%d-%H%M%S 5M" combined ErrorLog "|/usr/sbin/rotatelogs /srv/my_project/logs/error.log.%Y%m%d-%H%M%S 5M" LogLevel warn WSGIDaemonProcess dynamics user=itsme group=itsme processes=1 threads=15 maximum- requests=10000 python-path=/srv/my_project/venv/lib/python2.7/site-packages python- eggs=/srv/my_project/run/eggs WSGIProcessGroup dynamics WSGIScriptAlias / /srv/my_project/app/conf/apache/django.wsgi /srv/my_project/app/webapp/site_media> Order deny,allow Allow from all Options -Indexes FollowSymLinks </Directory> /srv/my_project/app/conf/apache> Order deny,allow Allow from all </Directory> </VirtualHost>
But, when I start apache and navigate to
, I see an error
, if I try to navigate to instead
, I am redirected to google search page. I think I need to do some additional configurations, but I don't know which ones. I probably need to point ServerRoot in
(but again with all these django folders I don't know where I should point exactly).
EDIT Now it's even worse. I tried reinstalling apache, but when I go to localhost the browser wants to load a page like a file. So what I did step by step:
1. sudo apt-get remove apache2 # remove to install from scratch 2. sudo apt-get update 3. sudo apt-get install apache2 4. sudo a2dissite default # disable the default site 5. create dynamics file in /etc/apache2/sites-available 6. dynamics file contains these lines: <VirtualHost *:80> ServerAdmin root@dynamics ServerName dynamics DocumentRoot /home/username/Sites/dynamics <Directory /home/username/Sites/dynamics/> Options Indexes FollowSymLinks MultiViews AllowOverride Node Order allow,deny allow from all </Directory> </VirtualHost> 7. /etc/apache2/apache2.conf contains `ServerName dynamics`.
If I also point SeverRoot to
, I get hundreds of errors when I restart apache, so I won't point it. Problems:
1. If I go to `http://dynamics`, I'm redirected to google search page 2. If I go to localhost, the browser wants to load a page like a file
So after reinstalling I am even one step back. I can't even create a virtual host. During this process, I ran into one - if you do
sudo apt-get remove
sudo apt-get purge
despite what they say, I can still see the non-traditional apache files - just like I did before uninstalling. So, I have one more question:
1. How to uninstall completely apache. All guides and tips that I followed left apache config files just as they were.
Well, I re-installed apache from the start, added a virtual host
(firstly, without any link from django), then I followed Daniel Roseman's advice - tweaked the file a bit
. And no, at least this part works. I can add the index.html file to the speakers folder and if I go to
I see this page. BUT, all my attempts to create a django project and run it at the same url
have failed. Every time I get this error, "Not Found". Tons of guides, hundreds of blogs, and oceans of tutorials seem completely useless to make (I think) the easiest task possible - just run a django project on Apache.
I ran bounty question . Now I just want to formalize everything in advance. Question: How do I deploy Django and Apache on Ubuntu ? Requirements:
Strongly required: 1. Ubuntu 12.04 2. Python 3.3.4 3. Apache 2.2.22 4. mod_wsgi
Not so much: 5. If someone does a test test, it will be cool. So my ultimate goal is to create a tiny web project where I could use
to call subroutines
. If this connection can be made in this environment, I will be completely above the moon. And let's say I want to have a specific virtual host called
. So, I want to store all project files in this / home / victor / dynamic / directory. I want step by step instructions, not just scraps of tips. And I hope this tutorial, if someone succeeds in doing it, will be incredibly popular with django newbeis like me.
source to share
You need to run
sudo a2ensite dynamics
to enable conf dynamic (or you can manually bind it to sites) and then restart Apache with
sudo /etc/init.d/apache2 restart
Edit . It looks like another problem is when you are trying to bind your virtual host to a domain name that does not exist and is not associated with your machine, i.e.
... If you want to access it this way, you need to edit yours
to point that name to your localhost: add this line to this file:
Don't forget that this is just a hack for your car. For a real deployment, you will need a correct domain name that is resolved via DNS.
source to share