Selasa, 01 November 2016

Setup Ubuntu 16.04 LTS + Django + Apache + Mod WSGI

$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install python python-dev python-pip \
    apache2 libapache2-mod-wsgi
$ export
$ sudo pip install --upgrade pip
$ sudo pip install django
$ sudo pip install Pillow
$ sudo pip install pytz
$ sudo pip install unicodecsv


Ubah baris ini sesuai contoh:

<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all denied
</Directory

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>


Sebagai catatan, project penulis ada di folder: /home/username/nama_project. Ini adalah folder utama untuk GIT. Folder django project sendiri ada di: /home/username/nama_project/nama_project. Sedangkan file wgsi.py ada di /home/username/nama_project/nama_project/nama_project
Tambahkan baris ini:

Alias /media/ /home/username/nama_project/nama_project/media/
Alias /static/ /home/username/nama_project/nama_project/static/

<Directory /home/username/nama_project/nama_project/static>
        Require all granted
</Directory>

<Directory /home/username/nama_project/nama_project/media>
        Require all granted
</Directory>


WSGIScriptAlias / /home/username/nama_project/nama_project/nama_project/wsgi.py
WSGIPythonPath /home/username/nama_project/nama_project

<Directory /home/username/nama_project/nama_project/nama_project>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>


Tambahkan file .htaccess di folder wsgi.py berada.

Terakhir, pastikan group www-data dapat mengakses root directory user /home/username.