Bitnami Django Stack

    Bitnami Django Stack greatly simplify 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?

    django.png

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

    Currently there are available different versions of Django stack, depending on the Django version.

    Bitnami Django Stack can also be deployed as virtual machines. If you are using the virtual machine, please see our Virtual Appliances documentation for instructions on logging into the machine.

    The Stacks can be also deployed as AMIs in the Amazon cloud, Azure or Google Compute Engine. Please take a look at our Amazon Cloud Images quick guide to see how to connect to the instance from your machine, our Azure Launchpad or our Google Launchpad

    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 in 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?

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

    win_platform.png On Windows: C:\Bitnami\djangostack-VERSION (On previous versions, the default installation directory was C:\Program Files\BitNami Django Stack)

    mac_platform.png On OS X: /Applications/djangostack-VERSION

    linux_platform.png On Linux: /home/user/djangostack-VERSION

    If you are using a virtual machine or a Cloud Images, the default installation directory is "/opt/bitnami".

    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, MySQL or PostgreSQL database and Apache servers are started after the installation.

    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. Refer to the section for your platform to learn more.

    Cloud Server

    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

    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

    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?

    All of the 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 when you want to invoke commands to access different binaries. Note that in virtual machines or Cloud Images, the environment is already loaded for the "bitnami" user automatically and the below is not necessary.

    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.

    linux_platform.png On Linux:

    $ cd ~/djangostack-version
    $ ./use_django
    
    

    win_platform.png On Windows:

    There is a shortcut in Start -> Bitnami Ruby Stack ->"Use Django"

    mac_platform.png On OS X:

    Open a Terminal and type the following:

    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. If you have installed the stack on a local machine as a regular user, you can access it at http://localhost on Windows or http://localhost:8080 on OS X and Linux. If not, you can specify the IP address of the server where you installed the Stack.

    You can access to the demo Project at "http://localhost/Project" on Windows or "http://localhost:8080/Project" on OS X or Linux. This sample project is running with "mod_wsgi"

    django-demo.png

     

    The Django project files are in the following location:

    "your_installdir/apps/django/django_projects"

    How to create a new Django project?

    To start a project with Django, it is necessary to start the Bitnami Console. If you are using a Virtual Appliance or Cloud Image, you can run the commands below directly.

    You can find the projects folder located at:

    linux_platform.png On Linux:

    installdir/apps/django/django_projects
    

    win_platform.png On Windows:

    For 2000, XP and 2003 Server:

    C:\Documents and Settings\user\Bitnami DjangoStack Projects
    

    For Vista, 7 and 2008 Server:

    C:\Users\user\Bitnami DjangoStack Projects
    

    mac_platform.png On OS X:

    /Applications/djangostack-version/apps/django/django_projects
    

    From a console go to your projects folder and run the following command to create a new project:                             

    django-admin.py startproject my_new_project
    

    If you wish to create a new applicaction inside the created project execute the following commands as well:

    cd my_new_project
    python manage.py startapp my_new_app
    

     

    You can check your Django version 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?

    Before start to follow the steps, keep in mind that installdir is the installation directory that you configured during the installation process. If you are using a Virtual Appliance, a Cloud Image or Bitnami Cloud Hosting, the installation directory is: /opt/bitnami.

    For development tasks you can use the standalone server in Django 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.

    Note that 127.0.0.1 is only accessible from the local machine. If you are remotely accessing the server you should use the ip 0.0.0.0 (or the server IP). Also make sure that the port is open in your firewall rules, for Bitnami Cloud hosting servers check how to access your machine documentation.

     

    For a production environment we recomend to configure Apache with mod_wsgi module before start serving your application. If you are using Bitnami Stacks and Virtual Appliances for Django, mod_wsgi is already installed and activated by default. 

    Django application configuration

    First, modify the WSGI application script file named 'wsgi.py' in the 'installdir/apps/django/django_projects/my_new_project/my_new_project' folder.

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

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

    Then, create these two files:

    touch installdir/apps/django/django_projects/my_new_project/conf/httpd-prefix.conf
    touch installdir/apps/django/django_projects/my_new_project/conf/httpd-app.conf
    
     
    On Unix you can run your application with mod_wsgi in daemon mode. Add the following code in httpd-app.conf :
    <IfDefine !IS_DJANGOSTACK_LOADED>
      Define IS_DJANGOSTACK_LOADED
      WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
    </IfDefine>
    
    WSGIScriptAlias /my_new_project 'installdir/apps/django/django_projects/my_new_project/my_new_project/wsgi.py'
    <Directory "installdir/apps/django/django_projects/my_new_project/my_new_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 /my_new_project 'installdir/apps/django/django_projects/my_new_project/my_new_project/wsgi.py'
    <Directory "installdir/apps/django/django_projects/my_new_project/my_new_project/">
        WSGIApplicationGroup %{GLOBAL}
        <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
            Require all granted
        </IfVersion>
    </Directory>
    
     

    In 'installdir/apps/django/django_projects/my_new_project/conf/httpd-prefix.conf' add this code:

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

    Finally, add the line below in 'installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf':

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

    Then restart the Apache server and visit your project at http://localhost:8080/my_new_project

    Database configuration

    If you want to configure a database for your project, you can configure the "settings.py" file with the following settings. The examples below show how to configure the database connection with a database called "djangostack":

    • MySQL
     DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'djangostack',
            'HOST': '/opt/bitnami/mysql/tmp/mysql.sock',                                                 
            'PORT': '3306',
            'USER': 'your_user',
            'PASSWORD': 'your_password'
        }
    }
    
    • PostgreSQL
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'djangostack',
            'HOST': '/opt/bitnami/postgresql',
            'PORT': '5432',
            'USER': 'your_user',
            'PASSWORD': 'your_password'
        }
    }
    • SQLite
     DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': '/opt/bitnami/apps/django/django_projects/Project/Project/Project.db',
        }
    }
     

    The database connection is configured to use a socket. If you are using DjangoStack on Windows, you should use 'HOST': '127.0.0.1' .

    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
    122853 view(s), 16 edit(s) and 7897 character(s)

    Comments

    You must login to post a comment.