[Django]-How can Django projects be deployed with minimal installation work?

3đź‘Ť

âś…

Can the deployment process of django project be made easier?

No. You can script some of this, if you want. However, you’re never going to install MySQL, MySQLPuthon, mod_wsgi (or mod_python), or Django again.

You will, however, tweak your application all the time.

Am I doing too much?

No. Python (and Django) are not part of Apache. PHP is embedded in Apache. PHP is exactly like mod_python (or mod_wsgi). Just one piece of the pie. (Apparently, some hosts handle the PHP installation for you, but don’t handle the mod_wsgi or mod_python installation.)

Can some of the steps be omitted?

No. However, you only do it once.

What is the best way to deploy django site on a shared server?

You’re doing it correctly.

When I deployed another site with php (using CodeIgniter) I had to do nothing

Certainly an unfair comparison. Apparently, they already installed PHP and the database for you. Nice of them.

Also, PHP is not Python. PHP is a plug-in to Apache. Python is “just” a programming language, that requires a separate plug-in to Apache (i.e., mod_python or mod_wsgi).

See How nicely does Python 'flow' with HTML as compared to PHP?

👤S.Lott

4đź‘Ť

To enable easy Django deployement I would to the following:

Fisrt-time server configuration

  • Install mod_wsgi which allow you to run in embedded mode OR in daemon mode.
  • Install python and virtualenv

In your development environment

Every time you want to deploy

  • Copy your virtual environment to the production server
  • Just add an Include directive in your httpd.conf file (or use .htaccess) to your project’s apache configuration. As stated in mod_wsgi integration with django documentation, one example of how Apache included file could be configured would be:

Alias /media/ /usr/local/django/mysite/media/

<Directory /usr/local/django/mysite/media>
  Order deny,allow
  Allow from all
</Directory>

WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi

<Directory /usr/local/django/mysite/apache>
  Order deny,allow
  Allow from all
</Directory>

Automating deployement

  • I would consider using Fabric to automate deployement

2đź‘Ť

Django hosting support is not as widespread as for PHP, but there are some good options. I can recommend WebFaction – they provide an easy-to-use control panel which offers various combinations of Django versions, Python versions, mod_python, mod_wsgi, MySQL, PostgreSQL etc. They’re cost-effective, too. If you use their setup, you get SSH access but just about all of the setting up can be done via their control panel, apart from the actual uploading of your project folder.

Disclaimer: apart from being a happy customer I have no other connection with them.

👤Vinay Sajip

1đź‘Ť

You didn’t have to do anything when deploying a PHP site because your hosting provider had already installed it. Web hosts which support Django typically install and configure it for you.

👤John Millikin

1đź‘Ť

You just install this already made solution if your allowed to run an image on a virtual machine. I can imagine installations will be done this way in future as complicated security configuration can be done automatically.

👤David Raznick

0đź‘Ť

Most shared hosting sites run the LAMP (Linux, Apache, MySQL, PHP) stack so deployment is just a matter of copying some files over. If you were using one of the PHP frameworks like CakePHP or something the service hasn’t installed (like an imaging library) you’d be going through extra deployment steps as well.

With Django (or Rails, or any other complex framework) you have to set up the stack yourself that one time, then you’re good to go.

However, you’ll also want to think about post-deployment updating. If it’s something you’re going to do often you may also want to look into Fabric or Capistrano to help automate that.

P.S. I’ll second that WebFaction recommendation. It’s as close to one-button installation as I’ve seen. Pretty happy customer although I mostly use them for test-sites and prototyping.

👤Ramin

0đź‘Ť

You can use Python virtualenv and pip (see also “Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip“). I developed my Django project in the virtual environment. I copy the virtual environment file to the production machine when I deploy my application. I use mod_wsgi. You must write that in the mod_wsig file:

import site  
site.addsitedir('C:\PythonVirtualEnv\IntegralEnv\Lib\site-packages') 
👤Maplye

Leave a comment