Skip to content

Instantly share code, notes, and snippets.

@Guest007
Forked from fission6/Deploy Notes
Created November 19, 2015 14:16
Show Gist options
  • Save Guest007/246e0e4a4695e50bb789 to your computer and use it in GitHub Desktop.
Save Guest007/246e0e4a4695e50bb789 to your computer and use it in GitHub Desktop.
Deployment notes for Ubuntu Instance Nginx, uwsgi, postgres, django, virtualenv stack
Deployment notes for Ubuntu Instance
Nginx, uwsgi, postgres, django, virtualenv stack
* ssh root
root access (need pem)
ssh -i whatever.pem ubuntu@ec2-*-*-*-*.compute-1.amazonaws.com
* secure box
- cut off all ports but 22 and 80 using AWS Management Console
- edit /etc/ssh/sshd_config ensure PasswordAuthentication no
* add users
- create: on instance sudo useradd username -m -s /bin/bash
- password: sudo passwd username
- sudo group: sudo adduser <username> sudo
- create ssh keys: ssh-keygen -t rsa
* ssh devs
(http://aws.amazon.com/articles/1233)
- copy over local users public key
- add to ~/.ssh/authorized_keys
- chmod 700 on ~/.ssh, chmod 600 on authorized_keys
- ssh whatever@ec2-*-*-*-*.compute-1.amazonaws.com
- add to ~/.ssh/config
Host whatever
User whatever
HostName ec2-*-*-*-*.compute-1.amazonaws.com
- now: ssh whatever
* set up environment for hosting
- screen: modify ~/.screenrc
caption always "%{Wb} %H %{Bk}| %{Ck}%-w%50>%{Cb} %n %t %{-}%+w%<%{- Wk}%{Bk} | %=%{Wb} %C "
- install setuptools, pip, and virtualenv:
(http://www.pip-installer.org/en/latest/installing.html)
curl http://python-distribute.org/distribute_setup.py | sudo python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | sudo python
sudo pip install virtualenv
- setup virtualenv for app
1. cd ~/
2. virtualenv whatever.com --no-site-packages
3. activate by: `source bin/activate`
- install & configure uwsgi and nginx
(http://wiki.nginx.org/Install#Ubuntu_PPA)
1. sudo -s
2. sudo apt-get update
3. sudo apt-get install python-software-properties
4. nginx=stable # use nginx=development for latest development version
5. add-apt-repository ppa:nginx/$nginx
6. apt-get update
7. apt-get install nginx
- Git / pull down application code
1. cd ~/whatever.com
2. sudo apt-get install git
3. git config --global color.ui true
4. add public key of application user to github repo if need be
5. git clone [email protected]:whatever/whatevers.git
- postgres
(https://help.ubuntu.com/community/PostgreSQL)
(https://help.ubuntu.com/12.04/serverguide/postgresql.html)
1. sudo apt-get install postgresql
2. sudo -u postgres createuser whatever
3. sudo -u postgres psql
4. create database whatever;
5. alter user whatever password 'whatever'; # may need to edit /etc/postgres/../pg_hba.conf and make peer to md5 for password
6. test connection; `psql`
- psycopg2
1. pip install psycopg2
2. may need to
sudo apt-get install libpq-dev python-dev
- PIL
1. pip install PIL
w/ jpeg support
(http://dimamoroz.com/blog/3-ubuntu-pil-jpeg-support/)
1. sudo apt-get install libjpeg62-dev
2. cd /usr/lib
3. sudo ln -s x86_64-linux-gnu/libjpeg.so
4. sudo ln -s x86_64-linux-gnu/libz.so
- installing python packages
1. pip install whatever
- Spinning Up App
1. python manage.py syncdb
2. python manage.py migrate
3. test using python manage.py runserver 0.0.0.0:8000 (ensure port is opened)
4. dump local data, pg_dump dbname > output.sql
5. restore data psql dbname < output.sql
- uwsgi
1. pip install uwsgi
- Wiring up uwsgi and nginx
1. create ~/whatevers.com/conf/nginx.conf
2. create ~/whatevers.com/logs, point these in nginx.conf
(http://projects.unbit.it/uwsgi/)
3. create ~/whatever.com/media
4. ln -s /path/to/admin_tools/media/ admin_tools
5. start uwsgi `uwsgi -s 127.0.0.1:8000 -H /home/whatever/whatever.com/ -w whatever.wsgi -M`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment