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?
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
- Use virtualenv. Take a look at mod_wsgi and virtualenv configuration
- Install Django your django version (using python setup.py install)
- Install your python libs
- Develop your project
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
- [Django]-Generating a date relative to another date in Django template
- [Django]-Force re-collectstatic with django static?
- [Django]-Django objects change model field
- [Django]-Import parent module from submodule
- [Django]-Distinct values with Q objects
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.
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.
- [Django]-Django – queryset with extra method returns empty, count() says otherwise
- [Django]-Django URLResolver error
- [Django]-How to implement Angular with Django
- [Django]-Django templates: accessing the previous and the following element of the list
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.
- [Django]-How to filter model with a list containing the field and the value?
- [Django]-Using reverse relationships with django-rest-framework's serializer
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.
- [Django]-Django log errors and traceback in file in production environment
- [Django]-Feature differentiation: Rails / Django
- [Django]-Django Rest Framework: XMLHttpRequest cannot load http://127.0.0.1:8000/xyz/api/abc
- [Django]-Add django class based view to admin site
- [Django]-Single django app to use multiple sqlite3 files for database
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')
- [Django]-Twilio – generate 6 digit random numbers
- [Django]-Local Django website won't load in browser
- [Django]-Django application deployed at suburl, redirect to home page after login
- [Django]-Translate xml string to Python list
- [Django]-Django – TinyMCE – admin – How to change editor size?