Search Posts on Binpipe Blog

Django Installation on Centos 7 with Apache mod-wsgi & MariaDB

## Install the Components from the CentOS and EPEL Repositories

yum install epel-release
yum install python-pip httpd mod_wsgi
pip install --upgrade pip
yum install python-pip python-devel gcc mariadb-server mariadb-devel
sudo systemctl start mariadb
sudo systemctl enable mariadb

## Create a Database and Database User

mysql -u root -p

CREATE USER novice@localhost IDENTIFIED BY 'redhat';
GRANT ALL PRIVILEGES ON noviceproj.* TO novice@localhost;

## Install Django within a Virtual Environment & Connect DB

pip install virtualenv
mkdir noviceproj
cd noviceproj/
virtualenv noviceenv
source noviceenv/bin/activate
pip install django mysqlclient

Open the main Django project settings file located within the child project directory:

vi ~/noviceproj/noviceproj/
Towards the bottom of the file, you will see a DATABASES section that looks like this:

. . .

'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

. . .
This is currently configured to use SQLite as a database. We need to change this so that our MariaDB database is used instead. To do that comment the above and append the below lines:

'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'noviceproj',
'USER': 'novice',
'PASSWORD': 'redhat',
'HOST': 'localhost',
'PORT': '3306',

## Migrate the Database and Test your Project

cd ~/noviceproj/
python makemigrations
python migrate
python createsuperuser

vi noviceproj/

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

./ collectstatic

(set user/passwd for admin)

## Start Development Server

python runserver

Quit the server with CONTROL-C.

To leave virtualenv type:


## Setting up Apache Server with Mod_wsgi

vi /etc/httpd/conf.d/django.conf

Alias /static /root/noviceproj/static
<Directory /root/noviceproj/static >

Require all granted
<Directory /root/noviceproj/noviceproj>

Require all granted
WSGIDaemonProcess noviceproj python-path=/root/noviceproj:/root/noviceproj/noviceenv/lib/python2.7/site-packages

WSGIProcessGroup noviceproj
WSGIScriptAlias / /root/noviceproj/noviceproj/

usermod -a -G root apache
chmod 710 /home/user (not required)
chown :apache ~/noviceproj

systemctl restart httpd

No comments:

Post a Comment

Hi, Leave a comment here and one of the binary piper's will reply soon :)