5. Installing Nitrate with Apache (virtualenv) and MySQL


The steps in this section have been initially written with Red Hat Enterprise Linux 7 in mind. The steps should apply to other Linux distributions as well but file locations may vary!

5.1. Install Apache and prepare a local Nitrate directory

First install Apache and mod_wsgi if not present:

# yum install httpd mod_wsgi
# systemctl enable httpd
# systemctl start httpd

Next create a directory that will host your Nitrate instance:

# mkdir /var/www/html/mynitrate

5.2. Prepare virtualenv

You will install Nitrate inside a virtual environment to avoid conflicts with system Python libraries and allow for easier upgrade of dependencies:

# cd /var/www/html/mynitrate
# yum install python-virtualenv
# virtualenv venv
# ./venv/bin/activate

5.3. Install Nitrate from source code

First install RPM packages which are needed to compile some of the Python dependencies. See Setting up a development environment on Fedora for more information. Then:

(venv)# cd /home/<username>/
(venv)# git clone https://github.com/Nitrate/Nitrate.git
(venv)# cd ./Nitrate/
(venv)# git checkout --track [a proper tag or branch]
(venv)# pip install -r ./requirements/base.txt
(venv)# python setup.py install


Nitrate source code has been cloned into your home directory but has been installed into the virtual environment for Apache!

5.4. Initialize database

Database is required by Nitrate. Django ORM supports many database backends, but for the moment we recommend you to use MySQL because some parts of Nitrate do not use the ORM layer but instead hand-crafted SQL queries! Create database and user for Nitrate in MySQL:

mysql> create database nitrate;
mysql> GRANT all privileges on nitrate.* to nitrate@'%' identified by 'password';

5.5. Configure Nitrate

Create the following files.

/var/www/html/mynitrate/__init__.py - empty


from tcms.settings.product import *

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'top-secret'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

# Database settings
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'nitrate',
        'HOST': '',
        'USER': 'nitrate',
        'PASSWORD': 'password',
# Nitrate defines a 'slave_1' connection
DATABASES['slave_1'] = DATABASES['default']

STATIC_ROOT = '/var/www/html/mynitrate/static'


import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Create tables, create super user and collect static files:

(venv)# cd /var/www/html/mynitrate
(venv)# django-admin.py migrate --settings=settings
(venv)# django-admin.py createsuperuser --settings=settings
(venv)# django-admin.py collectstatic --settings=settings

Verify that your configuration works by:

(venv)# django-admin.py runserver --settings=settings


For more information about Nitrate configuration see Nitrate configuration settings!

5.6. Create upload directory

Create upload directory and change owner & group to apache:

# mkdir -p /var/nitrate/uploads
# chown apache:apache /var/nitrate/uploads

5.7. Configure Apache and mod_wsgi


WSGIDaemonProcess nitrateapp python-path=/var/www/html/mynitrate:/var/www/html/mynitrate/venv/lib/python2.7/site-packages
WSGIProcessGroup nitrateapp
WSGIScriptAlias / /var/www/html/mynitrate/wsgi.py

Alias /static/ /var/www/html/mynitrate/static/

<Location "/static/">
    Options -Indexes

Then restart Apache:

# systemctl restart httpd

In case of problem, refer to log file:


For access info, refer to:


Apache and mod_wsgi can be configured in many ways. Another example of Apache configuration for Nitrate is shown below. You will very likely have to adjust it based on your particular environment.

# Deployment using mod_wsgi
# Useful documentation:
# https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/

# Force the use of ssl:
#<IfModule mod_rewrite.c>
#    RewriteEngine on
#    RewriteCond %{HTTPS} off
#    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

# Make sure static files collected to this dir
# Ref https://docs.djangoproject.com/en/1.5/ref/contrib/staticfiles/#django-admin-collectstatic
Alias /static /usr/share/nitrate/static

# Limit threads forked:
# prefork MPM 
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 256
MaxRequestsPerChild 0

# Configurations for mod_wsgi
WSGIScriptAlias / /usr/lib/python2.6/site-packages/tcms/wsgi.py
WSGIPythonPath /usr/lib/python2.6/site-packages
WSGIPassAuthorization On

<Location "/">
    # ====================
    # Handler for mod_wsgi
    # ====================
    SetHandler wsgi-script

    Options All
    AllowOverride All
    Require all granted
    LimitRequestBody 10485760
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/x-javascript text/css

    ErrorDocument 401 "Your request is unauthorization."

<Location "/static">
    SetHandler None

    # Disable auth on the static content, so that we're aren't forced to
    # use Kerberos.  Doing so would remove "Expires" headers from the static
    # content, which would lead to poor page-load times.
    AuthType none
    Satisfy Any
    Allow from All

    # Many file types are likely to benefit from compression
    # Enable gzip compression on them:
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/x-javascript text/css

    # Set far-future Expires headers on static content
    # (trac 184):
    ExpiresActive On
    ExpiresDefault "access plus 10 years"