Skip to content
César Del Solar edited this page Aug 17, 2018 · 29 revisions

NOTE: The following is extremely out of date. We use Kubernetes now.

The following are some notes from deploying webolith on an AWS instance, as well as general setup info.

Requirements:

Use pip and virtualenv!

Here is my "pip freeze" file. It is recommended that you install pip, and use virtualenv to create a virtual environment for this installation. This currently has been tested and runs with Python 2.6.6 but I don't see why it wouldn't work for 2.7.

BeautifulSoup==3.2.0
Django==1.3
Fabric==1.2.0
Markdown==2.0.1
MySQL-python==1.2.3
South==0.7.3
cssmin==0.1.4
-e git://github.com/azuer88/django-basic-apps.git@c757ee207b4e699ddf2c4cd00bb495d9a3b65ca9#egg=django_basic_apps-dev
django-registration==0.8
django-tagging==0.3.1
gunicorn==0.13.4
paramiko==1.7.7.1
pycrypto==2.3
python-dateutil==2.0
recaptcha-client==1.0.6
webassets==0.5
wsgiref==0.1.2
redis==2.7.2

Almost all of the above packages can be installed with pip install Django==1.3 (for example), EXCEPT for the following:

Other requirements

  • MySQL (yum install mysql). Create a user and a database named djAerolith and grant access to user for this database:
create user 'aerolith'@'localhost' identified by 'password';
grant all privileges on djAerolith.* to 'aerolith'@'localhost' with grant option;
  • If need to restore from a sql backup:

mysql -u aerolith -p djAerolith < backup.sql

  • dbCreator needs Qt (4.7+, probably lower will work) to create the MySQL alphagram/word/lexicon "dump" files that can be loaded in with LOAD DATA INFILE. I will probably host these too in the future.

Prior to running

Make sure to do a python manage.py syncdb and a python manage.py migrate app for each South-controlled app if this is a new code installation. app should be replaced with wordwalls, accounts, and tablegame right now.

Serving the app

nginx, gunicorn:

http://ericholscher.com/blog/2010/aug/16/lessons-learned-dash-easy-django-deployment/

  • python manage.py run_gunicorn --config ../gunicornConf.py --daemon
  • kill -HUP `cat /home/ec2-user/webolith/gunicorn.pid` to reload new configuration/new code

sudo yum install nginx (or another way of installing nginx. you don't need nginx unless you are deploying to a web server -- for local testing, gunicorn or even Django's manage.py runserver is fine)

nginx start: sudo /etc/init.d/nginx start
conf file is at /etc/nginx/nginx.conf

to restart:
find pid of nginx master and send -HUP to it
sudo kill -HUP `cat /var/run/nginx.pid`

my nginx conf file:

user              nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


#----------------------------------------------------------------------
# Events Module 
#
#   http://wiki.nginx.org/NginxHttpEventsModule
#
#----------------------------------------------------------------------

events {
    worker_connections  1024;
    accept_mutex off; # on if worker_rpocesses > 1
}


#----------------------------------------------------------------------
# HTTP Core Module
#
#   http://wiki.nginx.org/NginxHttpCoreModule 
#
#----------------------------------------------------------------------

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream app_server {
    	server 127.0.0.1:8000 fail_timeout=0;
    }


    server {
        listen       80;
        server_name  .aerolith.org;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

	#root /home/ec2-user/webolith_static;

	 location /static/ {
	 # check for static file, if not found proxy to app
	   alias /home/ubuntu/webolith_static/;
#	   try_files $uri @proxy_to_app;
   
	 }
	 location /lists {
	   alias /home/ubuntu/public_html/lists;
	   autoindex on;
	 }
	 location /favicon.ico {
	   alias /home/ubuntu/favicon.ico;
	 }

	 location / {
	    try_files $uri @proxy_to_app;
	 }

#	 location /static/
#	 {

# }


	 location @proxy_to_app {
	 	  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		  proxy_set_header Host $http_host;
		  proxy_redirect off;
		  #proxy_buffering off;

		  proxy_pass http://app_server;


		  }

    }

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

}