<?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>Ray Acayan &#187; Apache</title>
	<atom:link href="http://www.RayAcayan.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.RayAcayan.com</link>
	<description>A Geek of All Trades</description>
	<lastBuildDate>Wed, 18 Aug 2010 19:40:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The Amazon EC2 Blog Migration Project</title>
		<link>http://www.RayAcayan.com/projects/the-amazon-ec2-blog-migration-project/</link>
		<comments>http://www.RayAcayan.com/projects/the-amazon-ec2-blog-migration-project/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 16:46:29 +0000</pubDate>
		<dc:creator>Ray Acayan</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Amazon EC2]]></category>
		<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[Consulting]]></category>
		<category><![CDATA[cPanel]]></category>
		<category><![CDATA[FileZilla]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mod_security]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OWASP]]></category>
		<category><![CDATA[PuTTY]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Webalizer]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://174.129.34.151/blog/?p=1080</guid>
		<description><![CDATA[I. Overview This side project presents my procedure for migrating my WordPress blog from a web hosting provider running cPanel to an Amazon EC2 instance. This project builds on the environment created in my previous blog post, &#34;The Mobile Cloud Project, Part 1.1: Basic AWS&#34;, where I presented an overview of Amazon Web Services and [...]]]></description>
			<content:encoded><![CDATA[<p></br></p>
<h2 style="color:darkblue">I. Overview</h2>
<p>This side project presents my procedure for migrating my WordPress blog from a web hosting provider running cPanel to an Amazon EC2 instance.</p>
<p>This project builds on the environment created in my previous blog post, <a href="http://www.rayacayan.com/projects/the-mobile-cloud-project-part-1-1-basic-aws/"><b>&quot;The Mobile Cloud Project, Part 1.1: Basic AWS&quot;</b></a>, where I presented an overview of Amazon Web Services and a procedure for creating virtual servers (Reserved and On-Demand instances) on Amazon EC2.<br />
<br /></br></p>
<h2 style="color:darkblue">II. Consulting</h2>
<p>I do my best to explain the concepts and techniques behind my projects.  If you like my work and can use my expertise in your projects, I am available for <span id="consulting_page" onmouseover="consulting_mouseOver()" onmousemove="consulting_mouseMove()" onmouseout="consulting_mouseOut()"><a href="http://www.RayAcayan.com/consulting/"><strong>consulting</strong></a></span> at a competitive rate.<br />
<br /></br></p>
<h2 style="color:darkblue">III. Procedure</h2>
<p>Once the Amazon EC2 instance was created and configured in my previous <a href="http://www.rayacayan.com/projects/the-mobile-cloud-project-part-1-1-basic-aws/"><b>blog post</b></a>, this migration procedure is actually fairly straightforward.  From the point of view of a terminal console, an Amazon EC2 instance running Ubuntu Linux is very similar to any other Ubuntu server.  The only difference is that certain tasks that were simplified behind a web hosting provider&#8217;s cPanel now need to be done explicitly on an EC2 instance.</p>
<p>This procedure assumes an existing WordPress blog at <a href="http://www.RayAcayan.com">http://www.RayAcayan.com</a> (i.e. this blog), an existing EC2 instance running Ubuntu 9.10 (Karmic), an Elastic IP address associated with that instance, and a local Windows client with Putty and FileZilla configured to connect to both the old blog&#8217;s web hosting provider and the new blog&#8217;s EC2 instance.  These were all configured in my previous blog post <a href="http://www.rayacayan.com/projects/the-mobile-cloud-project-part-1-1-basic-aws/"><b>&#8220;The Mobile Cloud Project, Part 1.1: Basic AWS&#8221;</b></a>. </p>
<h3 style="color:darkgreen">1.  Install packages on EC2 instance</h3>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li> Install Apache2, MySQL, PHP, Ruby on Rails, Python, and Django packages with the following commands.</li>
<div class="code">
$ sudo apt-get update<br />
$ sudo apt-get install apache2 mysql-server libapache2-mod-auth-mysql<br />
$ sudo apt-get install php5-mysql phpmyadmin<br />
$ sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev<br />
$ sudo apt-get install libmysqlclient15-dev<br />
<br />
$ sudo apt-get install ruby-full rubygems1.9.1 rails libmysql-ruby<br />
<br />
$ sudo apt-get install python2.6 python3 python-django<br />
$ sudo apt-get install libapache2-mod-python python-mysqldb
</div>
</ol>
<h3 style="color:darkgreen">2.  Enable mod_rewrite on Apache</h3>
<ol type="i">
<li>The mod_rewrite module allows WordPress to use pretty permalinks on your blog, such as /category/postname/</li>
<div class="code">
$ sudo a2enmod rewrite<br />
$ sudo nano /etc/apache2/sites-enabled/000-default
</div>
<li>Modify this file to show the following changes (i.e. change &#8220;None&#8221; to &#8220;All&#8221; to allow pretty permalinks, and add # comments to disable directory listing) then save this file.</li>
<div class="code">
DocumentRoot /var/www/<br />
[...]<br />
Options FollowSymLinks<br />
AllowOverride <b>All</b><br />
[...]<br />
<b>#</b> Options Indexes FollowSymLinks MultiViews<br />
<b>#</b> AllowOverride None<br />
<b>#</b> Order allow,deny<br />
<b>#</b> allow from all
</div>
<li>Restart Apache:</li>
<div class="code">
$ sudo /etc/init.d/apache2 restart
</div>
</ol>
<h3 style="color:darkgreen">3.  Install WordPress on the EC2 instance</h3>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li>Create the WordPress username and database on MySQL by entering the following commands:</li>
<div class="code">
$ sudo mysql -u root -p &lt;password&gt;<br />
mysql> create database wordpress;<br />
mysql> create user &lt;wp_username&gt;;<br />
mysql> set password for &lt;wp_username&gt; = password(&#8220;&lt;password&gt;&#8221;);<br />
mysql> grant all on wordpress.* to &lt;wp_username&gt;@localhost identified by `&lt;password&gt;&#8217;;<br />
mysql> quit
</div>
<li>Enter the following commands at the Linux prompt to download and install WordPress:</li>
<div class="code">
$ cd /var/www<br />
$ sudo wget http://wordpress.org/latest.tar.gz<br />
$ sudo tar -xzvf latest.tar.gz<br />
$ sudo mv wordpress blog
</div>
<li>Go to http://&lt;elastic ip&gt;/blog/wp-admin/install.php to execute the WordPress install script.</li>
<li>Download and install the WordPress themes and plugins that were in the previous blog (cPanel).</li>
</ol>
<p></p>
<h3 style="color:darkgreen">4.  Copy WordPress files and database from the old blog to the new blog</h3>
<ol type="i">
<li>Open FileZilla client and connect to the web hosting provider&#8217;s server that is hosting the old blog.  (See the provider&#8217;s instructions on how to do this.)</li>
<li>Download all files in the old blog:  ~/public_html or /var/www</li>
<li>Open a second FileZilla client to connect to the new blog (EC2). </li>
<li>Upload your custom files and directories to the /var/www directory of the new blog.</li>
<li>Open the WordPress Dashboard on the old blog (cPanel), click &quot;Export&quot; in the &#8220;Tools&#8221; menu on the left, and save the .xml file.</li>
<li>Open the WordPress Dashboard on the new blog (EC2), click &quot;Import&quot; in the &#8220;Tools&#8221; menu on the left, and upload the .xml file from the previous step. </li>
<li>Install the &#8220;WP-DB-Backup&#8221; plugin on both the old and new blogs.</li>
<li>On the old blog&#8217;s WordPress admin, click &#8220;Backup&#8221; on the &#8220;Tools&#8221; menu on the left and save the file as &#8220;oldwordpress.sql&#8221;.</li>
<li>Connect to the EC2 instance via FileZilla and upload the &#8220;oldwordpress.sql&#8221; file.
<li>Connect to the EC2 instance via Putty.</li>
<li>At the Linux prompt, enter &#8220;mysql wordpress &lt; oldwordpress.sql â€“u root -p&#8221; to import the old WordPress database to the new one.</li>
<li>Verify that the new blog is working at http://&lt;elastic ip&gt;/blog including links and styles. </li>
</ol>
<p></p>
<h3 style="color:darkgreen">5. Remap DNS to the new blog IP address on EC2</h3>
<ul>
<li>DNS needs to be configured to remap the blog&#8217;s domain name to the Elastic IP address of the new blog on EC2.</li>
</ul>
<ol type="i">
<li>Before proceeding, add an entry &#8220;&lt;elastic ip&gt; www.RayAcayan.com&#8221; to the local hosts file at C:\windows\system32\drivers\etc</li>
<li>Verify that the blog is working properly using the normal URL <a href="http://www.RayAcayan.com">http://www.RayAcayan.com</a></li>
<p>  At this point, only the local computer can access the new blog via URL because of the hosts file entry.  The new IP address will need to be propagated to the rest of the Internet via an external DNS provider so that everyone else can access it.</a></li>
<li>Select an external DNS provider such as <a href="http://www.easyDNS.com">http://www.easyDNS.com</a> and purchase a DNS-only service for about $20/year.</li>
<li>Add a DNS entry to map the hostname to the Elastic IP address of the new blog.</li>
<li>Go to the domain registrar&#8217;s website where the old blog domain is currently registered.</li>
<li>Change the name servers of the domain to point to the name servers of the  external DNS provider.</li>
<li>Wait several hours for the new DNS settings to propagate on the Internet.  Enter &#8220;nslookup&#8221; at the command prompt. If the response is the elastic IP address of the EC2 instance, then the DNS propagation has completed.</li>
<li>Remove the hosts file entry created in step 5.i. and run &#8220;ipconfig /dnsflush&#8221; at the command prompt. Verify that the blog is still reachable via the normal URL: <a href="http://www.RayAcayan.com">http://www.RayAcayan.com</a></li>
</ol>
<h3 style="color:darkgreen">6.  Install Additional Applications</h3>
<ol type="A">
<strong>
<li>Install Webalizer</li>
<p></strong><br />
Webalizer is a web stats application offered by your web hosting provider&#8217;s cPanel.  You will need to install it manually on your EC2 instance if you want to continue using it.</p>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li>Enter the following command to install Webalizer on the EC2 instance:</li>
<div class="code">
# apt-get install webalizer
</div>
</ol>
</ol>
<h3 style="color:darkgreen">7.  Configure Security</h3>
<ol type="A">
<strong>
<li>Secure the Apache web server with mod_security and Core Rule Set</li>
<p></strong></p>
<p>The &#8220;mod_security&#8221; Apache module is an open source intrusion detection and prevention engine for web applications.  It protects the Apache web server from common attacks such as SQL injection, cross-site scripting, etc.</p>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li>Enter the following commands at the Linux prompt:</li>
<div class="code">
#mkdir ~/install<br />
#cd ~/install<br />
#wget http://www.modsecurity.org/download/modsecurity-apache_2.5.10.tar.gz<br />
# tar -xzvf modsecurity-apache_2.5.10.tar.gz<br />
# cd modsecurity-apache_2.5.10/rules<br />
# cp *.conf /etc/apache2/conf.d<br />
# cp base_rules /etc/apache2/conf.d/modsecurity<br />
# cp optional_rules /etc/apache2/conf.d<br />
# mkdir /etc/apache2/logs<br />
# apt-get install libapache-mod-security<br />
# a2enmod mod-security
</div>
<li>Restart Apache:</li>
<div class="code">
# /etc/init.d/apache2 restart
</div>
</ol>
<p><strong>
<li>Configure password-protection on the PHPMyAdmin directory</li>
<p></strong></p>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li>Enter the following commands at the Linux prompt:</li>
<div class="code">
# mkdir /usr/local/apache2<br />
# htdigest -c /usr/local/apache2/.htpasswd_phpmyadmin &#8220;PHPMyAdmin&#8221; phpmyadmin<br />
(Enter password)<br />
# cp /etc/apache2/mods-available/auth_digest.load /etc/apache2/mods-enabled<br />
# nano /etc/apache2/apache2.conf
</div>
</li>
<li>Add the following text to the end of the apache2.conf file:</li>
<div class="code">
&lt;Directory /usr/share/phpmyadmin/&gt;<br />
&nbsp;&nbsp;Authtype digest<br />
&nbsp;&nbsp;AuthName &#8220;PHPMyAdmin&#8221;<br />
&nbsp;&nbsp;AuthUserFile /usr/local/apache2/.htpasswd_phpmyadmin<br />
&nbsp;&nbsp;require user phpmyadmin<br />
&lt;/Directory&gt;
</div>
<li>For added security, insert the following lines inside the &lt;Directory&gt; tag above to only allow connections from certain IP addresses:</li>
<div class="code">
&nbsp;&nbsp;Order deny,allow<br />
&nbsp;&nbsp;Deny from all<br />
&nbsp;&nbsp;Allow from &lt;static IP address&gt;
</div>
<li>Restart Apache:</li>
<div class="code">
# /etc/init.d/apache2 restart
</div>
</ol>
<p><strong>
<li>Configure password-protection on the WordPress Admin directory</li>
<p></strong></p>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li>Enter the following commands at the Linux prompt:</li>
<div class="code">
# mkdir /usr/local/apache2<br />
# htdigest -c /usr/local/apache2/.htpasswd_wp-admin &#8220;WordPress Admin&#8221; wp-admin<br />
(Enter password)<br />
# cp /etc/apache2/mods-available/auth_digest.load /etc/apache2/mods-enabled<br />
# nano /etc/apache2/apache2.conf
</div>
</li>
<li>Add the following text to the end of the apache2.conf file:</li>
<div class="code">
&lt;Directory /var/www/blog/wp-admin/&gt;<br />
&nbsp;&nbsp;Authtype digest<br />
&nbsp;&nbsp;AuthName &#8220;WordPress Admin&#8221;<br />
&nbsp;&nbsp;AuthUserFile /usr/local/apache2/.htpasswd_wp-admin<br />
&nbsp;&nbsp;require user wp-admin<br />
&lt;/Directory&gt;
</div>
<li>For added security, insert the following lines inside the &lt;Directory&gt; tag above to only allow connections from certain IP addresses:</li>
<div class="code">
&nbsp;&nbsp;Order deny,allow<br />
&nbsp;&nbsp;Deny from all<br />
&nbsp;&nbsp;Allow from &lt;static IP address&gt;
</div>
<li>Restart Apache:</li>
<div class="code">
# /etc/init.d/apache2 restart
</div>
</ol>
<p><strong>
<li>Configure password-protection on the Webalizer directory</li>
<p></strong></p>
<ol type="i">
<li>Connect to the EC2 instance using Putty.</li>
<li>Enter the following commands at the Linux prompt:</li>
<div class="code">
# mkdir /usr/local/apache2<br />
# htdigest -c /usr/local/apache2/.htpasswd_webalizer &#8220;Webalizer Stats&#8221; webalizer<br />
(Enter password)<br />
# cp /etc/apache2/mods-available/auth_digest.load /etc/apache2/mods-enabled<br />
# nano /etc/apache2/apache2.conf
</div>
</li>
<li>Add the following text to the end of the apache2.conf file:</li>
<div class="code">
&lt;Directory /var/www/webalizer/&gt;<br />
&nbsp;&nbsp;Authtype digest<br />
&nbsp;&nbsp;AuthName &#8220;Webalizer Stats&#8221;<br />
&nbsp;&nbsp;AuthUserFile /usr/local/apache2/.htpasswd_webalizer<br />
&nbsp;&nbsp;require user webalizer<br />
&lt;/Directory&gt;
</div>
<li>For added security, insert the following lines inside the &lt;Directory&gt; tag above to only allow connections from certain IP addresses:</li>
<div class="code">
&nbsp;&nbsp;Order deny,allow<br />
&nbsp;&nbsp;Deny from all<br />
&nbsp;&nbsp;Allow from &lt;static IP address&gt;
</div>
<li>Restart Apache:</li>
<div class="code">
# /etc/init.d/apache2 restart
</div>
</ol>
</ol>
<p>&nbsp;</p>
<h2 style="color:darkblue">IV. References</h2>
<p><strong>1. Amazon Web Services Technical Documentation</strong><br />
<a href="http://aws.amazon.com/documentation">http://aws.amazon.com/documentation</a></p>
<p><strong>2. Official Ubuntu Documentation</strong><br />
<a href="https://help.ubuntu.com">https://help.ubuntu.com</a></p>
<p><strong>3. RubyOnRails.org</strong><br />
<a href="http://rubyonrails.org/download/">http://rubyonrails.org/download/</a></p>
<p><strong>4. Python Programming Language &#8212; Official Website</strong><br />
<a href="http://www.python.org">http://www.python.org</a></p>
<p><strong>5. The Django Project</strong><br />
<a href="http://www.djangoproject.com/">http://www.djangoproject.com/</a></p>
<p><strong>6. Moving WordPress</strong><br />
<a href="http://codex.wordpress.org/Moving_WordPress">http://codex.wordpress.org/Moving_WordPress</a></p>
<p><strong>7. easyDNS</strong><br />
<a href="http://www.easydns.com">http://www.easydns.com</a></p>
<p><strong>8. OWASP ModSecurity Core Rule Set Project</strong><br />
<a href="http://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project">http://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project</a></p>
<p></br><br /></br></p>
]]></content:encoded>
			<wfw:commentRss>http://www.RayAcayan.com/projects/the-amazon-ec2-blog-migration-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

