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!

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

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

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
(venv)# cd ./Nitrate/
(venv)# git checkout --track [a proper tag or branch]
(venv)# pip install .
(venv)# python install


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

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';

Configure Nitrate

Create the following files.

/var/www/html/mynitrate/ - 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", "tcms.settings.product")

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)# migrate --settings=tcms.settings.product
(venv)# createsuperuser --settings=tcms.settings.product
(venv)# collectstatic --settings=tcms.settings.product

Verify that your configuration works by:

(venv)# runserver --settings=tcms.settings.product


For more information about Nitrate configuration see Nitrate configuration settings!

Create upload directory

Create upload directory and change owner & group to apache:

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

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/

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:

# 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
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/
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"