Android,iOS,Gadgets,Reviews Everything About Technology

Installing Django 1.6 + Apache 2 + mod_wsgi on Ubuntu

174

After long, long months of working out your project miracle, you decided that it’s time to show it to the world. In anticipation of the large attendance and popularity of your service, you tried to configure the project on the battle server, but you did not succeed.

You reread a bunch of manuals, tried everything in the world, but never got a working application. If you are in such a difficult situation, this article will tell you how to install and configure Django 1.6 with the Apache 2 web server and the Ubuntu operating system.

Software Installation

- Advertisement -

In this article, as a product server, we will use Ubuntu 12. If you do not have a server, create it (for example in DigitalOcean), then log in to the server by ssh and execute the commands (if you already have a server with configured applications, then skip this step):

~~~ {.sh} sudo apt-get update sudo apt-get upgrade


After the system update, install python and package manager ** pip **, we will use the version of python 2.7 (in Ubuntu 12 it is installed by default):
~~~{.sh}
sudo apt-get install python-pip python-dev build-essential 
sudo pip install --upgrade pip

Now install the Apache 2 web server and mod_wsgi and git :

~~~ {.sh} sudo apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert git-core sudo apt-get install libapache2-mod-wsgi


And now go to the directory `/ var / www` and persuade your project from the git repository (or load it in another way convenient for you).
~~~{.sh}
cd /var/www
git clone https://github.com/exampe/example_com.git

After you execute these commands, a directory will be created /var/www/example_com, this will be the root directory of your project. Now you need to configure the Apache virtual host.

~~~ {.sh} sudo nano /etc/apache2/sites-available/example.com


And add the following code:
~~~{.apache}
<VirtualHost *:80>
    ServerName example.com

    WSGIDaemonProcess example_com processes=2 threads=15 display-name=%{GROUP} python-path=/var/www/example_com
    WSGIProcessGroup example_com

    WSGIScriptAlias / /var/www/example_com/example_com/wsgi.py

    <Directory /var/www/example_com/example_com>
        Order allow,deny
        allow from all
    </Directory>

    LogLevel warn

    Alias /static/ /var/www/example_com/static/
    <Directory /var/www/example_com/>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Install the libraries necessary for your project. Then, enable the virtual host and restart the web server:

~~~ {.sh} pip install django


pip install ... and other libraries that are used in your application
~~~{.sh}
sudo a2ensite example.com
sudo service apache2 restart

A few more settings

I think that your application will send e-mail, for example when registering users, and for this you need to install sendmail, it’s easy:

~~~ {.sh} sudo apt-get install sendmail


The settings in your application (example_com.settings.py) to send mail should be:
~~~{.python}
DEFAULT_FROM_EMAIL = 'noreply@example.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_USE_TLS = True

That’s about all that’s needed, for the basic configuration of the django project on the battle server.

Comments