Installing nitrate on RHEL6 with Apache and MySQL

This deployment document presumes that you are running Red Hat Enterprise Linux 6. Of course, all deployment steps being described through this document also apply to other Linux distributions, such as CentOS, openSUSE, or Debian.

This document aims to deployment within a server that will serve test case management service to stuffs or customers. Therefore, all commands and configuration are done with system Python interpreter and those configuration files installed in the standard system directories, like the /etc/httpd/conf/httpd.conf.

Installation

Get source code

The Nitrate source code is available at:https://github.com/Nitrate/Nitrate

You can get the latest changes with git easily:

git clone https://github.com/Nitrate/Nitrate.git
git checkout --track [a proper tag or branch]

Install dependencies

Install devel packages that should be installed first:

sudo yum install gcc python-devel mysql-devel krb5-devel libxml2-devel libxslt-devel

Install dependencies:

sudo pip install path/to/Nitrate

Install from source code

After downloading the source code, go to the source code directory and install this project with python setup.py:

cd [nitrate_download_path]/nitrate
sudo python setup.py install

Initialize database

Database is required by Nitrate (and all of Django apps). Django ORM supports many database backends, we recommend you to use MySQL.

Create database and user for nitrate in mysql:

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

Update settings/product.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'nitrate',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'nitrate',
        'PASSWORD': 'password',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

Create tables and load initial data:

django-admin.py migrate --settings=tcms.settings.product

Create super user if needed:

django-admin.py createsuperuser --settings=tcms.settings.product

Config Settings

First please go to nitrate root path, it’s different based on your current OS.

Like on RHEL6.3, the root path is located in:

/usr/lib/python2.6/site-packages/nitrate-3.8.6-py2.6.egg/tcms

As we plan to deploy an example server for nitrate, we can use product.py as the default settings. After backed up the product.py, please modify settings based on your custom configurations in settings/product.py. For more information see Configuration!

Use cache (Optional)

You can use Django’s cache framework to get better performance.

Refer to following docs for more details:

Start the django app

After upon steps is completed, now you can try to start the web server which is a built-in development server provided by Django to test if the app can run as expected. Run following command:

django-admin.py runserver --settings=tcms.settings.product

Then try to use web browser to open http://localhost:8000/ to verify the working status of this web service.

Install Apache & mod_wsgi

Install httpd & mod_wsgi:

sudo yum install httpd mod_wsgi

Create upload dir

Create upload dir and change dir own & group to apache:

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

Collect static files

The default directory to store static files is /var/nitrate/static, you can modify it by changing STATIC_ROOT setting in /path/to/nitrate/tcms/settings/product.py.

Run following command to collect static files:

sudo django-admin.py collectstatic --settings=tcms.settings.product

Reference: https://docs.djangoproject.com/en/1.5/howto/static-files/deployment/

Deploy with Apache

Deploying Django projects with Apache and mod_wsgi is the recommended way to get them into production.

Create wsgi.conf in /etc/httpd/conf.d/ which include one line:

LoadModule wsgi_module modules/mod_wsgi.so

To build a production server with Apache, just copy apache conf to /etc/httpd/conf.d/.

I presume that the conf file is named nitrate-httpd.conf.

PidFile /tmp/httpd.pid
Listen 0.0.0.0:8080
User apache
Group apache
DocumentRoot "/var/www/html"
Include conf.modules.d/*.conf

LogLevel notice
ErrorLog /dev/stderr
TransferLog /dev/stdout

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

WSGIDaemonProcess nitrateapp processes=2 python-path=/nitrate-config
WSGIProcessGroup nitrateapp
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /usr/lib/python3.10/site-packages/tcms/wsgi.py
WSGIPassAuthorization On
WSGISocketPrefix /var/run/wsgi/nitrate-wsgi

<Location "/">
    SetHandler wsgi-script
    Options 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>

# Uncomment if HTTP over SSL is enabled.
#<IfModule mod_rewrite.c>
#    RewriteEngine on
#    RewriteCond %{HTTPS} off
#    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
#</IfModule>

# Make sure static files are collected to this directory
Alias /static /usr/share/nitrate/static

<Location "/static">
    SetHandler None
    Options -Indexes
    # Disable auth on the static content.
    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
    ExpiresActive On
    ExpiresDefault "access plus 10 years"
</Location>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

Change any configuration to fit your deployment environment.

In /etc/httpd/conf/httpd.conf, set the following settings simply:

ServerName example.com:80
Listen ip_address:80

After configuration, run:

sudo service httpd start

Please go to browser to have a verify if this service runs successfully.

If any problem, please refer to log file:

/var/log/httpd/error_log

Or any access info, refer to:

/var/log/httpd/access_log