<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.toString() &#187; Django</title>
	<atom:link href="http://www.dottostring.com/category/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dottostring.com</link>
	<description>Programming is our passion</description>
	<lastBuildDate>Sun, 04 Oct 2009 15:57:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django deployment on Amazon EC2 &#8211; Step by step tutorial</title>
		<link>http://www.dottostring.com/2009/10/django-deployment-on-amazon-ec2-step-by-step-tutorial/</link>
		<comments>http://www.dottostring.com/2009/10/django-deployment-on-amazon-ec2-step-by-step-tutorial/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 15:57:48 +0000</pubDate>
		<dc:creator>Irfan</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[amazon ec2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=382</guid>
		<description><![CDATA[Making EC2 Tools environment:

Download and the command line tools from http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&#38;categoryID=88 and extract at some place like: C:\ec2-api-tools-1.3-41620
Login into your amazon EC2 account. Goto:
Your Account -&#62; Security Credentials -&#62; x.509 Certificates
make one and download to some place like C:\ec2
Make sure that you have latest version of JRE installed on your local machine. Now use the [...]]]></description>
			<content:encoded><![CDATA[<h2>Making EC2 Tools environment:</h2>
<ol>
<li>Download and the command line tools from <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&amp;categoryID=88" target="_blank">http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&amp;categoryID=88</a> and extract at some place like: C:\ec2-api-tools-1.3-41620</li>
<li>Login into your amazon EC2 account. Goto:<br />
Your Account -&gt; Security Credentials -&gt; x.509 Certificates<br />
make one and download to some place like C:\ec2</li>
<li>Make sure that you have latest version of JRE installed on your local machine. Now use the following commands to set environment variables, (CHANGE THE PATHS TO YOUR PATHS):<br />
<code>set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_11"<br />
set EC2_HOME=C:\ec2-api-tools-1.3-41620<br />
set PATH=%PATH%;%EC2_HOME%\bin<br />
set EC2_PRIVATE_KEY=c:\ec2\pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem<br />
set EC2_CERT=c:\ec2\cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem</code></li>
</ol>
<p>Now we have our local machine ready to use EC2 commands.</p>
<h2>Running and connecting to the instance</h2>
<ol>
<li>Get a list of available amazon AMIs using this command<br />
<code>ec2-describe-images -o self -o amazon | grep fedora</code> <br />
We have applied the fedora filter as we want to use it. There is an apache-mysql fedora core4 AMI available as ec2-public-images/fedora-core4-apache-mysql.manifest.xml. We will be using this AMI. Note down its id, which is in this case: ami-25b6534c</li>
<li>Now we will be downloading our private RSA key to be used with this AMI. Run the following command in command prompt:<br />
<code>ec2-add-keypair gsg-keypair<br />
</code>and save everything between these lines including these lines as &#8220;id_rsa-gsg-keypair&#8221;:<br />
&#8220;&#8212;&#8211;BEGIN RSA PRIVATE KEY&#8212;&#8211;&#8221;<br />
&#8220;&#8212;&#8211;END RSA PRIVATE KEY&#8212;&#8211;&#8221;   <br />
We want to use putty to communicate with this AMI. Our private key needs to be converted into putty format. Download puttygen.exe from <a href="http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe " target="_blank">http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe </a>open puttygen.exe, load id_rsa-gsg-keypair and save private key</li>
<li>Run the public AMI instance using this command:<br />
<code>ec2-run-instances ami-25b6534c -k gsg-keypair<br />
</code>NOTE DOWN THE ID OF THE INSTANCE </li>
<li>You can use this command to check the status of you instance. Note down the server address of the instance:<br />
<code>ec2-describe-instances i-548****<br />
</code>(Replace i-548**** with you instance id)</li>
<li>Now we need to open port 22 (for ssh) and port 80 (for http) on this instance. Run the following commands in command prompt.<br />
<code>ec2-authorize default -p 22<br />
ec2-authorize default -p 80</code></li>
<li>Enter the server address noted down in step 4 to your browser. You should see a default Fedora Core 4 Apache welcome page.</li>
<li>Open putty; goto<br />
Connection -&gt; SSH -&gt; Auth<br />
browse for your private key you made using puttygen.                            </p>
<p>Enter the sever address from step 4 to connect and use the username &#8216;root&#8217; to login. </li>
<li>Once successfully connected, you can use this instance like any other Linux server.</li>
</ol>
<h2>Configuring Server, Apache and mode_python</h2>
<ol>
<li><a href="http://yum.baseurl.org/" target="_blank">Yum</a> is already installed on this instance but it needs to be configured. Open the file <em>/etc/yum.repos.d/fedora.repo</em> and uncomment the <em>baseurl</em> line. Also change the url to http://archives.fedoraproject.org/pub/archive/fedora/linux/*****<br />
Do the same with <br />
<em> /etc/yum.repos.d/fedora-updates.repo <span style="font-style: normal;">and</span><br />
/etc/yum.repos.d/fedora-extras.repo</em></li>
<li>Update the list:<br />
<code>yum check-update</code></li>
<li>Use following  commands to install some packages using yum:<br />
<code>yum install gcc<br />
yum install httpd-devel<br />
yum install python-devel</code></li>
<li>Now install mod_python using following commands:<br />
cd /tmp<br />
wget http://download.filehat.com/apache/httpd/modpython/mod_python-3.3.1.tgz<br />
tar xvfz mod_python-3.3.1.tgz<br />
cd mod_python-3.3.1<br />
./configure<br />
make<br />
make install</li>
<li>mod_python is installed. Now we just need to add following lines to /etc/httpd/conf/httpd.conf to make it load with apache.<br />
<code>LoadModule python_module modules/mod_python.so<br />
PythonOption mod_python.mutex_directory "/tmp"<br />
PythonOption mod_python.mutex_locks 8</code></li>
</ol>
<h2>Saving the EC2 instance on S3</h2>
<p>You will loose all settings and configurations as you will terminate the instance. We need to save instance as our own AMI at this stage.</p>
<ol>
<li>Download PSCP from <a href="http://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe" target="_blank">http://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe</a> and run the following command in command prompt to transfer our X.509 certificate to the server for future use.pscp -i id_rsa-gsg-keypair pk-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem cert-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem root@ec2-67-***-***-***.compute-1.amazonaws.com:/mnt (Replace Server name and .pem file names/paths with your files.)</li>
<li> Now we need to download AMI-Tools for backup of our instance. Go back to putty, log into the server as described before and run the following set of commands.<br />
<code>cd /tmp<br />
wget http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368&amp;categoryID=88<br />
unzip ec2-ami-tools-1.3-34544.zip<br />
cp -r ec2-ami-tools-1.3-34544/ /usr/local/<br />
export EC2_AMITOOL_HOME=/usr/local/ec2-ami-tools-1.3-34544/<br />
export PATH=$PATH:${EC2_AMITOOL_HOME:-EC2_HOME}/bin<br />
ec2-bundle-vol -d /mnt -k /mnt/pk-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem -c /mnt/cert-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem -u YOUR_AWS_ACCOUNT_ID -r i386 -p mod_python<br />
</code>(Replace YOUR_AWS_ACCOUNT_ID with your account ID) </li>
<li>This will take some time and will create image files in /mnt. Now we will upload these image files to S3 using this command<br />
<code>ec2-upload-bundle -b  -m /mnt/image.manifest.xml -a  -s </code><br />
 <br />
It will take some time.</li>
<li>Now we need to register our image so that AWS can locate it.<br />
<code>ec2-register /image.manifest.xml</code> <br />
You will get you AMI id, safe it for future use. </li>
<li>Now you can safely terminate your instance.</li>
</ol>
<h2>Installing django</h2>
<ol>
<li>Use the following commands to install django:<br />
<code>cd /usr/local<br />
svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk<br />
ln -s `pwd`/django-trunk/django /usr/lib/python2.4/site-packages/django<br />
ln -s /usr/local/django-trunk/django/bin/django-admin.py /usr/local/bin</code></li>
<li>Edit the httpd.conf at /etc/httpd/conf/httpd.conf and add following lines:<br />
&lt;Location &#8220;/mysite/&#8221;&gt;<br />
SetHandler python-program<br />
PythonHandler django.core.handlers.modpython<br />
SetEnv DJANGO_SETTINGS_MODULE mysite.settings<br />
PythonOption django.root /mysite<br />
PythonDebug On<br />
PythonPath &#8220;['/path/to/project'] + sys.path&#8221;<br />
&lt;/Location&gt;<br />
 </li>
<li>Restart the apache and you are ready to go <img src='http://www.dottostring.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2009%2F10%2Fdjango-deployment-on-amazon-ec2-step-by-step-tutorial%2F';
  addthis_title  = 'Django+deployment+on+Amazon+EC2+%26%238211%3B+Step+by+step+tutorial';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2009/10/django-deployment-on-amazon-ec2-step-by-step-tutorial/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
