Bitnami Django Stack

    The Bitnami Django Stack greatly simplifies the development and deployment of Django applications. A Bitnami stack is a preconfigured environment that is available as native installers, virtual machines and cloud images.

    How do I download and install Django Stack?

    Cloud Server

    Bitnami cloud images extend stack appliances to run in a cloud computing environment. You can run Bitnami applications on a pay-as-you-go basis, programmatically starting and stopping them. Bitnami cloud images are currently available for Amazon EC2Microsoft AzureVMware vCloud AirGooogle Cloud Platform, and DigitalOcean, with support for additional cloud environments planned for the future.

    Virtual Machine/Native Installer

    You can download the Bitnami Django Stack for your platform at http://bitnami.com/stack/django. There are installers and virtual machines available for Windows, Mac OS X and Linux operating systems.

    The Bitnami Django Stack is distributed free of charge under the Apache 2.0 license.

    Which components are installed with Django Stack?

    The Bitnami Django Stack ships the components listed below. If you want to know which specific version of each component is bundled in the stack you are downloading, check the README.txt file on the download page or in the stack installation directory. You can also find more information about each component using the links below.

    Main components:

    Dependencies and additional components:

    • SQLite database
    • Imaging
    • easy_install
    • pip
    • OpenSSL library
    • CURL library

    What is the default installation directory?

    Cloud Server

    The default installation directory is /opt/bitnami.

    Virtual Machine

    The default installation directory is /opt/bitnami.

    Native Installer

    When using native installers, the default installation directory depends on the platform and can be changed during the installation:

    • Windows: C:\Bitnami\djangostack-VERSION (On previous versions, the default installation directory was C:\Program Files\BitNami Django Stack)
    • Mac OS X: /Applications/djangostack-VERSION
    • Linux: /home/user/djangostack-VERSION.

    How do I start and stop the servers?

    Each Django stack ships several servers that must be started before you will be able to work with them. By default, the MySQL or PostgreSQL database server and the Apache server are started after the installation.

    Cloud Images

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The script is located at /opt/bitnami/ctlscript.sh. Call it without any arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ sudo /opt/bitnami/ctlscript.sh restart mysql
    

    Virtual Machine

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The script is located at /opt/bitnami/ctlscript.sh. Call it without any arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ sudo /opt/bitnami/ctlscript.sh restart mysql
    

    Native Installer

    You can use either the graphical manager tool or the command-line tool to start and stop the servers.

    Graphical Tool

    Bitnami stacks include a graphical tool to manage the servers easily (native installers only). Using this tool, you can start, stop and restart the servers and check the log files.

    manager-servers.png

     

     

     

     

     

     

     

     

     

     

    On Windows:

    • Double-click the "manager-windows.exe" file in your installation directory.  
    • You can also start the Manager tool using the Start Menu path Start -> Program Files -> Bitnami Stack -> Manager.

    On Linux and Mac OS X:

    • Double-click the "manager-osx" or "manager-linux-*" tool in your installation directory. 
    Command-line Tool

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The control script is only available for Linux and Mac OS X native installers. The script is located in your installation directory and named ctlscript.sh. Call it without any arguments to restart all services.

    On Linux:
    If your installation directory is /home/USER/wordpress-4.0.1-0, call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /home/USER/wordpress-4.0.1-0
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /home/USER/wordpress-4.0.1-0
    $ ./ctlscript.sh restart mysql
    

    On Mac OS X:
    If your installation directory is /Applications/wordpress-4.0.1-0, call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /Applications/wordpress-4.0.1-0
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /Applications/wordpress-4.0.1-0
    $ ./ctlscript.sh restart mysql
    

    Tabs end

    How can I run a command in the Django Stack?

    Select your platform for instructions on how to run commands in your stack.

    Cloud Server

    Log in to the server console as the 'bitnami' user and run the command as usual. The required environment is automatically loaded for the ‘bitnami’ user.

    Virtual Machine

    Log in to the server console as the 'bitnami' user and run the command as usual. The required environment is automatically loaded for the ‘bitnami’ user.

    Native Installer

    All native installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system. To work correctly, certain environment variables need to be set before accessing different binaries in the stack.

    The Bitnami console is a script to load the stack environment. This console is useful to run any command included in the stack: python, pip, openssl, easy_install among others.

    On Linux:

    At the server console, enter the following commands:

    $ cd ~/djangostack-VERSION
    $ ./use_django
    

    On Windows:

    From the Start Menu, click the Start -> Bitnami Django Stack -> Use Django shortcut.

    On OS X:

    Open a Terminal and type the following commands:

    hostname:~ user$ cd /Applications/djangostack-VERSION
    hostname:~ user$ ./use_django
    

    How to start with the sample Django project?

    Once the installation or deployment finishes, you can access the welcome page from your browser.

    {{ wiki.template( "Template:SectionTab", {name: "Cloud Server}}

    Access the Bitnami Django Stack via your browser at http://[server-IP-address]/.

    Access the sample project via your browser athttp://[server-IP-address]/Project.

    The Django project files are located at /opt/bitnami/apps/django/django_projects.

    Virtual Machine

    Access the Bitnami Django Stack via your browser at http://[server-IP-address]/.

    Access the sample project via your browser athttp://[server-IP-address]/Project.

    The Django project files are located at /opt/bitnami/apps/django/django_projects.

    Native Installer

    Access the Bitnami Django Stack via your browser at http://localhost (Windows) or http://localhost:8080 (Mac OS X and Linux).

    Access the sample project via your browser at http://localhost/Project (Windows) or http://localhost:8080/Project (Mac OS X and Linux).

    The Django project files are located at installdir/apps/django/django_projects.

    Tabs end

    Here is an example of what you will see:

    django-demo.png

    How to create a new Django project?

    Cloud Images

    The projects folder is located at /opt/bitnami/apps/django/django_projects.

    Follow the steps below:

    1. Change to your projects folder and run the following command to create a new project. Replace the PROJECT placeholder with the name of your project.   

    $ sudo django-admin.py startproject PROJECT
    

    2. If you wish to create a new application inside the project, execute the following commands as well. Replace the APP placeholder with the name of your application.

    $ cd PROJECT
    $ sudo python manage.py startapp APP
    

    You can check your Django version at any time by executing the following command:

    python -c "import django; print(django.get_version())"
    

    For getting started with Django, check the official Django documentation for the version that you are using.

    Virtual Machine

    The projects folder is located at /opt/bitnami/apps/django/django_projects.

    Follow the steps below:

    1. Change to your projects folder and run the following command to create a new project. Replace the PROJECT placeholder with the name of your project.   

    $ sudo django-admin.py startproject PROJECT
    

    2. If you wish to create a new application inside the project, execute the following commands as well. Replace the APP placeholder with the name of your application.

    $ cd PROJECT
    $ sudo python manage.py startapp APP
    

    You can check your Django version at any time by executing the following command:

    python -c "import django; print(django.get_version())"
    

    For getting started with Django, check the official Django documentation for the version that you are using.

    Native Installer

    The location of the Django projects folder depends on the platform, as shown below:

    On Linux:

    The projects folder is located at installdir/apps/django/django_projects.

    On Windows:

    • For 2000, XP and 2003 Server, the projects folder is located at C:\Documents and Settings\USER\Bitnami DjangoStack Projects.
    • For Vista, 7 and 2008 Server, the projects folder is located at C:\Users\USER\Bitnami DjangoStack Projects.

    On Mac OS X:

    The projects folder is located at /Applications/djangostack-VERSION/apps/django/django_projects.

    To start a project with Django, follow these steps:

    1. Start the Bitnami Console, by running the command below using the console.

    $ cd ~/djangostack-VERSION
    $ ./use_django
    

    2. Change to your projects folder and run the following command to create a new project. Replace the PROJECT placeholder with the name of your project.                             

    $ django-admin.py startproject PROJECT 

    3. If you wish to create a new application inside the project, execute the following commands as well. Replace the APP placeholder with the name of your application.  

    $ cd PROJECT 
    $ python manage.py startapp APP
    

    You can check your Django version at any time by executing the following command:

    python -c "import django; print(django.get_version())"
    

    For getting started with Django, check the official Django documentation for the version that you are using.

    How to start a Django project?

    Follow the steps below to develop and deploy your Django project.

    Development

    Cloud Images

    For development, use the standalone server in Django by executing the following command inside your project folder:

    $ python manage.py runserver IP:PORT
    

    IP and PORT are optional parameters. 127.0.0.1:8000 will be used by default if you don't specify any of them. If you plan to remotely access the server, you should use the IP address 0.0.0.0, or the actual server IP address.

    IMPORTANT: Remember to open the port used by the Django server in the server firewall. Refer to your cloud platform's page in this wiki for more information.

    Virtual Machine

    For development, use the standalone server in Django by executing the following command inside your project folder:

    $ python manage.py runserver IP:PORT
    

    IP and PORT are optional parameters. 127.0.0.1:8000 will be used by default if you don't specify any of them. If you plan to remotely access the server, you should use the IP address 0.0.0.0, or the actual server IP address.

    IMPORTANT: Remember to open the port used by the Django server in the server firewall. Refer to these instructions for more information.

    Native Installer

    For development, use the standalone server in Django by executing the following command inside your project folder:

    $ python manage.py runserver IP:PORT
    

    IP and PORT are optional parameters. 127.0.0.1:8000 will be used by default if you don't specify any of them. If you plan to remotely access the server, you should use the IP address 0.0.0.0, or the server's network IP address.

    IMPORTANT: Remember to open the port used by the Django server in the server firewall. Refer to these instructions for more information.

    Tabs end

    Production deployment

    For a production environment, we recomend configuring Apache with the mod_wsgi module before starting to serve your application. On Bitnami Cloud Images and Virtual Appliances, mod_wsgi is already installed and activated by default.

    Cloud Images

    1. First, modify the WSGI application script file at /opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/wsgi.py. Remember to replace PROJECT with the actual path and name to your Django project.

    Although the exact content may be different depending on your Django version, ensure that the content is similar to the code below and that you add your project to the path with sys.path.append.

    import os
    import sys
    sys.path.append('/opt/bitnami/apps/django/django_projects/PROJECT')
    os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/PROJECT/egg_cache")
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT.settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
     
    2. Create a conf/ folder in the  /opt/bitnami/apps/django/django_projects/PROJECT/ directory. 
    $ sudo mkdir /opt/bitnami/apps/django/django_projects/PROJECT/conf
    

    3. Create the following files:

    $ sudo touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf
    $ sudo touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf
    
     
    4. On Linux, you can run the application with mod_wsgi in daemon mode. Add the following code in /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf:
    <IfDefine !IS_DJANGOSTACK_LOADED>
      Define IS_DJANGOSTACK_LOADED
      WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
    </IfDefine>
    
    WSGIScriptAlias /PROJECT '/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/wsgi.py'
    <Directory "/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/">
        WSGIProcessGroup wsgi-djangostack
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
            Require all granted
        </IfVersion>
    </Directory>
    

    5. In the /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf file, add this code:

    Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf"
    

    6. Add the line below to the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

    Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf"
    

    7. Restart the Apache server.

    $ sudo /opt/bitnami/ctlscript.sh restart apache
    

    You should now be able to browse to your project at http://[server-IP-address]/PROJECT.

    Virtual Machine

    1. First, modify the WSGI application script file at /opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/wsgi.py. Remember to replace PROJECT with the actual path and name to your Django project.

    Although the exact content may be different depending on your Django version, ensure that the content is similar to the code below and that you add your project to the path with sys.path.append.

    import os
    import sys
    sys.path.append('/opt/bitnami/apps/django/django_projects/PROJECT')
    os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/PROJECT/egg_cache")
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT.settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
     
    2. Create a conf/ folder in the  /opt/bitnami/apps/django/django_projects/PROJECT/ directory. 
    $ sudo mkdir /opt/bitnami/apps/django/django_projects/PROJECT/conf
    

    3. Create the following files:

    $ sudo touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf
    $ sudo touch /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf
    
     
    4. On Linux, you can run the application with mod_wsgi in daemon mode. Add the following code in /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf:
    <IfDefine !IS_DJANGOSTACK_LOADED>
      Define IS_DJANGOSTACK_LOADED
      WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
    </IfDefine>
    
    WSGIScriptAlias /PROJECT '/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/wsgi.py'
    <Directory "/opt/bitnami/apps/django/django_projects/PROJECT/PROJECT/">
        WSGIProcessGroup wsgi-djangostack
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
            Require all granted
        </IfVersion>
    </Directory>
    

    5. In the /opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf file, add this code:

    Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-app.conf"
    

    6. Add the line below to the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

    Include "/opt/bitnami/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf"
    

    7. Restart the Apache server.

    $ sudo /opt/bitnami/ctlscript.sh restart apache
    

    You should now be able to browse to your project at http://[server-IP-address]/PROJECT.

    Native Installer

    1. First, modify the WSGI application script file at installdir/apps/django/django_projects/PROJECT/PROJECT/wsgi.py. Remember to replace PROJECT with the actual path and name to your Django project.

    Although the exact content may be different depending on your Django version, ensure that the content is similar to the code below and that you add your project to the path with sys.path.append.

    import os
    import sys
    sys.path.append('installdir/apps/django/django_projects/PROJECT')
    os.environ.setdefault("PYTHON_EGG_CACHE", "installdir/apps/django/django_projects/PROJECT/egg_cache")
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT.settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
     
    2. Create a conf/ folder in the installdir/apps/django/django_projects/PROJECT/ directory. 
    $ mkdir installdir/apps/django/django_projects/PROJECT/conf
    

    3. Create the following files:

    touch installdir/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf
    touch installdir/apps/django/django_projects/PROJECT/conf/httpd-app.conf
    
     
    4. On Linux and Mac OS X, you can run the application with mod_wsgi in daemon mode. Add the following code in installdir/apps/django/django_projects/PROJECT/conf/httpd-app.conf:
    <IfDefine !IS_DJANGOSTACK_LOADED>
      Define IS_DJANGOSTACK_LOADED
      WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
    </IfDefine>
    
    WSGIScriptAlias /PROJECT 'installdir/apps/django/django_projects/PROJECT/PROJECT/wsgi.py'
    <Directory "installdir/apps/django/django_projects/PROJECT/PROJECT/">
        WSGIProcessGroup wsgi-djangostack
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
            Require all granted
        </IfVersion>
    </Directory>
    
     
    On Windows, the daemon mode for mod_wsgi is not support and the configuration will be slightly different:
    WSGIScriptAlias /PROJECT 'installdir/apps/django/django_projects/PROJECT/PROJECT/wsgi.py'
    <Directory "installdir/apps/django/django_projects/PROJECT/PROJECT/">
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
            Require all granted
        </IfVersion>
    </Directory>
    

    5. In the installdir/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf file, add this code:

    Include "installdir/apps/django/django_projects/PROJECT/conf/httpd-app.conf"
    

    6. Add the line below to the installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

    Include "installdir/apps/django/django_projects/PROJECT/conf/httpd-prefix.conf"
    

    7. Restart the Apache server.

    $ installdir/ctlscript.sh restart apache
    

    You should now be able to browse to your project at http://[server-IP-address]/PROJECT (Windows) or http://[server-IP-address]/PROJECT (Linux and Mac OS X).

    Tabs end

    If you wish to configure a database for your project, configure the settings.py file with the following settings. The examples below show how to configure the database connection with a database called "djangostack". Remember to replace /opt/bitnami with the actual path to your stack installation directory for native installers.

    For MySQL:

     DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'djangostack',
            'HOST': '/opt/bitnami/mysql/tmp/mysql.sock',                                                 
            'PORT': '3306',
            'USER': 'USERNAME',
            'PASSWORD': 'PASSWORD'
        }
    }
    

    For PostgreSQL:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'djangostack',
            'HOST': '/opt/bitnami/postgresql',
            'PORT': '5432',
            'USER': 'USERNAME',
            'PASSWORD': 'PASSWORD'
        }
    }
    
    NOTE: The database connection in the above configuration file is configured to use a socket. If you are using the Bitnami Django Stack on Windows, you should instead replace the HOST parameter with 'HOST': '127.0.0.1'.

    For SQLite:

     DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': '/opt/bitnami/apps/django/django_projects/Project/Project/Project.db',
        }
    }
     

    How to configure GeoDjango with PostGIS?

    This guide assumes that you are working with Django 1.5+ which already supports PostGIS 2.0+: GeoDjango with PostGIS quick start guide

    Tag page (Edit tags)
    • No tags
    Page statistics
    123792 view(s), 22 edit(s) and 9222 character(s)

    Comments

    You must login to post a comment.