<?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>Abhi&#039;s Weblog &#187; Ubuntu</title>
	<atom:link href="http://abhinavsingh.com/blog/tag/ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>http://abhinavsingh.com/blog</link>
	<description>PHP, Memcached, XMPP and Web Development</description>
	<lastBuildDate>Wed, 06 Apr 2011 22:19:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu</title>
		<link>http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/</link>
		<comments>http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 13:38:04 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[XCache]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/?p=592</guid>
		<description><![CDATA[Recently, because of a mandatory VPS move I had an opportunity to migrate all my sites from apache to nginx. My old box was in a messy state and setting up a new box from scratch was always going to be fun. Here in this post, I will walk you through all the steps that [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2010%2F04%2Fsetting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2010%2F04%2Fsetting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=nginx,PHP,Ubuntu,XCache&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently, because of a mandatory VPS move I had an opportunity to migrate all my sites from apache to nginx. My old box was in a messy state and setting up a new box from scratch was always going to be fun. Here in this post, I will walk you through all the steps that helped me migrate seamlessly. Specially, how did I setup the new box ensuring zero downtime on the sites.</p>
<p><strong style="font-size:18px;"><u>Ensuring zero downtime while migration:</u></strong><br />
By the time I will pin up various pieces on my new vps box, I didn&#8217;t want my site visitors to see an under-maintenance page. To ensure zero downtime, I usually follow these steps:</p>
<ul>
<li>Setup the new vps with nginx, php-fastcgi, etc as described later in the post</li>
<li>To verify the setup on new vps, edit the local host file depending upon your operating system
<pre class="php" name="code">/private/etc/hosts (mac)
/etc/hosts (ubuntu)
C:\Windows\System32\drivers\etc\hosts (windows)
</pre>
<p>Go ahead and add the following host entry:</p>
<pre class="php" name="code">99.198.122.216 abhinavsingh.com</pre>
<p>where, 99.198.122.216 is my new vps ip address and abhinavsingh.com is a vhost configured to handle by nginx on my new vps</li>
<li>Now, whenever I visit http://abhinavsingh.com in my browser, my local machine will point it to my new vps box. However, all other visitors will still be served by apache on old vps.</li>
<li>After verifying the setup, I simply remove previously added host setting on my local box and update the DNS settings for my site at godaddy.</li>
</ul>
<p>To start with, just add up the required host setting on your local system.</p>
<p><strong style="font-size:18px;"><u>Installing Nginx and configuring vhosts:</u></strong><br />
Follow these steps to install nginx webserver:</p>
<ul>
<li>Update and upgrade apt-get and install nginx
<pre class="php" name="code">sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx</pre>
</li>
<li>Configure vhost for nginx by creating a file <code>/etc/nginx/sites-available/mysite.com</code> as follows:
<pre class="php" name="code">server {
        listen   80;
        server_name  mysite.com;
        access_log  /var/log/nginx/mysite.access.log;

        root   /var/www/mysite;
        index  index.php index.html index.htm;

        location / {
        }
}</pre>
</li>
<li>Enable vhost by creating a symlink as follows:
<pre class="php" name="code">cd /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/mysite.com mysite.com
sudo /etc/init.d/nginx restart</pre>
</li>
<li>Assuming you have configured your local host file correctly, try visiting http://mysite.com and your browser will take it to the new vps</li>
</ul>
<p><strong style="font-size:18px;"><u>Setting up php-fastcgi and xcache:</u></strong><br />
Here are the steps to configure php-fastcgi and how to ensure php-fastcgi is up and running even after system reboot. We will also configure xcache for better performance.</p>
<ul>
<li>sudo apt-get install php5-cgi php5-cli php5-xcache</li>
<li>Download <a href="http://gist.github.com/383557">php-fastcgi default config</a> and place it at <code>/etc/default/php-fastcgi</code></li>
<li>Download <a href="http://gist.github.com/383550">php-fastcgi init.d script</a> and place it at <code>/etc/init.d/php-fastcgi</code></li>
<li>Add php-fastcgi init.d as startup script
<pre class="php" name="code">update-rc.d -f php-fastcgi defaults</pre>
</li>
<li>Update following fields inside <code>/etc/php5/conf.d/xcache.ini</code>:
<pre class="php" name="code">xcache.admin.user = "admin"
xcache.admin.pass = "pass"
xcache.size  =  128M
xcache.count = 4</pre>
<p> xcache.count should ideally be equal to <code>cat /proc/cpuinfo |grep -c processor</code></li>
<li>Setup xcache admin interface:
<pre class="php" name="code">cd /var/www
ln -s /usr/share/xcache/admin xcache</pre>
</li>
<li>Update <code>/etc/php5/cgi/php.ini</code> as per your requirements and start php-fastcgi process
<pre class="php" name="code">sudo /etc/init.d/php-fastcgi start</pre>
</li>
<li>Visit xcache admin panel http://vps_ip_address/xcache</li>
</ul>
<p><strong style="font-size:18px"><u>Stitching php-fastcgi and nginx vhosts:</u></strong><br />
Now lets enable php for vhosts configured with nginx:</p>
<ul>
<li>Download <a href="http://gist.github.com/383588">nginx fastcgi param</a> config file and place it at <code>/etc/nginx/fastcgi.conf</code></li>
<li>Update /etc/nginx/sites-available/mysite.com with following config:
<pre class="php" name="code">location ~ \.php$ {
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME /var/www/mysite$fastcgi_script_name;
                include         /etc/nginx/fastcgi.conf;
        }
</pre>
</li>
<li>Restart nginx and we are done</li>
</ul>
<p>Here we complete the vps setup and vhost configurations. Verify the new vps setup and once satisfied update site&#8217;s DNS settings. Another challenge involving migration from apache to nginx includes rewriting apache .htaccess rewrite rules for nginx. However, I will keep that for another post.</p>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2010%2F04%2Fsetting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu%2F","http:\/\/gist.github.com\/383557","http:\/\/gist.github.com\/383550","http:\/\/gist.github.com\/383588"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDEwLzA0L3NldHRpbmctbmdpbngtcGhwLWZhc3RjZ2ktYW5kLXhjYWNoZS1vbi1hLW5ldy11YnVudHUvPHdwdGI%2BU2V0dGluZyBOZ2lueCwgUEhQIEZhc3RjZ2kgYW5kIFhDYWNoZSBvbiBhIG5ldyBVYnVudHU8d3B0Yj5odHRwOi8vYWJoaW5hdnNpbmdoLmNvbS9ibG9nPHdwdGI%2BQWJoaSYjMDM5O3MgV2VibG9n";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/" title="Memcached and &quot;N&quot; things you can do with it &#8211; Part 1">Memcached and &quot;N&quot; things you can do with it &#8211; Part 1</a> (19)</li><li><a href="http://abhinavsingh.com/blog/2008/07/how-to-get-started-with-web-development/" title="How to get started with web development?">How to get started with web development?</a> (9)</li><li><a href="http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/" title="How to configure Ubuntu and LAMP on Windows">How to configure Ubuntu and LAMP on Windows</a> (4)</li><li><a href="http://abhinavsingh.com/blog/2010/08/php-code-setup-and-demo-of-jaxl-boshchat-application/" title="PHP Code, Setup and Demo of Jaxl boshchat application">PHP Code, Setup and Demo of Jaxl boshchat application</a> (80)</li><li><a href="http://abhinavsingh.com/blog/2010/08/releasing-jaxl-2-0-object-oriented-xmpp-framework-in-php/" title="Releasing Jaxl 2.0 &#8211; Object oriented XMPP framework in PHP">Releasing Jaxl 2.0 &#8211; Object oriented XMPP framework in PHP</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Setting up ejabberd 2.1.x development environment on Ubuntu</title>
		<link>http://abhinavsingh.com/blog/2010/03/setting-up-ejabberd-2-1-x-development-environment-on-ubuntu/</link>
		<comments>http://abhinavsingh.com/blog/2010/03/setting-up-ejabberd-2-1-x-development-environment-on-ubuntu/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 21:04:13 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[XMPP]]></category>
		<category><![CDATA[ejabberd]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/?p=587</guid>
		<description><![CDATA[apt-get provide a convenient way of installing ejabberd on Ubuntu distributions. However, if you are an erlang developer and looking to write custom ejabberd modules, you might want to install ejabberd from the source code. Checkout ejabberd source To start with lets grab the ejabberd 2.1.x branch source code: sudo apt-get install git-core git clone [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2010%2F03%2Fsetting-up-ejabberd-2-1-x-development-environment-on-ubuntu%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2010%2F03%2Fsetting-up-ejabberd-2-1-x-development-environment-on-ubuntu%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=ejabberd,Ubuntu,XMPP&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><code>apt-get</code> provide a convenient way of installing <code>ejabberd</code> on <code>Ubuntu</code> distributions. However, if you are an <code>erlang</code> developer and looking to write custom ejabberd modules, you might want to install ejabberd from the source code.</p>
<p><strong style="font-size:18px;"><u>Checkout ejabberd source</u></strong><br />
To start with lets grab the ejabberd 2.1.x branch source code:</p>
<ul>
<li>sudo apt-get install git-core</li>
<li>git clone git://git.process-one.net/ejabberd/mainline.git ejabberd</li>
<li>cd ejabberd</li>
<li>git checkout -b 2.1.x origin/2.1.x</li>
<li>cd src</li>
</ul>
<p><strong style="font-size:18px;"><u>Installing pre-requisites</u></strong><br />
Lets setup necessary pre-requisites before compiling ejabberd source code:</p>
<ul>
<li>sudo apt-get install build-essential</li>
<li>sudo apt-get install automake autoconf</li>
<li>sudo apt-get install erlang erlang-manpages</li>
<li>sudo apt-get install libexpat1-dev zlib1g-dev libssl-dev</li>
</ul>
<p><strong style="font-size:18px;"><u>Compiling ejabberd source code</u></strong><br />
Compiling and installing is dead simple:</p>
<ul>
<li>./configure</li>
<li>make</li>
<li>sudo make install</li>
</ul>
<p><strong style="font-size:18px;"><u>Setting up administration account</u></strong><br />
By now we have ejabberd server setup on our ubuntu box. Lets setup the admin account:</p>
<ul>
<li>sudo ejabberdctl start</li>
<li>sudo ejabberdctl register admin localhost password</li>
<li>sudo vim /etc/ejabberd/ejabberd.cfg</li>
<li>Add following configurations if not already present:
<pre name="code" class="php">{acl, admin, {user, "admin", "localhost"}}.
{loglevel, 5}. %% Log level while development</pre>
</li>
<li>sudo ejabberdctl restart</li>
<li>Visit ejabberd admin panel: http://localhost:5280/admin</li>
<li>When prompted enter username as <code>admin@localhost</code> and the password you chose above while registering admin account</li>
</ul>
<p><strong style="font-size:18px;"><u>Resolving startup errors</u></strong><br />
You might see a few error reports in logs or elsewhere while starting ejabberd server:</p>
<ul>
<li>
<pre class="php" name="code">/sbin/ejabberdctl: 340: cannot create //var/lock/ejabberdctl/ejabberdctl-1: Directory nonexistent</pre>
</li>
<li>
<pre class="php" name="code">=ERROR REPORT==== 2010-03-29 21:53:03 ===
C(<0.995.0>:ejabberd_captcha:331) : The option captcha_cmd is not configured, but some module wants to use the CAPTCHA feature.</pre>
</li>
<li>
<pre class="php" name="code">=INFO REPORT==== 2010-03-29 21:53:03 ===
I(<0.780.0>:ejabberd_rdbms:37) : ejabberd has not been compiled with relational database support. Skipping database startup.</pre>
</li>
</ul>
<p>Here is how you can resolve the above errors:</p>
<ul>
<li>sudo mkdir /var/lock/ejabberdctl/ejabberdctl-1</li>
<li>Add following line in <code>ejabberd.cfg</code>
<pre class="php" name="code">{captcha_cmd, "/lib/ejabberd/priv/bin/captcha.sh"}.</pre>
<p> Replace <code>/lib/ejabberd/priv/bin/captcha.sh</code> with path to <code>/ejabberd/tools/captcha.sh</code></li>
</ul>
<p><strong style="font-size:18px;"><u>Getting started with ejabberd development</u></strong><br />
Below are links to a few useful resources to get you started with erlang and ejabberd module development:</p>
<ul>
<li>Erlang programming rules and conventions: <a href="http://www.erlang.se/doc/programming_rules.shtml">http://www.erlang.se/doc/programming_rules.shtml</a></li>
<li>Erlang documentation: <a href="http://www.erlang.org/doc">http://www.erlang.org/doc</a></li>
<li>Ejabberd module development wiki: <a href="http://www.process-one.net/en/wiki/ejabberd_module_development">http://www.process-one.net/en/wiki/ejabberd_module_development</a></li>
<li>Ejabberd documentation: <a href="https://support.process-one.net/doc/display/MESSENGER/ejabberd">https://support.process-one.net/doc/display/MESSENGER/ejabberd</a></li>
</ul>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2010%2F03%2Fsetting-up-ejabberd-2-1-x-development-environment-on-ubuntu%2F","http:\/\/www.erlang.se\/doc\/programming_rules.shtml","http:\/\/www.erlang.org\/doc","http:\/\/www.process-one.net\/en\/wiki\/ejabberd_module_development","https:\/\/support.process-one.net\/doc\/display\/MESSENGER\/ejabberd"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDEwLzAzL3NldHRpbmctdXAtZWphYmJlcmQtMi0xLXgtZGV2ZWxvcG1lbnQtZW52aXJvbm1lbnQtb24tdWJ1bnR1Lzx3cHRiPlNldHRpbmcgdXAgZWphYmJlcmQgMi4xLnggZGV2ZWxvcG1lbnQgZW52aXJvbm1lbnQgb24gVWJ1bnR1PHdwdGI%2BaHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZzx3cHRiPkFiaGkmIzAzOTtzIFdlYmxvZw%3D%3D";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2011/04/jaxl-library-list-of-available-hooks-for-various-xmpp-events/" title="JAXL library &#8211; List of available hooks for various XMPP events">JAXL library &#8211; List of available hooks for various XMPP events</a> (3)</li><li><a href="http://abhinavsingh.com/blog/2010/08/php-code-setup-and-demo-of-jaxl-boshchat-application/" title="PHP Code, Setup and Demo of Jaxl boshchat application">PHP Code, Setup and Demo of Jaxl boshchat application</a> (80)</li><li><a href="http://abhinavsingh.com/blog/2010/08/releasing-jaxl-2-0-object-oriented-xmpp-framework-in-php/" title="Releasing Jaxl 2.0 &#8211; Object oriented XMPP framework in PHP">Releasing Jaxl 2.0 &#8211; Object oriented XMPP framework in PHP</a> (6)</li><li><a href="http://abhinavsingh.com/blog/2010/07/introducing-wp-chat-xmpp-chat-plugin-for-wordpress/" title="Introducing WP-Chat :: XMPP Chat plugin for Wordpress">Introducing WP-Chat :: XMPP Chat plugin for Wordpress</a> (46)</li><li><a href="http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/" title="Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu">Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2010/03/setting-up-ejabberd-2-1-x-development-environment-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Memcached and &quot;N&quot; things you can do with it &#8211; Part 1</title>
		<link>http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/</link>
		<comments>http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 09:36:11 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Memcache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/?p=186</guid>
		<description><![CDATA[In my last post MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose, I discussed in brief about 4 caching technologies which you might have used knowingly or unknowingly. Towards the end we came to a conclusion that memcached is the best caching solution when you are looking for speed and number of hits [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2009%2F01%2Fmemcached-and-n-things-you-can-do-with-it%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2009%2F01%2Fmemcached-and-n-things-you-can-do-with-it%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=Debian,Facebook,Memcache,PHP,Ubuntu,Windows&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In my last post <a target="_blank" href="http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/">MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose</a>, I discussed in brief about 4 caching technologies which you might have used knowingly or unknowingly.</p>
<p>Towards the end we came to a conclusion that memcached is the best caching solution when you are looking for speed and number of hits per second. By my experience, memcached is capable of handling more than a 100 Million PV&#8217;s per month without any problem. However, towards the end I did also discussed why memcached is unreliable and unsecure.</p>
<p>In this post I will dig a level deeper into memcached. For ease here is the so called table of content:</p>
<ol>
<li><strong>Basics:</strong> Memcached &#8211; Revisited</li>
<li><strong>Code Sample:</strong> A memcached class and how to use it</li>
<li><strong>N things:</strong> What else can I do with memcached</li>
<li><strong>Case Study:</strong> How Facebook uses memcached</li>
<li><strong>DONT&#8217;s:</strong> A few things to be taken care</li>
</ol>
<p><strong style="font-size:18px;"><u>Basics: Memcached &#8211; Revisited</u></strong><br />
Memcached was developed by <a target="_blank" href="http://bradfitz.com/">Brad</a> when live journal was hitting more than 20 Million PV&#8217;s per day. Handling 20 Million PV&#8217;s was no joke and he needed a better solution to handle such a high traffic. Since most of the blogs doesn&#8217;t change once published, he thought of having a model where he can skip the database read for the same posts again and again or atleast reduce the number of database reads. And hence came Memcached. Memcached is a deamon which runs in the background. By deamon you may think of a process running in the background doing its job.</p>
<p>If you are using ubuntu or debian like me, here are the steps for installing memcached:</p>
<ol>
<li>sudo apt-get install php5-memcache</li>
<li>Go to <em>/etc/php5/conf.d/memcache.ini</em> and uncomment the line <em>;extension=memcache.so</em> to enable this module</li>
<li>sudo pecl install memcache</li>
<li>Go to php.ini file and add this line: <em>extension=memcache.so</em></li>
<li>sudo apt-get install memcached</li>
<li>sudo /etc/init.d/memcached start</li>
<li>Restart Apache</li>
</ol>
<p>If you are on windows, here are the steps which will help you running memcached on windows machine:</p>
<ol>
<li>Download the memcached win32 binary from my <a href="http://code.google.com/p/abhinavsingh/source/browse/trunk/Memcached/memcache-1.2.5/memcached-1.2.5-win32-bin.zip" target="_blank">code.google</a> vault.</li>
<li>Unzip the downloaded file under <em>C:\memcached</em></li>
<li>As we need to install memcached as a service, run this from a command line: <em>C:\memcached\memcached.exe -d install</em> from the command line</li>
<li>Memcache by default loads with 64Mb of memory which is just not sufficient enough. Navigate to <em>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server</em> in your registry and find the ImagePath entry. Change that to <em>&#8220;C:\memcached\memcached.exe&#8221; -d runservice -m 512</em></li>
<li>Start the server by running this command: <em>C:\memcached\memcached.exe -d start</em></li>
<li>Open folder C:\PHP\ext and check for <em>php_memcache.dll</em>. If you are unlucky not to have that download from <a href="http://code.google.com/p/abhinavsingh/source/browse/trunk/Memcached/dlls/php-4.x/php_memcache.dll" target="_blank">here for PHP-4.x</a> and from <a href="http://code.google.com/p/abhinavsingh/source/browse/trunk/Memcached/dlls/php-5.x/php_memcache.dll" target="_blank">here for PHP-5.x</a></li>
<li>Add <em>extension=php_memcache.dll</em> in your php.ini file</li>
<li>Restart Apache</li>
<li>Download the <a target="_blank" href="http://abhinavsingh.googlecode.com/files/svn-trunk-Memcached.rar">full package</a> consisting of exe&#8217;s, classes and dll&#8217;s from here.</li>
</ol>
<p>A few other options which you can use for starting memcached are:<br />
<em>memcached -d -m 2048 -l 10.0.0.40 -p 11211</em> , This will start memcached as a daemon, using 2GB of memory, and listening on IP 10.0.0.40, port 11211. Port 11211 is the default port for memcached.</p>
<p>By now I assume you have a <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  on your face, because you have memcached deamon running on your machine. Windows users can check that by opening up the task manager and looking for a memcached.exe process. I don&#8217;t see any reason for you not smiling, but if in case you are that unlucky windows user, please leave that system and move to a unix machine. Atleast try running Ubuntu on windows by reading this post of mine <a target="_blank" href="http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/">How to configure Ubuntu and LAMP on Windows</a>.</p>
<p><strong style="font-size:18px;"><u>Code Sample: Memcached class</u></strong><br />
So we have memcached setup on our system. Now we will try to hook up a simple code with it, which will do all the necessary talking with the deamon. Below I will demonstrate a very basic and simple application which will help you getting started. This application contains a total of 5 files namely: database.class.php, memcache.class.php, log.class.php, index.php, memcacheExtendedStats.php.</p>
<p><strong>log.class.php</strong><br />
This is a very basic logger class which will log every thing for you to inspect later. Here is the code:</p>
<pre name="code" class="php">
  class logAPI {
    var $LogFile = "log.txt";

    function Logger($Log) {
      $fh = fopen($this->LogFile,"a");
      fwrite($fh,$Log);
      fclose($fh);
    }
  }
</pre>
<p>When ever the code connects with memcached deamon, or database or fail to connect to either of them , this class will log the appropriate message in <em>log.txt</em></p>
<p><strong>database.class.php</strong><br />
This is another basic database class which have methods like <em>getData()</em> and <em>setData()</em>. <em>getData()</em> is used while trying to retrieve rows from the database while <em>setData()</em> is used while updating or inserting new rows in the database. For this demo application we will only be using the <em>getData()</em> method. Here is the code:</p>
<pre name="code" class="php">
  include_once("memcache.class.php");
  include_once("log.class.php");

  class databaseAPI {

    /************************/
    /** Database information **/
    /************************/
    var $dbhost = "localhost";
    var $dbuser = "root";
    var $dbpass = "";
    var $dbname = "gtalkbots";
    var $db = NULL;

    /******************************/
    // CONSTRUCTOR DEFINITION //
    /******************************/
    function __construct() {
      $this->connect();
    }

    /*************************************************/
    // Function establishes a connection to database //
    /*************************************************/
    function connect() {
      // Connect to the dbhost
      $connection = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die(mysql_error());

	  // If connection fails send a mail to $dbmail about the same
      if(!$connection) {
        echo "Failed to establish a connection to host";
        exit;
      }
      else {
        // Connect to dbname
        $database = @mysql_select_db($this->dbname);

	// If fails to connect to the database send a mail to $dbmail
        if(!$database) {
          echo "Failed to establish a connection to database";
          exit;
        }
        else {
          $this->db = $connection;
        }
      }
    }

    /*******************************************/
    // Function closes the database connection //
    /*******************************************/
    function close() {
      mysql_close($this->db);
    }

    /***********************************************************/
    // Function executes the query against database and returns the result set   //
    // Result returned is in associative array format, and then frees the result //
    /***********************************************************/
    function getData($query,$options=array("type"=>"array","cache"=>"on"),$resultset="") {
        // Lookup on memcache servers if cache is on
	if($options['cache'] == "on") {
	    $obj = new memcacheAPI();
	    if($obj->connect()) {
	        // Try to fetch from memcache server if present
		$resultset = $obj->getCache($query);
	    }
    	    else {
	        // Fetch query from the database directly
	    }
	}
	// If $resultset == "" i.e. either caching is off or memcache server is down
        // OR $resultset == null i.e. when $query is not cached
	if($resultset == "" || $resultset == null) {
	    $result = mysql_query($query,$this->db);
	    if($result) {
		if($options['type'] == "original") {
		    // Return the original result set, if passed options request for the same
		    $resultset = $result;
		}
                else if($options['type'] == "array") {
	            // Return the associative array and number of rows
	    	    $mysql_num_rows = mysql_num_rows($result);
		    $result_arr = array();
		    while($info = mysql_fetch_assoc($result)) {
		        array_push($result_arr,$info);
		    }
		    $resultset = array("mysql_num_rows" => $mysql_num_rows,"result" => $result_arr,"false_query" => "no");
		}
  		// Cache the $query and $resultset
		$obj->setCache($query,$resultset);
		$obj->close();
		return $resultset;

                // Free the memory
		mysql_free_result($result);
            }
            else {
	        $resultset = array("false_query" => "yes");
	        return $resultset;
            }
	}
	else {
	    // If $query was found in the cache, simple return it
	    $obj->close();
	    return $resultset;
	}
    }

    /**********************************************************/
    // Function executes the query against database (INSERT, UPDATE) types   //
    /************************************************************/
    function setData($query) {
      // Run the query
      $result = mysql_query($query,$this->db);
      // Return the result
      return array('result'=>$result,'mysql_affected_rows'=>mysql_affected_rows());
    }

  }
</pre>
<p><strong>memcache.class.php</strong><br />
Memcache class consists of two methods: getCache() and setCache(). getCache() will look up for the (key,value) pair in memory. If it exists, the method unserialize it and returns back. setCache() is used to set (key,value) pair in memory. It accepts the key and value, serialize the value before storing in cache.</p>
<pre name="code" class="php">
  class memcacheAPI {

	/* Define the class constructor */
	function __construct() {
	  $this->connection = new Memcache;
	  $this->log = new logAPI();
	  $this->date = date('Y-m-d H:i:s');
	  $this->log->Logger("[[".$this->date."]] "."New Instance Created<br/>\n");
	}

	/*  connect() connects to the Memcache Server  */
	/* returns TRUE if connection established */
	/* returns FALSE if connection failed */
	function connect() {
	  $memHost = "localhost";
	  $memPort = 11211;
	  if($this->connection->connect($memHost,$memPort)) {
	    $this->log->Logger("[[".$this->date."]] "."Connection established with memcache server<br/>\n");
		return TRUE;
	  }
	  else {
	    $this->log->Logger("[[".$this->date."]] "."Connection failed to establish with memcache server<br/>\n");
	    return FALSE;
	  }
	}

	/* close() will disconnet from Memcache Server */
	function close() {
	  if($this->connection->close()) {
	    $this->log->Logger("[[".$this->date."]] "."Connection closed with memcache server<br/>\n");
	    $this->log->Logger("=================================================================================================<br/>\n\n");
	    return TRUE;
	  }
	  else {
	    $this->log->Logger("[[".$this->date."]] "."Connection didn't close with memcache server<br/>\n");
		$this->log->Logger("=======================================================================================================<br/>\n\n");
	    return FALSE;
	  }
	}

	/* getCache() function will fetch the passed $query resultset from cache */
	/* returned resultset is null if $query not found in cache */
	function getCache($query) {
	  /* Generate the key corresponding to query */
	  $key = base64_encode($query);

	  /* Get the resultset from cache */
	  $resultset = $this->connection->get($key);

	  /* Unserialize the result if found in cache */
	  if($resultset != null) {
	    $this->log->Logger("[[".$this->date."]] "."Query ".$query." was found already cached<br/>\n");
	    $resultset = unserialize($resultset);
	  }
	  else {
	    $this->log->Logger("[[".$this->date."]] "."Query ".$query." was not found cached in memcache server<br/>\n");
	  }
	  return $resultset;
	}

	/* setCache() function will set the serialized resultset on Memcache Server */
	function setCache($query,$resultset,$useCompression=0,$ttl=600) {
	  /* Generate the key corresponding to query */
	  $key = base64_encode($query);

	  /* Set the value on Memcache Server */
	  $resultset = serialize($resultset);
	  if($this->connection->set($key,$resultset,$useCompression,$ttl)) {
	    $this->log->Logger("[[".$this->date."]] "."Query ".$query." was cached<br/>\n");
		return TRUE;
	  }
	  else {
	    $this->log->Logger("[[".$this->date."]] "."Query ".$query." was not able to cache<br/>\n");
		return FALSE;
	  }
	}

  }
</pre>
<p><strong>index.php</strong><br />
With everything in place, its time to test memcached. We will check if memcached is working fine by running this code file twice one by one. Open command line and point to this code. Run from command line: <em>php index.php</em> . Then again run from command line <em>php index.php</em>.</p>
<pre name="code" class="php">
  include_once("database.class.php");
  $mdb = new databaseAPI();

  $query = "SELECT * from status LIMIT 0,1000";
  $resultset = $mdb->getData($query);
  $mdb->close();

  echo "
<pre>";
  print_r($resultset);
  echo "</pre>
<p>";
</pre>
<p>If everything is working fine, you will see a log.txt file being generated which will look as follows.</p>
<p><strong>log.txt</strong></p>
<pre name="code" class="php">
[[2009-01-18 09:52:57]] New Instance Created<br/>
[[2009-01-18 09:52:57]] Connection established with memcache server<br/>
[[2009-01-18 09:52:57]] Query SELECT * from status LIMIT 0,1000 was not found cached in memcache server<br/>
[[2009-01-18 09:52:57]] Query SELECT * from status LIMIT 0,1000 was cached<br/>
[[2009-01-18 09:52:57]] Connection closed with memcache server<br/>
=================================================================================================<br/>

[[2009-01-18 09:53:08]] New Instance Created<br/>
[[2009-01-18 09:53:08]] Connection established with memcache server<br/>
[[2009-01-18 09:53:08]] Query SELECT * from status LIMIT 0,1000 was found already cached<br/>
[[2009-01-18 09:53:08]] Connection closed with memcache server<br/>
=================================================================================================<br/>
</pre>
<p>From the log file we can see that the 1st time results were fetched from the database and for the second time from memcached <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Before we proceed further lets explain the flow of the above scripts. In <em>index.php</em> we create a new instance of <em>database.class.php</em> $mdb. Then we try to $query for 100 rows from the database. $mdb->getData($query) initiates this database fetch. As the program control goes to getData() method of <em>database.class.php</em>, it passed the control to getCache() method of <em>memcache.class.php</em>. There the code create a $key = base64_encode($query) and checks if we have the result set cached in memcached. If it doesn&#8217;t exists, it passed control back to getData() of database.class.php which fetches it from the database. After the fetch, it passes the $resultset back to setCache() method of memcache.class.php. There the setCache() method serialize the $resultset and cache it as ($key,$value) = (base64_encode($query), serialize($resultset)) in memcache.</p>
<p>Next time when the same query is fired and control goes to getCache() method of <em>memcache.class.php</em>, it fetches the result from cache, unserialize it and returns back the result to getData() of <em>database.class.php</em>. And thats why you see a log similar to above.</p>
<p><strong>memcache.extendedstats.php</strong><br />
Finally it&#8217;s time to see some statistics. Here is a simple file which will show memcache status:</p>
<pre name="code" class="php">
  $memcache_obj = new Memcache;
  $memcache_obj->addServer('localhost', 11211);

  $stats = $memcache_obj->getExtendedStats();

  echo "
<pre>";
  print_r($stats);
  echo "</pre>
<p>";
</pre>
<p>Running it from command line using: <em>php memcache.extendedstats.php</em> will give you a statistic array like this.</p>
<pre name="code" class="php">
Array
(
    [localhost:11211] => Array
        (
            [pid] => 5472
            [uptime] => 17
            [time] => 1232303504
            [version] => 1.2.5
            [pointer_size] => 32
            [curr_items] => 1
            [total_items] => 1
            [bytes] => 271631
            [curr_connections] => 2
            [total_connections] => 5
            [connection_structures] => 3
            [cmd_get] => 2
            [cmd_set] => 1
            [get_hits] => 1
            [get_misses] => 1
            [evictions] => 0
            [bytes_read] => 271705
            [bytes_written] => 271614
            [limit_maxbytes] => 536870912
            [threads] => 1
        )

)
</pre>
<p>This array tells you of a number of things about how your memcached deamon and caching architecture is performing. In short here is what each of the variable would mean:</p>
<ol>
<li><strong>pid:</strong> Process id of this server process</li>
<li><strong>uptime:</strong> Number of seconds this server has been running</li>
<li><strong>time:</strong> Current UNIX time according to the server</li>
<li><strong>version:</strong> Version string of this server</li>
<li><strong>rusage_user:</strong> Accumulated user time for this process</li>
<li><strong>rusage_system:</strong> Accumulated system time for this process</li>
<li><strong>curr_items:</strong> Current number of items stored by the server</li>
<li><strong>total_items:</strong> Total number of items stored by this server ever since it started</li>
<li><strong>bytes:</strong> Current number of bytes used by this server to store items</li>
<li><strong>curr_connections:</strong> Number of open connections</li>
<li><strong>total_connections:</strong> Total number of connections opened since the server started running</li>
<li><strong>connection_structures:</strong> Number of connection structures allocated by the server</li>
<li><strong>cmd_get:</strong> Cumulative number of retrieval requests</li>
<li><strong>cmd_set:</strong> Cumulative number of storage requests</li>
<li><strong>get_hits:</strong> Number of keys that have been requested and found present</li>
<li><strong>get_misses:</strong> Number of items that have been requested and not found</li>
<li><strong>bytes_read:</strong> Total number of bytes read by this server from network</li>
<li><strong>bytes_written:</strong> Total number of bytes sent by this server to network</li>
<li><strong>limit_maxbytes:</strong> Number of bytes this server is allowed to use for storage.</li>
</ol>
<p>However at this stage the figures which you might be interested in knowing are <em>get_hits</em> and <em>get_misses</em>. <em>get_misses</em> means number of times you requested for a key in memcache and it was not found while get_hits means number of times your requested key was successfully retrieved from memcached. Hence as expected we currently have <em>get_misses = 1</em> and <em>get_hits = 1</em>. Try running <em>php index.php</em> once more and <em>get_hits</em> will get incremented by one.</p>
<p><strong style="font-size:18px;"><u>N things: What else can I do</u></strong><br />
Till now you have memcached deamon running on your system and you know how to communicate with the deamon. You also know a very basic usage of memcached now, i.e. cache the queries to reduce load from your database. However there is a lot more you can do with memcached.</p>
<p>Here I would like to present before you a few applications of memcached which I learnt from my experiences. I hope they will be enough to make you think otherwise.</p>
<ol>
<li><strong><u>Restricting spammers on your site</u> :</strong> Often you will find on social networking sites like <em>Digg</em>, <em>Facebook</em> and <em>Orkut</em> that if you try to add several users as your friend within a short span, they (facebook) will show you a warning or they (digg) will restrict you from doing it. Similarly there are cases when you want to send a shout to more than 200 users on digg and you are restricted from doing so. How will you implement this on your site?
<p><strong style="color:#AA0000">Ordinary user&#8217;s solution:</strong> One solution is if a user &#8216;X&#8217; add another user &#8216;Y&#8217; as a friend, you will check how many friends has &#8216;X&#8217; added in the past 10 minutes. If that exceeds 20, you won&#8217;t allow him to add more friends or show him a warning message. Simple enough and will work coolly. But what if your site have more than a million users, with many hackers around the world trying to keep your servers busy. As a memcached user you must have following solution in your mind:</p>
<p><strong style="color:#0000AA">Your solution:</strong> As &#8216;X&#8217; adds &#8216;Y&#8217; in his friend list, you will set a (key,value) pair in memcached, where $key = &#8220;user_x&#8221; with $TTL = 10 minutes. For the first friend added, $value = 1. Now as &#8216;X&#8217; tries to add another friend, your simply increment $value for $key = &#8220;user_x&#8221;. As this $value equals 20, and &#8216;X&#8217; tried to add another friend, your code will check the value of $key = &#8220;user_x&#8221; and see if it&#8217;s present in memcached. If it&#8217;s present check for it&#8217;s value. If it&#8217;s value is equal to 20, you show a warning message to the user. Hence restricting him from adding more than 20 friends within a time span of 10 minutes. After 10 minutes, $key = &#8220;user_x&#8221; will automatically expires and your code will allow &#8216;X&#8217; to add more friends. Similar solution exists if you want to stop spammers from sending message or commenting over a limit on your site. Now I see confidence building in you as a memcached programmer <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  <br/><br/></li>
<li><strong><u>Detecting online active/inactive users</u> :</strong> Often you want a method which can tell your registered users, about their online friends. Or in a forum you want to tell the current reading user, about who all are reading this post. I won&#8217;t tell how an ordinary user will implement this, but as a memcached user your solution should be:
<p><strong style="color:#AA0000">Ordinary user&#8217;s solution:</strong> You don&#8217;t want to think of this.</p>
<p><strong style="color:#0000AA">Your solution:</strong> As user &#8216;X&#8217; visit post#12345 in the forum, not only you will fetch post data from the database, you also set two (key,value) pairs.</p>
<p>$key1 = &#8220;post_12345&#8243;<br />
$value1 = [[comma separated list of user names]]<br />
$TTL1 = [[some arbitrary large value is fine]]</p>
<p>$key2 = &#8220;user_x&#8221;<br />
$value2 = &#8220;post_12345&#8243;<br />
$TTL2 = 10 minutes, We assume a user to be inactive if he is on a particular post for more than 10 minutes (tunable), and we will mark him as inactive.</p>
<p>(key1,value1) is a post specific data while (key2,value2) is a user specific data. Now every time a user visits post#12345, you will do two things. Read all comma separated user names from $value1, and then check for their corresponding $key2 value. If corresponding $key2 exists and equals to $value2 = &#8220;post_12345&#8243;, i.e. on the same post and not idle, we will keep that user name in value of $key1. However if $key2 is not present (i.e. user gone away) or value of $key2 equals to some other post, we will remove his user name from $value1. Confused <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  , read twice and the picture will be clear.</p>
<p>Can you think of a better solution? Please let me and others know about it. (Remember we are trying to detect only active/inactive users, which is not same as online/offline users)<br/><br/></li>
<li><strong><u>Building scalable web services</u></strong> : Another application of memcached lies in building scalable web services and web widgets. <a href="http://gtalkbots.com" target="_blank">Gtalkbots</a> offer a cool widget which you can put on your blog and sites to show off your aggregated status messages. See this widget live in the right hand sidebar. While building this widget, one thing which I kept in mind was that, what if someone with million hits per day put my widget on his site. Even though, Gtalkbots gets a few thousand of hits per day, it will crash, mainly because of this particular widget being placed on a high traffic site. So as a memcached user I have done the following thing.
<p><strong style="color:#AA0000">Ordinary user&#8217;s solution:</strong> Deprecated</p>
<p><strong style="color:#0000AA">Your solution:</strong> I simply cache the widget data in memcache with $TTL = 1 hour. So every time this million hits per day site is accessed, which loads my widget million times a day, the query will be returned from cache. And hence saving my server from crashing. Fetch <a target="_blank" href="http://gtalkbots.com/dashboard/getwidgets">Gtalkbots widget</a> from here and try putting on your site.</li>
</ol>
<p>Alright by now you can impress your bosses with your cool memcache implementations. But wait there is a lot more you need to know. I can go on putting hundred&#8217;s of memcached applications here, but main point is, setting your mind as a memcached user. I personally have this habit of linking everything to memcached while designing a system, and if it suits my need, Bingo!.</p>
<ol>
<li><strong><u>Versioning your cache keys</u></strong> : One disadvantage of using cache at times is that, if unfortunately something goes wrong with your data and that buggy data is cached, your users will keep seeing that buggy data until your cache expires or you manually clear off your cache. Suppose you clear your cache and then one of your fucking engineer comes running saying the data is fine.
<p><strong style="color:#AA0000">Ordinary user&#8217;s solution:</strong> Stop it, No more plz</p>
<p><strong style="color:#0000AA">Your solution:</strong> As a memcached user, i would love to keep a Versioning system for my caches. Nothing complex, simply append <em>&#8220;v1&#8243;</em> (version number) to all your keys. i.e. $key = &#8220;user_x&#8221; will now become $key = &#8220;v1:user_x&#8221;. and at a place in your code you have <em>$current_cache_version = &#8220;v1&#8243;</em>. Now suppose you are told your data is buggy, so by the time your engineers are investigation change <em>$current_cache_version = &#8220;v2&#8243;</em>. This will keep your old caches, which you may want to recover after your investigation and at the same time show new data to your users.<br/><br/></li>
<li><strong><u>Not so frequent update of Db for trivial data</u></strong> : This is a site dependent application. Suppose you run a site where you are not so serious about database columns like &#8220;last_update_date&#8221;, &#8220;last_logged_in&#8221; and so on. However you still keep a track of such for analysis purpose and don&#8217;t mind if it&#8217;s not so accurate.
<p><strong style="color:#0000AA">Your solution:</strong> One simple solution to this problem is keep such trivial data in memcached and set up a cron job which will run every 10 minutes and populate such data in the database. <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<p>I will leave you with a presentation on memcache which I gave sometime back at office. I hope it will help you gain more understanding of memcache.</p>
<p><center></p>
<div style="width:425px;text-align:left" id="__ss_917157"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/imoracle/memcache-presentation?type=powerpoint" title="Memcache">Memcache</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=memcache-1231956637654098-1&#038;stripped_title=memcache-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=memcache-1231956637654098-1&#038;stripped_title=memcache-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/imoracle/memcache-presentation?type=powerpoint" title="View Memcache on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/caching">caching</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/memcache">memcache</a>)</div>
</div>
<p></center></p>
<p>I hope after reading this you are well equipped on how to design scalable systems. All the best! , do leave a comment or suggestions if any. If you liked this post, do subscribe for the next post in memcache series.</p>
<div id="paidTxtLinkAds">Check out our latest <a href="http://www.testking.org/70-642.htm">testking 70-642</a> dumps and <a href="http://www.testking.org/642-902.htm">testking 642-902</a> tutorials for php to get deep insight into new releases. PHP is easy to learn with our <a href="http://www.testking.org/220-701.htm">testking 220-701</a> training course.</div>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2009%2F01%2Fmemcached-and-n-things-you-can-do-with-it%2F","http:\/\/bradfitz.com\/","http:\/\/code.google.com\/p\/abhinavsingh\/source\/browse\/trunk\/Memcached\/memcache-1.2.5\/memcached-1.2.5-win32-bin.zip","http:\/\/code.google.com\/p\/abhinavsingh\/source\/browse\/trunk\/Memcached\/dlls\/php-4.x\/php_memcache.dll","http:\/\/code.google.com\/p\/abhinavsingh\/source\/browse\/trunk\/Memcached\/dlls\/php-5.x\/php_memcache.dll","http:\/\/abhinavsingh.googlecode.com\/files\/svn-trunk-Memcached.rar","http:\/\/gtalkbots.com","http:\/\/gtalkbots.com\/dashboard\/getwidgets","http:\/\/www.slideshare.net\/imoracle\/memcache-presentation?type=powerpoint","http:\/\/www.slideshare.net\/imoracle\/memcache-presentation?type=powerpoint","http:\/\/www.slideshare.net\/upload?type=powerpoint","http:\/\/slideshare.net\/tag\/caching","http:\/\/slideshare.net\/tag\/memcache","http:\/\/www.testking.org\/70-642.htm","http:\/\/www.testking.org\/642-902.htm","http:\/\/www.testking.org\/220-701.htm"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDA5LzAxL21lbWNhY2hlZC1hbmQtbi10aGluZ3MteW91LWNhbi1kby13aXRoLWl0Lzx3cHRiPk1lbWNhY2hlZCBhbmQgJnF1b3Q7TiZxdW90OyB0aGluZ3MgeW91IGNhbiBkbyB3aXRoIGl0ICYjODIxMTsgUGFydCAxPHdwdGI%2BaHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZzx3cHRiPkFiaGkmIzAzOTtzIFdlYmxvZw%3D%3D";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/" title="How to configure Ubuntu and LAMP on Windows">How to configure Ubuntu and LAMP on Windows</a> (4)</li><li><a href="http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/" title="Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu">Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu</a> (5)</li><li><a href="http://abhinavsingh.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/" title="Writing your first facebook chat bot in PHP using Jaxl library">Writing your first facebook chat bot in PHP using Jaxl library</a> (57)</li><li><a href="http://abhinavsingh.com/blog/2010/02/memq-fast-queue-implementation-using-memcached-and-php-only/" title="MEMQ : Fast queue implementation using Memcached and PHP only">MEMQ : Fast queue implementation using Memcached and PHP only</a> (17)</li><li><a href="http://abhinavsingh.com/blog/2010/01/wordpress-style-duplicate-comment-detected-using-memcached-and-php/" title="Wordpress style &quot;Duplicate comment detected&quot; using Memcached and PHP">Wordpress style &quot;Duplicate comment detected&quot; using Memcached and PHP</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>How to get started with web development?</title>
		<link>http://abhinavsingh.com/blog/2008/07/how-to-get-started-with-web-development/</link>
		<comments>http://abhinavsingh.com/blog/2008/07/how-to-get-started-with-web-development/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 12:57:49 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Altertunes]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CPanel]]></category>
		<category><![CDATA[Dedicated Server]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OpenLaszlo]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shared Hosting]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[WAMP]]></category>
		<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/2008/07/how-to-get-started-with-web-development/</guid>
		<description><![CDATA[Many of my friends have asked me on how to start with web development. I am not expert but here in this post I would like to describe a few steps that might help one climb the ladder of web development fast. Kindly feel free to add to this blog post if you think some [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F07%2Fhow-to-get-started-with-web-development%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F07%2Fhow-to-get-started-with-web-development%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=Altertunes,Apache,CPanel,Dedicated+Server,LAMP,MySQL,OpenLaszlo,Perl,PHP,Shared+Hosting,Ubuntu,VPS,WAMP,Web+Hosting&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Many of my friends have asked me on how to start with web development. I am not expert but here in this post I would like to describe a few steps that might help one climb the ladder of web development fast. Kindly feel free to add to this blog post if you think some other methodology might be better off.</p>
<ol>
<li><span style="font-weight: bold; color: rgb(51, 51, 255);"><span style="text-decoration: underline;">Where do I start web development?</span> </span><span style="color: rgb(0, 0, 0);">Well the first and best place to start web development is your own system. Yes your very own personal computer. You don&#8217;t need a server on internet to start with. Infact I worked locally on my computer for about a month before I went for free hostings, shared hosting and finally VPS. Once you feel that you are comfortable enough with the tid-bits of web development, then you can move to one of them.</span></li>
<li><span style="color: rgb(0, 0, 0);"><span style="font-weight: bold; text-decoration: underline; color: rgb(51, 51, 255);">How to configure my local computer for that?</span> You have a number of options to start with. I personally started on <a target="_blank" href="http://tomcat.apache.org/">Tomcat Server</a> after my initial training at Oracle. Tomcat is suited if you are starting with <a target="_blank" href="https://java.sun.com/products/jsp">JSP (Java Server/Servlet Pages)</a> . I started by making a few basic pages like creating a login/registration system. I made a few and then hosted on my office computer. Distributed the links to a few around to get the much needed boost. <span style="font-style: italic;">(Yes if you are into web development you need a lot of encouragement and appreciation from others, else your enthusiasm can soon die out). </span>However I soon realized that in todays world of web 2.0 Tomcat is not the thing. So I shifted to Apache.<span style="font-style: italic;">
<p></span>Next option you have is to go for Apache (which I use currently for all my developments). I have written 2 posts on how to configure your local system for the same. Read it here: <a target="_blank" href="http://abhinavsingh.com/blog/2008/05/web-development-part-1-apache-mysql-php/%20">Web Development Part 1 Apache MySQL PHP</a> . If you are interested in starting on a unix machine (which is always the best thing to do) here is the post where I described: <a target="_blank" href="http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/">How to configure Ubuntu and LAMP on Windows</a>.</p>
<p></span></li>
<li><span style="color: rgb(0, 0, 0);"><span style="font-weight: bold; text-decoration: underline; color: rgb(51, 51, 255);">Things to concentrate upon initially?</span><span style="font-weight: bold; color: rgb(51, 51, 255);"></span><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"> Before you go for any big big applications its better to get your basics right. I sucked for long while working with out dated styles and methodology. Here is a bunch of things which you should initially look to:
<ul>
<li>Choose the &lt;div&gt; style to create your HTML pages. I didn&#8217;t knew about this methodology and even went ahead to release <a target="_blank" href="http://altertunes.com">Altertunes</a> with &lt;table&gt; structure HTML pages.
</li>
<li>While looking around on internet you will find loads and lot of framework offerings. They really make your work sooo simple. Takes all the burden away from you. Solves all cross browser compatibility for your application and what not. Find a list of frameworks I have tried before here: <a target="_blank" href="http://abhinavsingh.com/blog/2008/05/essential-frameworks-for-web-development/">Essential Frameworks for web development</a>
</li>
<li>However one thing which you lose by using such frameworks is the insight. You never get to know what cross browser compatibility issues comes and how are they solved. They provide you easy ajax requests but you never get to know the methodology behind it. The biggest drawback which I find is that even for a simplest of application you always need to include whole bunch of files from framework hence making your application heavy for no reason.</li>
<li>Hence I finally went ahead coding everything from scratch and never ever used any framework for any of my works.</li>
<li>You need to learn how to prevent XSS (Cross browser scripting) and SQL Injection in your applications. Something very important for all your applications.</li>
</ul>
<p></span></span></span></li>
<li><span style="color: rgb(0, 0, 0);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="font-weight: bold; text-decoration: underline; color: rgb(51, 51, 255);">Getting to a free hosting server:</span><span style="font-weight: bold; color: rgb(51, 51, 255);"></span><span style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 0, 51);">After initial play at your PC, its time to get to a free hosting server which brings in more knowledge and experience. I am lucky in the fact that I moved to <a target="_blank" href="http://x10hosting.com">X10 Hosting</a> for the very first time. In my opinion they are one of the best in providing free hosts. The amount of features and largely the amount of support at their forums make them the best free hosting services around. I started with <a target="_blank" href="http://imoracle.x10hosting.com">http://imoracle.x10hosting.com</a> as my first ever site. Few applications which I build on that were:
<ul>
<li>User login and registration system, where user was authenticated by an link sent to him through email.</li>
<li>Inside I had a few basic applications including contact form, multiple picture uploads etc etc.</li>
<li>One of the finest feature I had in that was Gmail Contact Import script, which I made using PHP Curl application.</li>
<li>Last but not the least I built a chat application similar to browser based chat applications in google and yahoo mails. (Though not that efficient). That was first and the last time I used a framework for any of my application. It was built using <a target="_blank" href="http://prototype-window.xilinus.com/">Prototype Windows Class</a> framework.</li>
</ul>
<p>I told you about these features as these were the applications which got me started initially. Helped me learn the tid bits of web development. May be you too can give a try to a few of them as your first few applications.</span></span></span></span></span></li>
<li><span style="color: rgb(0, 0, 0);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="font-weight: bold; text-decoration: underline; color: rgb(51, 51, 255);">Altertunes:</span><span style="font-weight: bold; color: rgb(51, 51, 255);"></span><span style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 0, 51);">Must be wondering why is this name up here again. Well I agree <a target="_blank" href="http://altertunes.com">Altertunes</a> fails as a full time product on web but then actually this self initiated project helped me learn all and everything about web development. It was hugely an ajax dominated website with ajax requests flowing in and out of everything you do inside. Basically the social networking aspect inside altertunes helped me learn most of the things. Key things inside altertunes which helped me develop my web dev skills are:
<ul>
<li>Social networking aspects like adding friends, sending personal messages, dedicating a song to your friends etc etc.</li>
<li>Importing Gmail, Yahoo and other email contacts. I initially used self made gmail address book import script. But then probably Gmail changed the ways on their mail and my script started failing. However I was lucky to find various services which helps you import mail contacts.</li>
<li>Creating of search bots for mp3. This was one of the things done in PERL instead of PHP. Read my blog on <a target="_blank" href="http://abhinavsingh.com/blog/2008/05/how-to-write-crawlers-and-parse-a-page-using-perl-part-1/">how to create an html parser using PERL</a> here. This search bot was similar to any other search bot but it only used to index mp3 files in the database.</li>
<li>Use of various web services API&#8217;s like Artist Recommendation API by <a target="_blank" href="http://last.fm">last.fm</a>, Video API by <a target="_blank" href="http://youtube.com">YouTube</a>, Pictures API by <a target="_blank" href="http://google.com">Google</a>.</li>
<li>Features like creating your custom playlists, bookmarking artists, creation of analytic backend engine to provide users with the best recommended songs based on users listen history.</li>
<li>Finally, I learnt to make custom web players. Alterplayer which I made using <a href="http://openlaszlo.org">OpenLaszlo</a>, was something which I did out of PHP, MySQL, Apache.</li>
<li>Being at Oracle at that point in time, helped me in maintaining such a relational database with ease.</li>
<li>Auto suggest feature which is similar to google auto suggest. Altertunes used to offer you artist names as you typed in the name of the artist.</li>
<li>News from Google and Yahoo news. As there were no API&#8217;s available for this, I scrapped the google and yahoo news using PERL scripts and showed them to the users. (Illegal it was though) <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
</li>
</ul>
<p>However I must say that your website is not complete till you have all the look and feel and User Interface to lure the users. Initially I thought that the UI is coming up good but then as the features which I wanted to offer increased and with my sucking &lt;table&gt; structured HTML pages everything got screwed. However Altertunes helped me develop my web dev skills a hell lot and helped me understanding the right way of doing things. Probably picking up a small project for yourself is always the best idea, as then only you will always try to make your application look more professional.</p>
<p></span></span></span></span></span></span></span></li>
<li><span style="color: rgb(0, 0, 0);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="font-weight: bold; text-decoration: underline; color: rgb(51, 51, 255);">Time for a shared host</span> : As the traffic increased on <span style="color: rgb(51, 0, 51);">Altertunes I had to quickly shift to a shared hosting. I again went for a shared hosting at X10, where I bought a hosting server for around 80$ a year with 99% uptime till date. All my websites including Altertunes, My personal website and a few other under ground works of mine are hosted on the same shared host. Basically shared host assures you of more % uptime, more bandwidth and more forum support from X10. Those guys just go out of their ways at times to help you out.
<p></span>However you always have few drawbacks of a shared host:</p>
<ul>
<li>First of all its a shared host i.e. a single CPU with many document roots (one root for each client) in it. At times hosting service providers over shoot the maximum allowed roots on a single CPU, which makes your CPU share low. And hence sucking performances.</li>
<li>Your site can go down even without a single error from your side. Yes this is the case which happened with me, when one of the other user on the same CPU set up a cron job (an automated job which runs every X hours) to take a backup of his server every 1 hour. Well in that case every single hour he used to consume maximum CPU cycles and hence all other users their started experiencing major downtimes. However X10 forum moderators are kind enough. They take immediate actions in such cases and ensure everything is fine.</li>
<li>You can&#8217;t have all PHP PEAR and Perl modules installed. I wanted to have a PHP PERL module installed for me by which I can write perl codes inside my PHP script. But as its a shared host and a package installed effects everyone on the CPU, I was denied by the X10 hosting admins.</li>
<li>Similarly for creating a upload meter application you need to have APC (Alternate PHP Cache) module enabled on your server. And I was again denied this package by the X10 hosting as they will cache all other users file which they might not want to.</li>
<li>Finally the biggest drawback is that you don&#8217;t have access to the httpd.conf i.e you apache server configuration file and your php.ini your php configuration file. Which at times you may want to change to meet your applications demand.<br />
<br style="color: rgb(51, 51, 255);" /></li>
</ul>
<p></span></span></span></span></span></span></span></li>
<li><span style="color: rgb(0, 0, 0);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 0, 51);"><span style="font-weight: bold; text-decoration: underline; color: rgb(51, 51, 255);">Finally time for a VPS (Virtual Private Server) </span>: When you start feeling you want a total control on your server and applications, its time to switch to a VPS. However they will cost you more than expected. I started with VPS at <a target="_blank" href="http://vpsfarm.com">VPSFarm</a> which I must say totally sucks. Doesn&#8217;t go well for me atleast with Zero support (&#8216;Zero&#8217; means zero). I took the Xen 1024 plan which costs around 40$ per month. However by the time my 1st month got over X10 started offering VPS too and with my experience and relations with them I immediately shifted to a VPS at X10. It too costs me same, around 35$ per month with more RAM and more Disk Space.
<p>However do not move to a VPS because you want to. It takes a lot of hard work to set it up and maintain it further. You basically have no support what so ever. Your mails not going, file not loading, server down, database not working. No one is accountable for that except you. But then you get all the controls on various configuration files which means you can fine tune the system to meet your needs.</p>
<p>However one thing which I miss is the comfort of CPanel which used to come in by default with free host and shared hostings. I got so used to it in last 1 year.&nbsp; Plus being from ECE background doesn&#8217;t helps me a great deal either. Anyways I suppose I am here to stay on VPS for long. I am slowly migrating all my websites to VPS.&nbsp;</span></span></span></span></span></span></span></li>
</ol>
<p>I guess this is all I had to share here in this post. If I have missed out on anything which many of you have asked me on chat and mails kindly feel free to ask it here. If I feel I need to add anything, will do so.</p>
<p>For experienced developers who accidentally read till here, feel free to add anything you want to. If you feel anything was wrong in my methodology and approach do let us all know. I am still learning.</p>
<p>All the best for all those starting out there.</p>
<p>Patience is the Key I will say finally.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<b>Other Posts you may want to read:</b><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<ul>
<li>
    <a href="    http://abhinavsingh.com/blog/2008/07/calendar-with-auto-notification-api-and-demo/"> Calendar with auto notification API</a>
  </li>
<li>
    <a href="http://abhinavsingh.com/webdemos/iphoneflickphotoapi/">iPhone Flick Photo Slideshow API</a>
  </li>
<li>
    <a href="http://abhinavsingh.com/webdemos/photocropperapi/">ImageCropper API and Demo</a>
  </li>
<li>
    <a href="http://abhinavsingh.com/webdemos/igoogleportal/">How to make an iGoogle type portal</a>
  </li>
<li>
    <a href="http://abhinavsingh.com/webdemos/phototaggerapi/">Photo Tagging API and Demo</a>
  </li>
</ul>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F07%2Fhow-to-get-started-with-web-development%2F","http:\/\/tomcat.apache.org\/","https:\/\/java.sun.com\/products\/jsp","http:\/\/altertunes.com","http:\/\/x10hosting.com","http:\/\/imoracle.x10hosting.com","http:\/\/prototype-window.xilinus.com\/","http:\/\/altertunes.com","http:\/\/last.fm","http:\/\/youtube.com","http:\/\/google.com","http:\/\/openlaszlo.org","http:\/\/vpsfarm.com","http:\/\/abhinavsingh.com\/webdemos\/iphoneflickphotoapi\/","http:\/\/abhinavsingh.com\/webdemos\/photocropperapi\/","http:\/\/abhinavsingh.com\/webdemos\/igoogleportal\/","http:\/\/abhinavsingh.com\/webdemos\/phototaggerapi\/"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDA4LzA3L2hvdy10by1nZXQtc3RhcnRlZC13aXRoLXdlYi1kZXZlbG9wbWVudC88d3B0Yj5Ib3cgdG8gZ2V0IHN0YXJ0ZWQgd2l0aCB3ZWIgZGV2ZWxvcG1lbnQ%2FPHdwdGI%2BaHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZzx3cHRiPkFiaGkmIzAzOTtzIFdlYmxvZw%3D%3D";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/" title="How to configure Ubuntu and LAMP on Windows">How to configure Ubuntu and LAMP on Windows</a> (4)</li><li><a href="http://abhinavsingh.com/blog/2008/05/web-development-part-1-apache-mysql-php/" title="Web Development &#8211; Part 1: Apache, MySQL, PHP">Web Development &#8211; Part 1: Apache, MySQL, PHP</a> (4)</li><li><a href="http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/" title="Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu">Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu</a> (5)</li><li><a href="http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/" title="Memcached and &quot;N&quot; things you can do with it &#8211; Part 1">Memcached and &quot;N&quot; things you can do with it &#8211; Part 1</a> (19)</li><li><a href="http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/" title="MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose">MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose</a> (43)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2008/07/how-to-get-started-with-web-development/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to configure Ubuntu and LAMP on Windows</title>
		<link>http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/</link>
		<comments>http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/#comments</comments>
		<pubDate>Tue, 13 May 2008 05:41:47 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/</guid>
		<description><![CDATA[Hello all Linux freaks, Having already looked upon how to configure Apache-PHP-MySQL on Windows, now here I will try to explain in short how to do the same on Linux OS. I personally don&#8217;t have a seperate machine for linux. I run Ubuntu on my Windows machine using VM Ware. So before we go on [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F05%2Fhow-to-configure-ubuntu-and-lamp-on-windows%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F05%2Fhow-to-configure-ubuntu-and-lamp-on-windows%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=Apache,Linux,MySQL,PHP,Ubuntu,Windows&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello all Linux freaks,</p>
<p>Having already looked upon how to configure Apache-PHP-MySQL on Windows, now here I will try to explain in short how to do the same on Linux OS. I personally don&#8217;t have a seperate machine for linux. I run Ubuntu on my Windows machine using VM Ware. So before we go on to see how to configure LAMP on Ubuntu, lets see how can we have Ubuntu running on Windows.</p>
<ul>
<li>For this tutorial I have used VMware-player-2.0.2-59824.exe for VM Ware installation and Ubuntu-7.04-desktop-i386.zip for Ubuntu. You will need to download the same from <a href="http://www.vmware.com/download/player/">http://www.vmware.com/download/player/</a> and <a href="http://www.ubuntu.com/GetUbuntu/download">http://www.ubuntu.com/GetUbuntu/download</a></li>
<li>Install VM Ware, which is the most simple installer as you can get. At the end it will ask you to reboot the machine and kindly do not skip this step.</li>
<li>Now, open VM Ware which you have just installed and you should see something like this:
<p><img src="http://altertunes.com/library/images/Ubuntu_1.jpg" border="0" /></p>
</li>
<li>Now click the open button and browse to the folder where you have unzipped the Ubuntu zip file.
<p><img src="http://altertunes.com/library/images/Ubuntu_2.jpg" border="0" /></p>
</li>
<li>Click open Ubuntu-7.04-desktop-i386.vmx and thats it. You have just installed and configured Ubuntu on Windows. Simple, Isn&#8217;t it ? You should be seeing something like this by now:
<p><img src="http://altertunes.com/library/images/Ubuntu_3.jpg" border="0" /></p>
</li>
</ul>
<p>For my system, Ubuntu automatically picked up various internet settings. However when I tried running the same from my office, I had to make appropriate changes for proxy setting. Kindly do the same for running internet on your Ubuntu.</p>
<p>Now an important thing before we proceed:</p>
<ol>
<li>The default administrator password for Ubuntu is <span style="font-weight: bold;">ubuntu</span></li>
<li>By default you are not the admin or root user. Hence you will need to prefix <span style="font-weight: bold;">sudo</span> or <span style="font-weight: bold;">su</span> to run a command as administrator in the Ubuntu terminal.</li>
</ol>
<p>Also, before we proceed further kindly check if your Ubuntu is configured correctly for internet connection. Just check by opening this blog through mozilla in ubuntu. If it works, you are all set to configure LAMP on ubuntu.</p>
<p>Follow the following steps to configure LAMP on ubuntu (you need to run a few commands on your terminal window)</p>
<ul>
<li>Open file at /etc/apt/source.list and uncheck the box for install from CD. This will let ubuntu install all modules directly from the repository.
</li>
<li>$ sudo apt-get upgrade</li>
<li>$ sudo apt-get update</li>
<li>$ sudo apt-get install mysql-server mysql-admin apache2 php5 libapache2-mod-php5 libapache2-mod-auth-mysql php5-mysql phpmyadmin</li>
<li>$ sudo mysqladmin -u root password [YOUR_NEW_PASSWORD]</li>
<li>$ sudo /etc/init.d/mysql restart</li>
<li>$ sudo /etc/init.d/apache2 restart</li>
</ul>
<p>Thats pretty much we need. Now let us test our configuration and LAMP setup.</p>
<ol>
<li>$ sudo vim /var/www/phpinfo.php</li>
<li>Type in the following few lines of code in the file:
<pre><font size="-1">&lt;?php
  phpinfo();
?&gt;</font></pre>
</li>
<li>Open up your browser and type in <a href="http://localhost/phpinfo.php">http://localhost/phpinfo.php</a></li>
<li>If you are able to see the php config file information on your browser. Thats it.</li>
<li>Next type <a href="http://localhost/phpmyadmin">http://localhost/phpmyadmin</a></li>
<li>Login as root i.e. <span style="font-weight: bold;">Username</span> : root and <span style="font-weight: bold;">Password</span> : [YOUR_NEW_PASSOWRD]</li>
<li>If you are lucky enough you will see the phpadmin console.</li>
</ol>
<p>Congratulations ! Thats pretty much what exactly we need. Now go on to do all your web development on Linux. Hail Windows <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I configure all this stuff long back, so if I have missed out on some issues kindly lemme know and comment the same.</p>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F05%2Fhow-to-configure-ubuntu-and-lamp-on-windows%2F","http:\/\/www.vmware.com\/download\/player\/","http:\/\/www.ubuntu.com\/GetUbuntu\/download","http:\/\/localhost\/phpinfo.php","http:\/\/localhost\/phpmyadmin"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDA4LzA1L2hvdy10by1jb25maWd1cmUtdWJ1bnR1LWFuZC1sYW1wLW9uLXdpbmRvd3MvPHdwdGI%2BSG93IHRvIGNvbmZpZ3VyZSBVYnVudHUgYW5kIExBTVAgb24gV2luZG93czx3cHRiPmh0dHA6Ly9hYmhpbmF2c2luZ2guY29tL2Jsb2c8d3B0Yj5BYmhpJiMwMzk7cyBXZWJsb2c%3D";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2008/07/how-to-get-started-with-web-development/" title="How to get started with web development?">How to get started with web development?</a> (9)</li><li><a href="http://abhinavsingh.com/blog/2009/01/memcached-and-n-things-you-can-do-with-it/" title="Memcached and &quot;N&quot; things you can do with it &#8211; Part 1">Memcached and &quot;N&quot; things you can do with it &#8211; Part 1</a> (19)</li><li><a href="http://abhinavsingh.com/blog/2008/05/web-development-part-1-apache-mysql-php/" title="Web Development &#8211; Part 1: Apache, MySQL, PHP">Web Development &#8211; Part 1: Apache, MySQL, PHP</a> (4)</li><li><a href="http://abhinavsingh.com/blog/2010/04/setting-nginx-php-fastcgi-and-xcache-on-a-new-ubuntu/" title="Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu">Setting Nginx, PHP Fastcgi and XCache on a new Ubuntu</a> (5)</li><li><a href="http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/" title="MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose">MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose</a> (43)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2008/05/how-to-configure-ubuntu-and-lamp-on-windows/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

