A Noob Speaks to Noobs:�
Your first site in the cloud
Katie Cunningham
Cox Media Group
Who am I?
Why learn server basics?
Story time!
Ground Rules
Tools we'll be using
Picking an OS
DO NOT:
Do use the one that works for you
I'm using Ubuntu
Picking a provider
Look for:
Some providers!
I'm using
Before we get going…
How are we going to serve the site?
So many choices!
I’m using
Apache + mod_wsgi
Setting up Apache
File: mysite.wsgi
import os, sys
sys.path.append('/var/www/django/django_projects/')
os.environ['DJANGO_SETTINGS_MODULE'] = ’mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And the virtual host…
File: mysite.net
<VirtualHost *:80>
ServerAdmin whoever@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/django/django_projects/mysite
LogLevel warn
WSGIDaemonProcess myuser processes=2 maximum-requests=500 threads=1
WSGIProcessGroup myuser
WSGIScriptAlias / /var/www/mydjango/apache/mysite.wsgi
Alias /media /var/www/mydjango/media/mysite/
Alias /admin_media /var/www/mydjango/admin_media
</VirtualHost>
Get a server
Done through the web interface
Get a server
Add a server
Get a server
Pick your OS
Get a server
Pick what size you want
Get a server
Seriously, save the password.
Get a server
YAY! It’s done!
Get a server
You now have a server!
Get a server
Some words about this server…
Server setup!
NO
We are starting this right.
Fabric
Running the fabric script
fab -f new_server.py -H XX.XX.XX.XX –u root deploy
Server setup!
Tasks:
Server setup!
We need some packages…
PACKAGES=('apache2',
'subversion',
'sqlite3',
'python-setuptools',
'python-pip',
'git-core',
'gitosis',
'libapache2-mod-wsgi',)
Server setup!
Let’s get our server ready!
def setup_server():
sudo('apt-get update')
for p in PACKAGES:
sudo('apt-get -y install %s' % p)
Server setup!
Adding a user…
def add_user(user):
local('touch passwords')
sudo('useradd -m %s' % (user))
sudo('echo "%s ALL=(ALL) ALL" >> /etc/sudoers' % user)
password = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(8))
sudo('echo "%s:%s" | chpasswd' % (user, password))
local('echo "%s:%s" >> passwords' % (user, password))
Server setup!
Install our pip things!
PIP_PACKAGES = (‘django’,)
def pip_install():
for package in PIP_PACKAGES:
sudo('pip install %s' % package)
Setup is NOT DONE?!
Moving some files…
def put_files():
sudo('mkdir -p /tmp/deploy/')
sudo('chown kcunning /tmp/deploy')
local('rm -rf mysite')
local('git clone git@github.com:yourgitname/gitrepo')
local('tar cvf deploy-files.tar gitrepo/*')
put('deploy-files.tar', '/tmp/deploy/')
sudo('tar xvf /tmp/deploy/deploy-files.tar -C /tmp/deploy')
local('rm -rf gitrepo')
Argh MORE SETUP
def place_files():
sudo('mv /tmp/deploy/The-Real-Katie/config/therealkatie.net /etc/apache2/sites-available/')
sudo('mv /tmp/deploy/The-Real-Katie/config/trk.wsgi /var/www/mydjango/apache/’)
Almost there…
def services():
sudo('a2ensite mysite.com')
sudo('service apache2 restart')
We’re done!
Huzzah!
DO IT AGAIN
Updates
You’ll eventually want to update things…
Clone your server
Updates
Go get your image…
Updates
Create a new image…
Updates
Now make a new server!
Updates
Choose your image and size…
Updates
Include:
Next steps