-
Notifications
You must be signed in to change notification settings - Fork 20
Production Deployment Notes
These are some rough notes for deploying Tramcar using Apache2 and mod_wsgi. If you run into any problems along the way, please create an issue so we can help you figure it out. These notes assume you followed the steps outlined in the README.
Install the necessary apt and python packages:
$ sudo apt-get install apache2 libapache2-mod-wsgi-py3 mysql-server python3-dev libmysqlclient-dev
$ source .venv/bin/activate
(.venv) $ pip install mysqlclient
In tramcar/settings.py
, change:
DEBUG = False
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<db>',
'USER': '<user>',
'PASSWORD': '<password>'
}
}
In tramcar/settings.py
, add the following:
STATIC_ROOT = "/var/www/html/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "job_board/static/"),
os.path.join(BASE_DIR, ".venv/lib/python3.5/site-packages/django/contrib/admin/static/"),
]
The above assumes that you will be serving static content from /var/www/html/static
. Ensure the directory exists and is writable by the user you run Django's manage.py with.
With that the static files configuration in place, you will now need to do the following to copy the static files for the Django admin and Tramcar to /var/www/html/static
:
(.venv) $ python manage.py collectstatic
The best way to ensure the previous step completed is to log into the admin panel (/admin) once everything is up and running and ensure CSS is loading correctly.
In /etc/apache2/sites-enabled/000-default.conf
:
WSGIScriptAlias / /home/<user>/tramcar/tramcar/wsgi.py
# mod_wsgi 3.4 (Ubuntu Trusty)
# WSGIDaemonProcess tramcar path=/home/<user>/tramcar/:/home/<user>/tramcar/.venv/lib/python3.4/site-packages/
# mod_wsgi 4.3.0 (Ubuntu Xenial)
WSGIDaemonProcess tramcar home=/home/<user>/tramcar/ python-path=/home/<user>/tramcar/.venv/lib/python3.5/site-packages/
<VirtualHost *:80>
ServerName tramcar.<somedomain.com>
ServerAdmin webmaster@<somedomain.com>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIProcessGroup tramcar
Alias /static/ /var/www/html/static/
<Directory /home/<user>/tramcar/tramcar>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
# Not required, but locking down /admin is probably a very good idea!
#<Location /admin>
#Require ip <ip>
#</Location>
</VirtualHost>
To send e-mails from Tramcar (for example, when jobs are expired), add the following to tramcar/settings.py
:
EMAIL_HOST = 'smtp.mailgun.org'
EMAIL_HOST_USER = '<mailgun_user>'
EMAIL_HOST_PASSWORD = '<mailgun_password>'
We highly recommend using a service like Mailgun -- not having to fiddle with SMTP servers means you will have more time to help us fix bugs. :)