Skip to content

Instantly share code, notes, and snippets.

@Kalki5
Last active April 26, 2018 05:48
Show Gist options
  • Save Kalki5/737acfcbc64bed245708b8f5e78993f1 to your computer and use it in GitHub Desktop.
Save Kalki5/737acfcbc64bed245708b8f5e78993f1 to your computer and use it in GitHub Desktop.
Deploy django 2.0.2 (REST app) on Ubuntu 16.04 with apache 2.4, python 3.6 and mod_wsgi
NameVirtualHost *:80
<VirtualHost *:80>
ServerName job.api.XXXXX.XXX
ServerAlias job
ServerAdmin webmaster@localhost
SetEnv DJANGO_SETTINGS_MODULE job_service.settings.production
<Directory /var/www/html/job.service/job_service>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess job.service python-home=/var/www/html/job.service/jobservice_env python-path=/var/www/html/job.service
WSGIProcessGroup job.service
WSGIScriptAlias / /var/www/html/job.service/job_service/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/job.error.log
CustomLog ${APACHE_LOG_DIR}/job.access.log combined
</VirtualHost>
sudo su
(Install apache, python, etc)
apt-get update
apt-get install python3-pip apache2 libapache2-mod-wsgi-py3 mysql-server
apt-get install python3.6-dev libmysqlclient-dev
pip3 install virtualenv
(Going to my project directory)
cd /var/www/html/job.service
(Creating venv nside my project directory)
virtualenv jobservice_env
source jobservice_env/bin/activate
(Install project dependencies)
pip install -r requirements.txt
chown -R www-data:www-data *
chmod -R 0755 *
(Djanog Migrate)
python manage.py migrate --settings=job_service.settings.production
(Check if development server works)
python manage.py runserver 0.0.0.0:9004 --settings=job_service.settings.production
(Enable mod_wsgi on apache)
a2enmod wsgi
(Edit apache configuration)
vim /etc/apache2/sites-available/common.conf
(Restart server)
service apache2 restart
(Finally check if it works)
curl job
(Use logs for troubleshooting)
tail -f /var/log/apache2/job.error.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment