Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run multiple django project in different virtualenv on apache

I want to run two different django_projects each in different virtualenv. This is the code :

ServerName ubuntu_server_apache

<VirtualHost *:80>

ServerName dev.hexxie.com

ErrorLog "/home/ashish/deployments/mysite_dev/conf/mysite_dev_error.log"

WSGIScriptAlias / /home/ashish/deployments/mysite_dev/mysite/mysite/wsgi.py

Alias /static /home/ashish/deployments/mysite_dev/static_root
<Directory /home/ashish/deployments/mysite_dev/static_root>
Require all granted
</Directory>

Alias /media /home/ashish/deployments/mysite_prod/data/media
<Directory /home/ashish/deployments/mysite_prod/data/media>
Require all granted
</Directory>

<Directory /home/ashish/deployments/mysite_dev/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

</VirtualHost>
WSGIPythonPath /home/ashish/deployments/mysite_dev/mysite:/home/ashish/.virtualenvs/mysite_dev/lib/python2.7/site-packages



<VirtualHost *:80>

ServerName hexxie.com
ServerAlias *.hexxie.com

ErrorLog "/home/ashish/deployments/mysite_prod/conf/mysite_error.log"

WSGIScriptAlias / /home/ashish/deployments/mysite_prod/mysite/mysite/wsgi.py

Alias /static /home/ashish/deployments/mysite_prod/static_root
<Directory /home/ashish/deployments/mysite_prod/static_root>
Require all granted
</Directory>

Alias /media /home/ashish/deployments/mysite_prod/data/media
<Directory /home/ashish/deployments/mysite_prod/data/media>
Require all granted
</Directory>

<Directory /home/ashish/deployments/mysite_prod/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

</VirtualHost>
WSGIPythonPath /home/ashish/deployments/mysite_prod/mysite:/home/ashish/.virtualenvs/mysite_prod/lib/python2.7/site-packages

But I am getting internal server error using this apache conf. I feel that this is due to WSGIPythonPath used twice in conf. WSGIPythonPath can't be included inside virtualhost. So how to run two diff django project each on diff virtualenv on apache ?

like image 398
Ashish Gupta Avatar asked Jun 01 '15 22:06

Ashish Gupta


People also ask

How do I make two Django projects share the same database?

You just need to declare in your model in class meta the attribute db_table with a name diferent the name of app + model (Which are automatically generated by Django) the twice projects need the same models. before the run makemigrations and migrate.

Does Django run on Apache?

Django will work with any version of Apache which supports mod_wsgi. The official mod_wsgi documentation is your source for all the details about how to use mod_wsgi. You'll probably want to start with the installation and configuration documentation.


1 Answers

For a start, use a daemon process group so each runs in a separate process and then use the python-home option on the respective WSGIDaemonProcess group directives. See:

  • http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
  • http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html
like image 65
Graham Dumpleton Avatar answered Oct 12 '22 08:10

Graham Dumpleton