Install Elasticfox

Install the Elasticfox Firefox Extension for Amazon EC2: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=609

Set up Amazon EC2 accounts and Elasticfox

Follow Arope's instructions for setting up Amazon EC2 accounts and Elasticfox. I used the alestic/ubuntu-8.04-hardy-base-20080628.manifest.xml machine image.

view standard apache page

In Elasticfox, right-click on your running instance and select "Copy Public DNS Name to clipboard". Then, paste that address in your browser. You should see Apache's "It works!" page.

ssh into instance

In Elasticfox, right-click on your running instance and select "SSH to Public Domain Name"

install stuff

Ubuntu Hardy has the following versions:

Apache 2.2.8

Mod_python 3.3.1

MySql 5.0.51

Django 0.96.1

On your remote instance, do the following.

# apt-get update # apt-get install python-django # apt-get install mysql-server # apt-get install python-mysqldb # apt-get install libapache2-mod-python

Update 2008-09-09: The Django mod_python documentation recommends using Apache's prefork MPM as opposed to the worker MPM. The worker MPM was installed by default on my Alestic Ubuntu image so I uninstalled it and replaced it with the prefork version.

# apt-get autoremove --purge apache2-mpm-worker # apt-get install apache2-mpm-prefork

To see your current version of Apache, run the command: apache2 -V

create a django project

# cd /srv # django-admin startproject mysite

configure django mod_python

See also Jeff Baier's article: Installing Django on an Ubuntu Linux Server for more information.

Edit /etc/apache2/httpd.conf and insert the following:

<location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonPath "['/srv'] + sys.path" PythonDebug On </location>

restart the apache server

# /etc/init.d/apache2 restart

You should see Django's "It Worked!" page.

Set up a MySql database and user

Note, use the password you entered when installing MySql

# mysql -u root -p Enter password: mysql> CREATE DATABASE django_db; Query OK, 1 row affected (0.01 sec) mysql> GRANT ALL ON django_db.* TO 'djangouser'@'localhost' IDENTIFIED BY 'yourpassword'; Query OK, 0 rows affected (0.03 sec) mysql> quit Bye

Edit the Django database settings

mysite/settings.py

DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. DATABASE_NAME = 'django_db' # Or path to database file if using sqlite3. DATABASE_USER = 'djangouser' # Not used with sqlite3. DATABASE_PASSWORD = 'yourpassword' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.

Do a 'syncdb' to create the database tables

# cd mysite # python manage.py syncdb Creating table auth_message Creating table auth_group Creating table auth_user Creating table auth_permission Creating table django_content_type Creating table django_session Creating table django_site You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'sofeng'): E-mail address: sofeng@email.com Password: Password (again): Superuser created successfully. Installing index for auth.Message model Installing index for auth.Permission model Loading 'initial_data' fixtures... No fixtures found.

upload a mercurial django project

Edit

on the remote instance, install mercurial:

# apt-get install mercurial

on your local machine with the mercurial repo, run:

$ hg clone -e 'ssh -i /home/sofeng/.ec2-elasticfox/id_django-keypair.pem' yourproj ssh://root@yourdns.compute-1.amazonaws.com//srv/yourproj

/home/sofeng/.ec2-elasticfox/id_django-keypair.pem

yourdns.compute-1.amazonaws.com

whereis the private key associated with your instance andis the public domain name associated with your instance.

back on the remote instance:

# cd /srv/mozblog # hg update

# python manage.py syncdb

set up apache to serve static files

Create a link to the media files: # cd /var/www # ln -s /srv/mozblog/media site_media # ln -s /usr/share/python-support/python-django/django/contrib/admin/media/ admin_media

Edit /etc/apache2/httpd.conf : <location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mozblog.settings PythonPath "['/srv'] + sys.path" PythonDebug On </location> <location "/site_media"> SetHandler None </location> <location "/admin_media"> SetHandler None </location>

Restart the apache server

# /etc/init.d/apache2 restart