Deploying numberphil.com

In this page, we'll first work on local environment, and then deploy numberphil app to our VPS.
This numberphil app is using Django 1.8.
Get the source:
$ git clone https://github.com/PyGoogle/NumberPhil.git
Setup virtualenv:
$ cd NumberPhil $ virtualenv venv $ source venv/bin/activate
Let's install necessary packages and their dependencies in a virtualenv:
(venv)$ pip install -r requirements.txt
Let's create a MySQL db called numberphildb with a user:
(venv)$ mysql -u root -p mysql> CREATE DATABASE numberphil; mysql> CREATE USER 'numberphil'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'numberphil'@'localhost';
Start the application.
(venv)$ python manage.py makemigrations (venv)$ python manage.py migrate
Run server:
(venv)$ python manage.py runserver
At "http://localhost:8000/", got the following error:
TemplateSyntaxError at / 'numberphil' is not a valid tag library: Template library numberphil not found...
We do not have a templatetags. Actually, we copied the project from the script used to build einsteinish.com. So, we need to rename it. Under resources/templatetags:
$ mv einsteinish.py numberphil.py
404 error for static/css:
"GET /static/css/numberphil.css HTTP/1.1" 404 1667
Another error (SMTP) when the user tries to register (http://localhost:8000/accounts/register/):
SMTPDataError at /accounts/register/ (421, '4.7.0 Temporary System Problem. Try again later (RQ). 28sm32700166pfr.89 - gsmtp')

We need to set a proper id for django-site in local_settings.py:
#SITE_ID = 1 # example.com (default) SITE_ID = 2 # localhost:8000 #SITE_ID = 3 # numberphil.com
Setting up DB:
[sfvue@sf numberphil3]$ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 25397 Server version: 5.5.44-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database numberphildb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | djangotestdb | | doremidb | | einsteinishdb3 | | einsteinishdb5 | | mysql | | numberphildb | | performance_schema | | sfvuedb | | sfvuedb3 | | sfvueuserdb | +--------------------+ 11 rows in set (0.00 sec)
To create a user with superuser privilege:
MariaDB [(none)]> CREATE USER 'numberphil'@'localhost' IDENTIFIED BY 'password'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON * . * TO 'numberphil'@'localhost';
Setup virtual env and install packages:
[sfvue@sf numberphil3]$ virtualenv venv [sfvue@sf numberphil3]$ source venv/bin/activate (venv)[sfvue@sf numberphil3]$ pip install -r requirements.txt
Then, we need to set proper environment (local_settings.py such as DB password and django-site ID.
Create tables for numberphildb:
(venv)[sfvue@sf numberphil3]$ python manage.py makemigrations (venv)[sfvue@sf numberphil3]$ python manage.py migrate
To access DB from remote, we can use port forwarding :
$ ssh -L 9001:localhost:80 -l sfvue 45.79.90.218
Set ID for django-site in numberphildb:

Set up a virtualhost for numberphil.com in /etc/httpd/sites-available/numberphil.com.conf:
<VirtualHost *:80> ServerAdmin webmaster@numberphil.com ServerName www.numberphil.com ServerAlias numberphil.com ErrorLog /var/www/numberphil.com/logs/error.log CustomLog /var/www/numberphil.com/logs/access.log combined WSGIDaemonProcess numberphil3 python-path=/var/www/django/numberphil3:/var/www/django/numberphil3/venv/lib/python2.7/site-packages WSGIProcessGroup numberphil3 WSGIScriptAlias / /var/www/django/numberphil3/numberphil/wsgi.py Alias /static/ /var/www/django/numberphil3/static/ </VirtualHost> #<Directory /> # Options Indexes FollowSymLinks # AllowOverride None # Require all granted #</Directory> WSGIPythonPath /var/www/django/numberphil3/ <Directory /var/www/django/numberphil3/numberphil> <Files wsgi.py> Require all granted </Files> </Directory>
Make a softlink:
$ sudo ln -s /etc/httpd/sites-available/numberphil.com.conf /etc/httpd/sites-enabled/numberphil.com.conf
Restart the Apache server:
$ sudo apachectl restart
In this section, some of the errors and the fixes will be listed.
When we try to store an image thumbnail for a topic, got this error:
OSError at /resource/topic/new/ [Errno 13] Permission denied: '/var/www/django/numberphil3/media'
By modifying the permission, we can fix the problem:
$ sudo chown -R apache:apache media
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization