<?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>The NewComer</title>
	<atom:link href="http://blog.jambura.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jambura.com</link>
	<description>Sharing my web developing experience with the world</description>
	<lastBuildDate>Wed, 25 Apr 2012 07:29:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Implementing MySql View in CakePHP For Typeahead Search</title>
		<link>http://blog.jambura.com/2012/03/23/implementing-mysql-view-in-cakephp-for-typeahead-search/</link>
		<comments>http://blog.jambura.com/2012/03/23/implementing-mysql-view-in-cakephp-for-typeahead-search/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 14:32:37 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Autocomplete]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[jQuery Ui]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[Typeahead]]></category>
		<category><![CDATA[View]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=556</guid>
		<description><![CDATA[View works like a table, but it is not a table. It never exists; it is only a prepared SQL statement that is run when you reference the view name. A programmer can write VIEWs that limit the dataset both horizontally and vertically, ensuring that only the data that is required is queried for. Recently [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2011/08/cakephp_logo_250_trans.png"><img src="http://blog.jambura.com/wp-content/uploads/2011/08/cakephp_logo_250_trans.png" alt="" title="cakephp_logo_250_trans" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>View works like a table, but it is not a table. It never exists; it is only a prepared SQL statement that is run when you reference the view name. A programmer can write VIEWs that limit the dataset both horizontally and vertically, ensuring that only the data that is required is queried for. Recently I Had to implement a search option for one of my developed site. The requirement was to show typeahed results from 5 tables. I used <a href="http://jqueryui.com/demos/autocomplete/" target="_blank">jQuery Ui &#8211; Autocomplete</a>&#8216;s Remote with caching to fullfil this requirement. My ajax call back result must fast enough as user writes on the textbox and result is showing. So for my first query return I used MySql View. Then start I firedup my <a href="http://book.cakephp.org/1.3/view/1522/Code-Generation-with-Bake" target="_blank">Cake Bake</a>. When I go to model creation i dont see my view&#8217;s name. I thought I have made some mistake &#8211; So I start looking into my view creation sql, my database configuration. But all seems ok. Then I clear cache by deleting  app/tmp/cahe/models/. Yet no luck. Then I start poking around codes on cake folder. Then i found what I have been dreading.</p>
<p>On cake/libs/model/datasources/datasource.php line 613</p>
<pre class="brush: plain; title: ; notranslate">
function listSources() {
    $cache = parent::listSources();
    if ($cache != null) {
        return $cache;
    }
    $result = $this-&gt;_execute('SHOW TABLES FROM ' . $this-&gt;name($this-&gt;config['database']) . ';');

    if (!$result) {
        return array();
    } else {
        $tables = array();

        while ($line = mysql_fetch_row($result)) {
            $tables[] = $line[0];
        }
        parent::listSources($tables);
        return $tables;
    }
}
</pre>
<p>So CakePHP does not support MySql view!? No it does. But views are not available for Bake <img src='http://blog.jambura.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . Anyway you have create model, controller and view files old fashioned manually.</p>
<p>So my view sql is </p>
<pre class="brush: plain; title: ; notranslate">
CREATE VIEW searches AS
select videos.id AS id,videos.video_title AS Name,'videos' AS TYPE from videos
union
select users.id AS id,concat(users.first_name,' ',users.last_name) AS Name, 'users' AS TYPE from users
union
select tag_sub_categories.id AS id,tag_sub_categories.name AS name,'tag_sub_categories' AS TYPE from tag_sub_categories
union
select shows.id AS id,shows.title AS title,'shows' AS TYPE from shows union select announcements.id AS id,announcements.title AS title,'announcements' AS TYPE from announcements;
</pre>
<p>Mysql <a href="http://dev.mysql.com/doc/refman/5.0/en/union.html" target="_blank">UNION</a> is used to combine the result from multiple SELECT statements into a single result set. UNION is quite handy as you can see I can have all the values from different table in one result set. I also used a virtual field TYPE for tracking were the values from. </p>
<p>Bow create a file app/models/search.php and add the following code</p>
<pre class="brush: plain; title: ; notranslate">
class Search extends AppModel {
	var $name = 'Search';
	var $useTable = 'searches';
	var $primaryKey = 'id';
	var $useDbConfig = 'default';
}
</pre>
<p>You have to use $primaryKey otherwise when you to use find(&#8216;list&#8217;) as described <a href="http://cakephp.lighthouseapp.com/projects/42648/tickets/1968#ticket-1968-9">Here</a>.</p>
<p>Now lets create out controller file app/controllers/searches_controller.php</p>
<pre class="brush: plain; title: ; notranslate">
class SearchesController extends AppController {

	var $name = 'Searches';
	var $paginate = array(
		'limit' =&gt; 10,
	);	

	function search_json() {
		$search_keyword=$this-&gt;params['url']['term'];
		$results = $this-&gt;Search-&gt;find('all',array(
					'conditions'=&gt;array('Name LIKE '=&gt; &quot;{$search_keyword}%&quot;),
					'limit'=&gt;8
				));
		$return_array=array();
		foreach	($results as $result):
			$temp['id']=$result['Search']['id'];
			$temp['label']= (strlen($result['Search']['Name']) &gt; 30)? substr($result['Search']['Name'], 0, 30). '...' : $result['Search']['Name'];
			$temp['value']=$result['Search']['Name'];
			$return_array[]=$temp;
		endforeach;
		echo json_encode($return_array);
		exit;
	}
}
</pre>
<p>For our search function</p>
<pre class="brush: plain; title: ; notranslate">
&lt;script&gt;
$(function(){
$.ui.autocomplete.prototype._renderItem = function( ul, item){
  var term = this.term.split(' ').join('|');
  var re = new RegExp(&quot;(&quot; + term + &quot;)&quot;, &quot;gi&quot;) ;
  var t = item.label.replace(re,&quot;&lt;strong&gt;$1&lt;/strong&gt;&quot;);
  return $( &quot;&lt;li&gt;&lt;/li&gt;&quot; )
     .data( &quot;item.autocomplete&quot;, item )
     .append( &quot;&lt;a &gt;&quot; + t + &quot;&lt;/a&gt;&quot; )
     .appendTo( ul );
};
	var cache = {},
		lastXhr;
	$( &quot;#search_ahead&quot; ).autocomplete({
		minLength: 2,
		source: function( request, response ) {
			var term = request.term;
			if ( term in cache ) {
				response( cache[ term ] );
				return;
			}

			lastXhr = $.getJSON( &quot;&lt;?php echo $html-&gt;url(array(&quot;controller&quot; =&gt; &quot;searches&quot;, &quot;action&quot; =&gt; &quot;search_json&quot;));?&gt;&quot;, request, function( data, status, xhr ) {
				cache[ term ] = data;
				if ( xhr === lastXhr ) {
					response( data );
				}
			});
		}
	});
});
&lt;/script&gt;
    	&lt;?php echo $this-&gt;Form-&gt;create(null, array('url'=&gt;&quot;/searches/show_results.html&quot;, 'type'=&gt;&quot;file&quot;, 'id'=&gt;'change_status', 'inputDefaults' =&gt; array('label' =&gt; false,'div' =&gt; false)));?&gt;
        &lt;table width=&quot;230&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;&gt;
            &lt;tr&gt;
                &lt;td width=&quot;170&quot;&gt;&lt;input name=&quot;search_ahead&quot; id=&quot;search_ahead&quot; type=&quot;text&quot; class=&quot;input-box2&quot; style=&quot;width:160px; height:22px;&quot; value=&quot;&quot; /&gt;&lt;/td&gt;
                &lt;td width=&quot;60&quot;&gt;&lt;?php echo $this-&gt;Form-&gt;end('/css/images/frequency-search.gif');?&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
        &lt;?php ?&gt;
</pre>
<p>This function also highlight the search text on the result text.<br />
<img src="http://blog.jambura.com/wp-content/uploads/2012/03/Screen-shot-2012-03-23-at-8.30.33-PM.png" alt="" title="Screen shot 2012-03-23 at 8.30.33 PM" width="300" height="239" class="aligncenter size-full wp-image-559" /></p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2012/03/23/implementing-mysql-view-in-cakephp-for-typeahead-search/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2012/03/23/implementing-mysql-view-in-cakephp-for-typeahead-search/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>afterSave: A Great Callback Method for Soft Deleting Related Model Data( hasOne, hasMany, belongsTo)</title>
		<link>http://blog.jambura.com/2012/03/01/aftersave-a-great-callback-method-for-soft-deleting-related-model-data-hasone-hasmany-belongsto/</link>
		<comments>http://blog.jambura.com/2012/03/01/aftersave-a-great-callback-method-for-soft-deleting-related-model-data-hasone-hasmany-belongsto/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 22:09:40 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[afterSave]]></category>
		<category><![CDATA[belongsTo]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[Callback Method]]></category>
		<category><![CDATA[hasMany]]></category>
		<category><![CDATA[hasOne]]></category>
		<category><![CDATA[Related Model Data]]></category>
		<category><![CDATA[Soft Delete]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=543</guid>
		<description><![CDATA[Update: Here is model file to download Download Code I never like to &#8220;Hard Delete&#8221; data. Some one will make mistake deleting something. Then they will tell you retrive it. So &#8220;Soft Delete&#8221; can save you time telling you clients/boss why the data can not be retrieved. BTW &#8220;Soft Delete&#8221; means you keep a field [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update:</b>  Here is model file to download <a href="http://blog.jambura.com/wp-content/uploads/2012/03/models.zip"><strong>Download Code</strong></a><br />
<br />
<a href="http://blog.jambura.com/wp-content/uploads/2011/08/cakephp_logo_250_trans.png"><img src="http://blog.jambura.com/wp-content/uploads/2011/08/cakephp_logo_250_trans.png" alt="" title="cakephp_logo_250_trans" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>I never like to &#8220;Hard Delete&#8221; data. Some one will make mistake deleting something. Then they will tell you retrive it. So &#8220;Soft Delete&#8221; can save you time telling you clients/boss why the data can not be retrieved. BTW &#8220;Soft Delete&#8221; means you keep a field in table name is_delete/delete. Setting it&#8217;s value 1(or any value you may use but using boolean 1 seems logical) means the item is deleted. &#8220;Hard Delete&#8221; means you delete the row from the table. Poof gone. When i say delete on this post means &#8220;Soft Delete&#8221;.</p>
<p>Now lest discuss the power of afterSave. Suppose you Relational database for products. You have categories, sub-categories and sub-categories. Their relation looks like this</p>
<p>Category hasMany SubCategories<br />
SubCategory hasMany SubSubCategories<br />
SubSubCategory hasMany Products</p>
<p>Category -> SubCategories -> SubSubCategories -> Products</p>
<p>As CakePHP naming convention your Category, SubCategory, SubSubCategory Model should have these fields</p>
<pre class="brush: plain; title: ; notranslate">
CREATE TABLE `categories ` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(550) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB ;

CREATE TABLE `sub_categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `name` varchar(550) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE `sub_sub_categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sub_category_id` int(11) NOT NULL,
  `name` varchar(550) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` int(11) NOT NULL,
  `sub_sub_category_id` int(11) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;
</pre>
<p>created, modified will be automatically updated by CakePHP. Its nice little feature. So on to our relation between tables. categories table is connected with sub_categories category_id. Its model will look like this</p>
<pre class="brush: plain; title: ; notranslate">
class Catagory extends AppModel {
	var $name = 'Catagory';
	var $displayField = 'name';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $hasMany = array(
		'SubCatagory' =&gt; array(
			'className' =&gt; 'SubCatagory',
			'foreignKey' =&gt; 'catagory_id',
			'dependent' =&gt; false,
		)
	);
}
</pre>
<p>Same with sub_categories, sub_sub_categories and products table.</p>
<pre class="brush: plain; title: ; notranslate">
class SubCatagory extends AppModel {
	var $name = 'SubCatagory';
	var $displayField = 'name';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'Catagory' =&gt; array(
			'className' =&gt; 'Catagory',
			'foreignKey' =&gt; 'catagory_id',
		)
	);

	var $hasMany = array(
		'SubSubCatagory' =&gt; array(
			'className' =&gt; 'SubSubCatagory',
			'foreignKey' =&gt; 'sub_catagory_id',
			'dependent' =&gt; false,
		)
	);
}

class SubSubCatagory extends AppModel {
	var $name = 'SubSubCatagory';
	var $displayField = 'name';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'SubCatagory' =&gt; array(
			'className' =&gt; 'SubCatagory',
			'foreignKey' =&gt; 'sub_catagory_id',
		)
	);

	var $hasMany = array(
		'Product' =&gt; array(
			'className' =&gt; 'Product',
			'foreignKey' =&gt; 'sub_sub_catagory_id',
			'dependent' =&gt; false,
		)
	);
}

class Product extends AppModel {
	var $name = 'Product';
	var $displayField = 'name';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'SubSubCatagory' =&gt; array(
			'className' =&gt; 'SubSubCatagory',
			'foreignKey' =&gt; 'sub_sub_catagory_id',
			'conditions' =&gt; '',
			'fields' =&gt; '',
			'order' =&gt; ''
		)
	);
}
</pre>
<p>Now we will delete on category &#8211; so the row on the categories table will updated with 1. But all the rows on the sub_categories, sub_sub_categories, products for that category will not be deleted. Now comes CakePHP to rescue. It is actually quite beautiful. Lets add afterSave() function to  Category model -category.php</p>
<pre class="brush: plain; title: ; notranslate">
	function afterSave()
	{
		if($this-&gt;data['Catagory']['is_delete']==1)
		{
			$this-&gt;SubCatagory-&gt;recursive=0;
			$sub_catagories = $this-&gt;SubCatagory-&gt;find('all', array(
								'conditions' =&gt; array('SubCatagory.catagory_id'=&gt;$this-&gt;data['Catagory']['id'])
							));
			foreach($sub_catagories as $sub_catagory):
				unset($this-&gt;data['SubCatagory']);
				$this-&gt;data=$sub_catagory;
				$this-&gt;data['SubCatagory']['is_delete']=1;
			endforeach;
		}
	}
</pre>
<p>We first check for delete. The we found out all the sub_catagories. Then we delete it. But what about the sub_sub_categories and products. Lets first delete the sub_sub_categories.</p>
<pre class="brush: plain; title: ; notranslate">
	function afterSave()
	{
		if($this-&gt;data['SubCatagory']['is_delete']==1 )
		{
			$this-&gt;SubSubCatagory-&gt;recursive=0;
			$sub_sub_catagories = $this-&gt;SubSubCatagory-&gt;find('all', array(
								'conditions' =&gt; array('SubCatagory.catagory_id'=&gt;$this-&gt;data['Catagory']['id'],'SubSubCatagory.sub_catagory_id'=&gt;$this-&gt;data['SubCatagory']['id'])
							));
			foreach($sub_sub_catagories as $sub_sub_catagory):
				unset($this-&gt;data['SubSubCatagory']);
				$this-&gt;data=$sub_sub_catagory;
				$this-&gt;data['SubSubCatagory']['is_delete']=1;
				$this-&gt;SubSubCatagory-&gt;save($this-&gt;data);
			endforeach;
		}
	}
</pre>
<p>Wow all the sub_sub_catagories are deleted. Now delete all the products</p>
<pre class="brush: plain; title: ; notranslate">
	function afterSave($created)
	{
		if($this-&gt;data['SubSubCatagory']['is_delete']==1 or $this-&gt;data['SubSubCatagory']['is_hide']==1)
		{
			$this-&gt;Product-&gt;recursive=0;
			$products = $this-&gt;Product-&gt;find('all', array(
								'conditions' =&gt; array('Product.catagory_id'=&gt;$this-&gt;data['SubCatagory']['catagory_id'], 'Product.sub_catagory_id'=&gt;$this-&gt;data['SubCatagory']['id'], 'Product.sub_sub_catagory_id'=&gt;$this-&gt;data['SubSubCatagory']['id'])
							));
			foreach($products as $product):
				unset($this-&gt;data['Product']);
				$this-&gt;data=$product;
				$this-&gt;data['Product']['is_delete']=1;
				$this-&gt;Product-&gt;save($this-&gt;data);
			endforeach;
		}
	}
</pre>
<p>Now all the records have been deleted. Now you can ask why i did not add the codes on the Category model because then deleting any sub_categories entry will not delete sub_sub_categories and products.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2012/03/01/aftersave-a-great-callback-method-for-soft-deleting-related-model-data-hasone-hasmany-belongsto/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2012/03/01/aftersave-a-great-callback-method-for-soft-deleting-related-model-data-hasone-hasmany-belongsto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ISPConfig 3 setup on Ubuntu</title>
		<link>http://blog.jambura.com/2012/02/10/ispconfig-3-setup-on-ubuntu/</link>
		<comments>http://blog.jambura.com/2012/02/10/ispconfig-3-setup-on-ubuntu/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 14:08:44 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Amavisd-new]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ClamAV]]></category>
		<category><![CDATA[Courier]]></category>
		<category><![CDATA[courier-authdaemon]]></category>
		<category><![CDATA[courier-authlib-mysql]]></category>
		<category><![CDATA[courier-imap]]></category>
		<category><![CDATA[courier-imap-ssl]]></category>
		<category><![CDATA[courier-pop]]></category>
		<category><![CDATA[courier-pop-ssl]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[getmail4]]></category>
		<category><![CDATA[ISPConfig]]></category>
		<category><![CDATA[ISPConfig 3]]></category>
		<category><![CDATA[maildrop]]></category>
		<category><![CDATA[MailPrograms]]></category>
		<category><![CDATA[mcrypt]]></category>
		<category><![CDATA[MyDNS]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql-client]]></category>
		<category><![CDATA[mysql-server]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[Pear]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[phpMyAdmin]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[postfix-doc]]></category>
		<category><![CDATA[postfix-mysql]]></category>
		<category><![CDATA[PureFTPdwith Quotas]]></category>
		<category><![CDATA[SpamAssassin]]></category>
		<category><![CDATA[SquirrelMail]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[suExec]]></category>
		<category><![CDATA[Vlogger]]></category>
		<category><![CDATA[Webalizer]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=500</guid>
		<description><![CDATA[There are number of Hosting Control Panel Softwares. The cPanel is best but it cost 10$ per month. Plesk also need licensing cost. Webmin is free but it interface is not user friendly. THe ISPConfig &#8211; Hosting Control Panel Software has user friendly interface with a lot of functions and it is totally free. They [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo-300x274.jpg" alt="" title="Ubuntu-logo" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>There are number of Hosting Control Panel Softwares. The cPanel is best but it cost 10$ per month. Plesk also need licensing cost. Webmin is free but it interface is not user friendly. THe ISPConfig &#8211; Hosting Control Panel Software has user friendly interface with a lot of functions and it is totally free.  They charge simple fee to download documentation pdf but They have very good documentation on line <a href="http://docs.ispconfig.org/creating-web-sites/subdomains/" target="_blank">Here</a>. Before you set up ISPConfig 3 you need to prepare you server. In this tutorial i will show how to set it up.</p>
<p><strong>Update Repositories</strong></p>
<p>We need to update the aptitude repository indexes. </p>
<pre class="brush: plain; title: ; notranslate">
 apt-get update
</pre>
<p><strong>Installing Prerequisites</strong></p>
<p>Next we need to install the prerequisite packages for ISPConfig. The following packages will be needed:</p>
<ul>
<li>PostFix (postfix, postfix-mysql, postfix-doc)</li>
<li>MySQL (mysql-client, mysql-server)</li>
<li>Courier (courier-authdaemon, courier-authlib-mysql, courier-pop, courier-pop-ssl, courier-imap, courier-imap-ssl)</li>
<li>System Libraries (libsasl2-2, libsasl2-modules, libsasl2-modules-sql, sasl2-bin, libpam-mysql, binutils)</li>
<li>SSL (openssl)</li>
<li>Mail Programs (maildrop, getmail4)</li>
<li>Rootkit Hunter (rkhunter)</li>
</ul>
<pre class="brush: plain; title: ; notranslate">
 apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl maildrop getmail4 rkhunter binutils
</pre>
<p>During the setup you will be presented the following screens:<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.50.27-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.50.27-PM-300x215.png" alt="" title="Screen shot 2012-02-10 at 6.50.27 PM" width="300" height="215" class="aligncenter size-medium wp-image-503" /></a></p>
<p>- Enter a password you would like to use for the root user in MySQL.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.50.43-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.50.43-PM-300x212.png" alt="" title="Screen shot 2012-02-10 at 6.50.43 PM" width="300" height="212" class="aligncenter size-medium wp-image-503" /></a></p>
<p>- You will be required to enter the password again.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.51.16-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.51.16-PM-300x209.png" alt="" title="Screen shot 2012-02-10 at 6.51.16 PM" width="300" height="209" class="aligncenter size-medium wp-image-504" /></a><br />
- Select No as we do not want to create the directories.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.51.25-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.51.25-PM-300x212.png" alt="" title="Screen shot 2012-02-10 at 6.51.25 PM" width="300" height="212" class="aligncenter size-medium wp-image-505" /></a><br />
- Select Internet Site as the configuration type.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.51.58-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.51.58-PM-300x209.png" alt="" title="Screen shot 2012-02-10 at 6.51.58 PM" width="300" height="209" class="aligncenter size-medium wp-image-506" /></a><br />
- Enter your server&#8217;s hostname here. Keep in mind that it MUST resolve in DNS.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.52.11-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-6.52.11-PM-300x210.png" alt="" title="Screen shot 2012-02-10 at 6.52.11 PM" width="300" height="210" class="aligncenter size-medium wp-image-507" /></a><br />
- Select OK on this screen.</p>
<p><strong>Customizing MySQL</strong></p>
<p>Once the installation has completed we will need to modify the MySQL configuration to allow connections from all interfaces instead of localhost only. To open the MySQL configuration file type the following:</p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/mysql/my.cnf
</pre>
<p>Find the line that starts with <em>bind-address</em> and comment it out by putting a # in front of it. Save the file and quit.</p>
<p>Now we need to restart MySQL:</p>
<pre class="brush: plain; title: ; notranslate">
service mysql restart
</pre>
<p>Next we will need to make sure that MySQL is answering properly:</p>
<pre class="brush: plain; title: ; notranslate">
netstat -tap | grep mysql
</pre>
<p>You should see something that looks like the following:</p>
<p>ttcp        0      0 *:mysql                 *:*                     LISTEN      10296/mysqld </p>
<p><strong>Configuring Courier</strong></p>
<p>During the installation, the SSL certificates for IMAP-SSL and POP3-SSL were created with the hostname localhost. To change this to the correct hostname (mail.contosso.com in this tutorial), delete the certificates.</p>
<pre class="brush: plain; title: ; notranslate">
cd /etc/courier
rm -f imapd.pem
rm -f pop3d.pem
</pre>
<p>Next modify the following two files replacing CN=localhost with CN=mail.contosso.com. You may modify the other values as necessary. Replace mail.contosso.com with your real domain.</p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/courier/imapd.cnf

...

CN=mail.contosso.com
</pre>
<pre class="brush: plain; title: ; notranslate">
nano/etc/courier/pop3d.cnf

...

CN=mail.contosso.com
</pre>
<p>Next we need to recreate the certificates.</p>
<pre class="brush: plain; title: ; notranslate">
mkimapdcert
mkpop3dcert
</pre>
<p>Restart the Courier-IMAP-SSL and Courier-POP3-SSL services.</p>
<pre class="brush: plain; title: ; notranslate">
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop-ssl restart
</pre>
<p><strong>Install Amavisd-new, SpamAssassin, ClamAV</strong></p>
<p>To install amavisd-new, SpamAssassin, and ClamAV type the following:</p>
<pre class="brush: plain; title: ; notranslate">
apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl
</pre>
<p><strong>Install Apache, PHP5, phpMyAdmin, FastCGI, suExec, Pear, and mcrypt</strong></p>
<p>We need to install the following components:</p>
<ul>
<li>Apache Web Server</li>
<li>PHP5</li>
<li>phpMyAdmin MySQL Admin Tool</li>
<li>FastCGI extensions for Apache</li>
<li>suExec</li>
<li>Pear</li>
<li>mcrypt extensions for PHP</li>
</ul>
<pre class="brush: plain; title: ; notranslate">
apt-get install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear php-auth php5-mcrypt mcrypt php5-imagick imagemagick libapache2-mod-suphp
</pre>
<p>You will be prompted with the following screen:<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.12.18-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.12.18-PM-300x215.png" alt="" title="Screen shot 2012-02-10 at 7.12.18 PM" width="300" height="215" class="aligncenter size-medium wp-image-510" /></a><br />
- Select apache2 by pressing the space-bar and select OK.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.21.38-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.21.38-PM-300x214.png" alt="" title="Screen shot 2012-02-10 at 7.21.38 PM" width="300" height="214" class="aligncenter size-medium wp-image-511" /></a><br />
-Enter MySql root server and select OK.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.21.49-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.21.49-PM-300x214.png" alt="" title="Screen shot 2012-02-10 at 7.21.49 PM" width="300" height="214" class="aligncenter size-medium wp-image-512" /></a><br />
-Enter password for phpMyAdmin and select OK.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.22.03-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.22.03-PM-300x215.png" alt="" title="Screen shot 2012-02-10 at 7.22.03 PM" width="300" height="215" class="aligncenter size-medium wp-image-513" /></a><br />
-Enter same password for phpMyAdmin and select OK.</p>
<p><strong>Activate Apache Modules</strong></p>
<p>Next we will need to activate the following Apache modules: suexec, rewrite, ssl, actions, and include.</p>
<pre class="brush: plain; title: ; notranslate">
a2enmod suexec rewrite ssl actions include
</pre>
<p><strong>Installing PureFTPd with Quotas</strong></p>
<p>We need to allow FTP access with quota support. To accomplish this we will install PureFTPd. Use the following command:</p>
<pre class="brush: plain; title: ; notranslate">
apt-get install pure-ftpd-common pure-ftpd-mysql quota quotatool
</pre>
<p>Next we need to make a few changes to the configuration of PureFTPd. Edit /etc/default/pure-ftpd-common:</p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/default/pure-ftpd-common
</pre>
<p>Make sure that STANDALONE_OR_INETD is set to standalone and VIRTUALCHROOT is set to true.</p>
<p>Save the file if you made any changes.</p>
<p>Restart PureFTPd:</p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/init.d/pure-ftpd-mysql restart
</pre>
<p>Next we will enable quotas on our file system. First we need to modify our filesystem structure to support quotas. Let&#8217;s modify /etc/fstab to add support.</p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/fstab
</pre>
<p>On the line that starts with either /dev/sda1 or /dev/xvda1 we need to add ,usrquota,grpquota right after noatime in the arguments. For example, it should look like the following when you&#8217;re done if the device is /dev/sda1:</p>
<pre class="brush: plain; title: ; notranslate">
/dev/sda1       /           ext3    defaults,errors=remount-ro,noatime,usrquota,grpquota    0 1
</pre>
<p>Next we need to enable quotas:</p>
<pre class="brush: plain; title: ; notranslate">
touch /quota.user /quota.group
chmod 600 /quota.*
mount -o remount /
</pre>
<p>We&#8217;ll run a few utilities to make sure quotas are setup correctly:</p>
<pre class="brush: plain; title: ; notranslate">
quotacheck -avugm
quotaon -avug
</pre>
<p><strong>Installing MyDNS</strong></p>
<p>Before we can install MyDNS we need to install a few prequisites:</p>
<pre class="brush: plain; title: ; notranslate">
# sudo aptitude install g++ libc6 gcc gawk make texinfo libmysqlclient15-dev
</pre>
<p>MyDNS is not available in the Ubuntu 8.10 repository so we will have to install it ourselves. It is assumed you have the URL to the current version from the MyDNS website.</p>
<pre class="brush: plain; title: ; notranslate">
cd /tmp
wget http://downloads.sourceforge.net/project/mydns/mydns/0.11.0/mydns-0.11.0.tar.gz
tar xvfz mydns-1.2.8.27.tar.gz
cd mydns-1.2.8
./configure
make
make install
</pre>
<p>Now we need to create a start/stop script for MyDNS:</p>
<p>To create the file:</p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/init.d/mydns
</pre>
<p>Copy the following text into this file:</p>
<pre class="brush: plain; title: ; notranslate">
#! /bin/sh
#
# mydns         Start the MyDNS server
#
# Author:       Philipp Kern &lt;phil@philkern.de&gt;.
#               Based upon skeleton 1.9.4 by Miquel van Smoorenburg
#               &lt;miquels@cistron.nl&gt; and Ian Murdock &lt;imurdock@gnu.ai.mit.edu&gt;.
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/mydns
NAME=mydns
DESC=&quot;DNS server&quot;

SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

case &quot;$1&quot; in
  start)
        echo -n &quot;Starting $DESC: $NAME&quot;

        start-stop-daemon --start --quiet \
                --exec $DAEMON -- -b
        echo &quot;.&quot;
        ;;
  stop)
        echo -n &quot;Stopping $DESC: $NAME&quot;
        start-stop-daemon --stop --oknodo --quiet \
                --exec $DAEMON
        echo &quot;.&quot;
        ;;
  reload|force-reload)
        echo -n &quot;Reloading $DESC configuration...&quot;
        start-stop-daemon --stop --signal HUP --quiet \
                --exec $DAEMON
        echo &quot;done.&quot;

        ;;
  restart)
        echo -n &quot;Restarting $DESC: $NAME&quot;
        start-stop-daemon --stop --quiet --oknodo \
                --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet \
                --exec $DAEMON -- -b
        echo &quot;.&quot;
        ;;
  *)
        echo &quot;Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}&quot; &gt;&amp;2
        exit 1
        ;;
esac

exit 0
</pre>
<p>Next we need to make the file executable and add startup links for it.</p>
<pre class="brush: plain; title: ; notranslate">
chmod +x /etc/init.d/mydns
update-rc.d mydns defaults
</pre>
<p><strong>Installing Vlogger and Webalizer</strong></p>
<p>Use the following commands to install:</p>
<pre class="brush: plain; title: ; notranslate">
apt-get  install vlogger webalizer
</pre>
<p><strong>Installing fail2ban</strong></p>
<p>This is optional but recommended. ISPConfig monitor will attempt to show the fail2ban log.</p>
<pre class="brush: plain; title: ; notranslate">
apt-get install fail2ban
</pre>
<p><strong>Installing SquirrelMail</strong></p>
<p>To install the SquirrelMail webmail client use the following:</p>
<pre class="brush: plain; title: ; notranslate">
apt-get install squirrelmail
</pre>
<p>You should see a screen that looks like the following:<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.29.49-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.29.49-PM-300x263.png" alt="" title="Screen shot 2012-02-10 at 7.29.49 PM" width="300" height="263" class="aligncenter size-medium wp-image-515" /></a><br />
-select OK.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.29.57-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.29.57-PM-300x266.png" alt="" title="Screen shot 2012-02-10 at 7.29.57 PM" width="300" height="266" class="aligncenter size-medium wp-image-516" /></a><br />
-select OK.<br />
Now we need to create a symbolic link&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
ln -s /usr/share/squirrelmail/ /var/www/webmail
</pre>
<p>Use the following to configure SquirrelMail:</p>
<pre class="brush: plain; title: ; notranslate">
squirrelmail-configure
</pre>
<p>You should see a screen that looks like the following:<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.32.31-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.32.31-PM-300x262.png" alt="" title="Screen shot 2012-02-10 at 7.32.31 PM" width="300" height="262" class="aligncenter size-medium wp-image-517" /></a><br />
- We need to tell SquirrelMail that we are using Courier-IMAP/POP3. At the prompt enter D and press Enter.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.32.44-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.32.44-PM-300x260.png" alt="" title="Screen shot 2012-02-10 at 7.32.44 PM" width="300" height="260" class="aligncenter size-medium wp-image-518" /></a><br />
- Enter courier here to tell it to use Courier.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.33.04-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.33.04-PM-300x264.png" alt="" title="Screen shot 2012-02-10 at 7.33.04 PM" width="300" height="264" class="aligncenter size-medium wp-image-519" /></a><br />
- Press any key at the screen to continue.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.33.23-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.33.23-PM-300x263.png" alt="" title="Screen shot 2012-02-10 at 7.33.23 PM" width="300" height="263" class="aligncenter size-medium wp-image-520" /></a><br />
- Press S here to save the configuration. Press Q here to quit.</p>
<p>Now we need to test our Squirrel Mail configuration to make sure it loads. You can verify by sending your web browser to http://your_domain/webmail. Replace your_domain with your fully qualified domain name.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.37.32-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.37.32-PM-300x169.png" alt="" title="Screen shot 2012-02-10 at 7.37.32 PM" width="300" height="169" class="aligncenter size-medium wp-image-523" /></a></p>
<p><strong>Installing ISPConfig 3</strong></p>
<p>ISPConfig 3 is not available in the Ubuntu 8.10 repositories so we will have to install it manually. You must download the current version from the ISPConfig download page.</p>
<pre class="brush: plain; title: ; notranslate">
cd /tmp
wget http://prdownloads.sourceforge.net/ispconfig/ISPConfig-3.0.4.2.tar.gz
tar zxvf ISPConfig-3.0.4.2.tar.gz
cd ispconfig3_install/install/
php -q install.php
</pre>
<p><a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.43.02-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.43.02-PM-300x263.png" alt="" title="Screen shot 2012-02-10 at 7.43.02 PM" width="300" height="263" class="aligncenter size-medium wp-image-525" /></a><br />
- Press enter to accept en.<br />
- Press enter to accept the standard installation.<br />
- Enter your fully qualified host name. The default value pulled from your server will be the default. Press enter if you would like to accept.<br />
- Press enter because MySQL is installed on the same server.<br />
- Press enter to use the default username of root for the MySQL connection.<br />
- Press enter to use the default password for MySQL. It has not been configured yet.<br />
- Press enter to accept the default MySQL database name.<br />
- Press enter to accept the default MySQL character set.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.44.15-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.44.15-PM-300x264.png" alt="" title="Screen shot 2012-02-10 at 7.44.15 PM" width="300" height="264" class="aligncenter size-medium wp-image-527" /></a><br />
- Type US for the country code.<br />
- Enter your state name.<br />
- Enter your city name.<br />
- Enter your organization&#8217;s name.<br />
- Enter your department, if applicable<br />
- Enter a representative name for your company.<br />
- Enter a primary contact e-mail for the certificate.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.44.26-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.44.26-PM-300x263.png" alt="" title="Screen shot 2012-02-10 at 7.44.26 PM" width="300" height="263" class="aligncenter size-medium wp-image-528" /></a><br />
- Select the default port of 8080.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.44.41-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.44.41-PM-300x263.png" alt="" title="Screen shot 2012-02-10 at 7.44.41 PM" width="300" height="263" class="aligncenter size-medium wp-image-529" /></a><br />
- Enter to use https for web interface<br />
Use the same step for ssl set up previously.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.45.23-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.45.23-PM-300x261.png" alt="" title="Screen shot 2012-02-10 at 7.45.23 PM" width="300" height="261" class="aligncenter size-medium wp-image-530" /></a><br />
- Upon successful completion you should have a screen that looks similar to the screen above.</p>
<p><strong>Testing</strong></p>
<p>You may now log into ISPConfig for the first time. Point your web browser to http://your_domain:8080 replacing your_domain with your domain name. You should see a window that looks similar to the one below.<br />
<a href="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.46.00-PM.png"><img src="http://blog.jambura.com/wp-content/uploads/2012/02/Screen-shot-2012-02-10-at-7.46.00-PM-300x169.png" alt="" title="Screen shot 2012-02-10 at 7.46.00 PM" width="300" height="169" class="aligncenter size-medium wp-image-532" /></a></p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2012/02/10/ispconfig-3-setup-on-ubuntu/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2012/02/10/ispconfig-3-setup-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mail Server Installation on Ubuntu</title>
		<link>http://blog.jambura.com/2012/02/02/mail-server-installation-on-ubuntu/</link>
		<comments>http://blog.jambura.com/2012/02/02/mail-server-installation-on-ubuntu/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 10:53:35 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[Dovecot]]></category>
		<category><![CDATA[IMAP/POP3 Server]]></category>
		<category><![CDATA[Mail Server Installation]]></category>
		<category><![CDATA[Mail Transfer Agent]]></category>
		<category><![CDATA[MTA]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[SASL Authentication with TLS]]></category>
		<category><![CDATA[Squirrel Mail]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=486</guid>
		<description><![CDATA[As a beginner to linux it took about almost 10 days of goggling for me for proper installation of mail server and fixing necessary problems. Before you start this you should look into these posts Some Important Linux commands for Newbies and Setup LAMP With Ubuntu In 10 Minutes. We will setup Postfix (Mail Transfer [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2012/01/Linux.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2012/01/Linux.jpg" alt="" title="Linux" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>As a beginner to linux it took about almost 10 days of goggling  for me for proper installation of mail server and fixing necessary problems. Before you start this you should look into these posts  <a href="http://blog.jambura.com/2012/01/20/some-important-linux-commands-for-newbies/">Some Important Linux commands for Newbies</a> and <a href="http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/">Setup LAMP With Ubuntu In 10 Minutes</a>. We will setup Postfix (Mail Transfer Agent MTA), Dovecot (IMAP/POP3 Server), SASL Authentication with TLS (Authenticate before sending mail outside network in Outlook) and Squirrel Mail (Popular Web based Email).</p>
<p>Note: If you install Postfix/Dovecot mail server you will ONLY be able to send mail within your network. You can only send mail externally if you install SASL authentication with TLS. As otherwise you get nasty &#8220;Relay Access Denied&#8221; error.</p>
<p><strong>Install Postfix MTA (Mail Transfer Agent)</strong></p>
<pre class="brush: plain; title: ; notranslate">
apt-get install postfix postfix-tls  libsasl2-2 sasl2-bin libsasl2-modules popa3d
</pre>
<p>During installation, postfix will ask for few questions like name of server and answer those questions by entering your domain name and select Internet site for postfix.</p>
<p>Postfix configuration file is located at:/etc/postfix/main.cf. You can edit this file using popular text editor nano /etc/postfix/main.cf<br />
Start or Restart Postfix Server:</p>
<pre class="brush: plain; title: ; notranslate">
/etc/init.d/postfix restart
/etc/init.d/postfix stop
/etc/init.d/postfix start
</pre>
<p><strong>Install Dovecot</strong></p>
<pre class="brush: plain; title: ; notranslate">
apt-get install dovecot-imapd dovecot-pop3d dovecot-common
</pre>
<p>Dovecot configuration file is located at: /etc/dovecot/dovecot.conf</p>
<p><em>Before we proceed we need to make some changes with dovecot configuration file. Double check the following entries in the file if the values are entered properly.</em></p>
<pre class="brush: plain; title: ; notranslate">
nano /etc/dovecot/dovecot.conf 

# specify protocols = imap imaps pop3 pop3s
protocols = pop3 imap
# uncomment this and change to no.
disable_plaintext_auth = no
pop3_uidl_format = %08Xu%08Xv
</pre>
<p>Now, create a user to test our pop3 mail with outlook:</p>
<pre class="brush: plain; title: ; notranslate">
adduser &lt;user_name&gt;
</pre>
<p>Restart Dovecot:</p>
<pre class="brush: plain; title: ; notranslate">
/etc/init.d/dovecot restart
</pre>
<p><strong>Configure SASL Authentication with TLS</strong><br />
SASL Configuration + TLS (Simple authentication security layer with transport layer security) used mainly to authenticate users before sending email to external server, thus restricting relay access. If your relay server is kept open, then spammers could use your mail server to send spam. It is very essential to protect your mail server from misuse.</p>
<p>Let us set up SMTP authentication for our users with postfix and dovecot.</p>
<p>Edit the postfix configuration file /etc/postfix/main.cf and enter the few lines to enable authentication of our users</p>
<pre class="brush: plain; title: ; notranslate">
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = yourdomain.com
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous
</pre>
<p>On the Dovecot side you also need to specify the dovecot authentication daemon socket. In this case we specify an absolute pathname. Refer to this postfix manual here</p>
<p>Edit /etc/dovecot/dovecot.conf</p>
<p>Look for the line that starts with auth default, before that insert the lines below.</p>
<pre class="brush: plain; title: ; notranslate">
auth default {
mechanisms = plain login
passdb pam {
}
userdb passwd {
}
socket listen {
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
}
</pre>
<p>Now, rename previous auth default to auth default2. If you dont rename this then dovecot server will give you error like multiple instances of auth default.</p>
<p>Now restart all the components of mail server.</p>
<pre class="brush: plain; title: ; notranslate">
/etc/init.d/saslauthd restart
/etc/init.d/postfix restart
/etc/init.d/dovecot restart
</pre>
<p><em>NOTE:<br />
1. If you dont enable My server requires authentication in outlook you cannot send emails to external recipients and you get relay access denied error.<br />
2. Do not use root login to login to your mail server.<br />
3. Dont forget to create a new user before you authenticate using outlook.</em></p>
<p><strong>Installing Squirrel Web Mail</strong><br />
Squirrel mail is one of the most popular web based email with very friendly interface. Squirrel mail works without mysql database very easy to install and configure under apache2.</p>
<pre class="brush: plain; title: ; notranslate">
apt-get install squirrelmail
</pre>
<p>Squirrelmail configuration file is located in: /etc/squirrelmail/ folder. By default all settings are preloaded.</p>
<pre class="brush: plain; title: ; notranslate">
# Run squirrelmail configuration utility as ROOT
/usr/sbin/squirrelmail-configure
</pre>
<p>Now we want to setup to run under apache. Edit apache configuration file /etc/apache2/apache2.conf and insert the following line:</p>
<pre class="brush: plain; title: ; notranslate">
Include /etc/squirrelmail/apache.conf
</pre>
<p>Thats it. Your webmail is ready !!! Point your browser to: http://yourdomain/squirrelmail</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2012/02/02/mail-server-installation-on-ubuntu/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2012/02/02/mail-server-installation-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Some Important Linux commands for Newbies</title>
		<link>http://blog.jambura.com/2012/01/20/some-important-linux-commands-for-newbies/</link>
		<comments>http://blog.jambura.com/2012/01/20/some-important-linux-commands-for-newbies/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 08:58:26 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[Create tar.gz file]]></category>
		<category><![CDATA[For allowing sudo]]></category>
		<category><![CDATA[For checking the size of current folder]]></category>
		<category><![CDATA[To add new user]]></category>
		<category><![CDATA[To copy an entire folder]]></category>
		<category><![CDATA[To create new directory]]></category>
		<category><![CDATA[To edit crontab file]]></category>
		<category><![CDATA[To find out the size of the folder in the folder]]></category>
		<category><![CDATA[To find the size of the hdd]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=466</guid>
		<description><![CDATA[My first experience with Linux started when i setuped a server for one my client. It was monumental task for me at that time. I was very happy mouse driven windows user. When I came to the world of putty I was lost. So I had to search for certain commands. I recently written the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2012/01/Linux.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2012/01/Linux.jpg" alt="" title="Linux" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>My first experience with Linux started when i setuped a server for one my client. It was monumental task for me at that time. I was very happy mouse driven windows user. When I came to the world of putty I was lost. So I had to search for certain commands. I recently written the <a href="http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/">Setup LAMP With Ubuntu In 10 Minutes</a>. One of my colleague trie to setup LAMP following that post. He was also  happy mouse driven windows user So he was having problem with commands. So in this post I am showing all the commands I need and used to use Linux server. I will post all the problems i faced using LAMP in next post. Be sure to <a href="http://blog.jambura.com/feed/rss/">subscribe my blog</a>.</p>
<p><strong>To create new directory</strong></p>
<pre class="brush: plain; title: ; notranslate">
mkdir target_director
</pre>
<p><strong>To copy an entire folder (directory tree) in Linux</strong></p>
<pre class="brush: plain; title: ; notranslate">
cp -ap /var/lib/mysql /mnt/mysql -ap for same permission as source
</pre>
<p><strong>For checking the size of current folder</strong></p>
<pre class="brush: plain; title: ; notranslate">
du -ch | grep total
</pre>
<p><strong>To find the size of the hdd</strong></p>
<pre class="brush: plain; title: ; notranslate">
 just enter df
</pre>
<p><strong>To find out the size of the folder in the folder</strong></p>
<pre class="brush: plain; title: ; notranslate">
du
du -a to show all the file's size
</pre>
<p><strong>See all files and their size</strong></p>
<pre class="brush: plain; title: ; notranslate">
du -s * -h
</pre>
<p><strong>To output the number of files in the current directory</strong>	</p>
<pre class="brush: plain; title: ; notranslate">
ls | wc -l
</pre>
<p><strong>See all the jobs</strong></p>
<pre class="brush: plain; title: ; notranslate">
ps -aux
</pre>
<p><strong>To find out RAM size on Linux machine</strong></p>
<pre class="brush: plain; title: ; notranslate">
free
</pre>
<p><strong>Rename folder/filename</strong></p>
<pre class="brush: plain; title: ; notranslate">
mv test hope
mv *.rtf *.txt
</pre>
<p><strong>To find which process is consuming how much RAM?</strong></p>
<pre class="brush: plain; title: ; notranslate">
top
</pre>
<p><strong>To see the free ram memory</strong></p>
<pre class="brush: plain; title: ; notranslate">
free -m
</pre>
<p><strong>To update yum using corn</strong> </p>
<pre class="brush: plain; title: ; notranslate">
0 21 *** usr/bin/yum -y update
</pre>
<p><strong>Create tar.gz file</strong></p>
<pre class="brush: plain; title: ; notranslate">
tar czvf myfolder.tar.gz abcfolder/
</pre>
<p><strong>Untar a tar file</strong><br />
tar czvf myfolder.tar.gz abcfolder/<br />
[/sourcecode]</p>
<p><strong>Delete bash History</strong><br />
Try to delete the content of ~/.bash_history</p>
<p><strong>To add new user</strong><br />
	* Adding a new user (useradd)<br />
    	* Modifying an existing user (usermod)</p>
<p>  Options:<br />
    	* -d home directory<br />
    	* -s starting program (shell)<br />
	    * -p password<br />
	    * -g (primary group assigned to the users)<br />
	    * -G (Other groups the user belongs to)<br />
	    * -m (Create the user&#8217;s home directory</p>
<pre class="brush: plain; title: ; notranslate">
useradd -gusers -Gmgmt -s/bin/shell -pass -d/home/jambura -m jambura
</pre>
<p>User&#8217;s home directory should be 700. If you are operating a ~username type server, the public_html directory should be 777. You may also need to open up the home directory to 755.</p>
<pre class="brush: plain; title: ; notranslate">
 useradd -s/bin/bash -pass -d/imp/sysbsd -m sysbsd
</pre>
<p><strong>For allowing sudo</strong></p>
<pre class="brush: plain; title: ; notranslate">
 sudo adduser jambura admin
</pre>
<p><strong>To delete user</strong></p>
<pre class="brush: plain; title: ; notranslate">
userdel user
</pre>
<p><strong>To display your crontab file</strong></p>
<pre class="brush: plain; title: ; notranslate">
crontab -l
</pre>
<p><strong>root can view any users crontab file by adding &#8220;-u username&#8221;</strong></p>
<pre class="brush: plain; title: ; notranslate">
crontab -u bappy -l  # List bappy's crontab file.
</pre>
<p>*     *     *     *     *  Command to be executed<br />
-     &#8211;     &#8211;     &#8211;     -<br />
|     |     |     |     |<br />
|     |     |     |     +&#8212;&#8211; Day of week (0-6)<br />
|     |     |     +&#8212;&#8212;- Month (1 &#8211; 12)<br />
|     |     +&#8212;&#8212;&#8212; Day of month (1 &#8211; 31)<br />
|     +&#8212;&#8212;&#8212;&#8211; Hour (0 &#8211; 23)<br />
+&#8212;&#8212;&#8212;&#8212;- Min (0 &#8211; 59)</p>
<p>Field          Allowed values<br />
&#8212;&#8211;          &#8212;&#8212;&#8212;&#8212;&#8211;<br />
minute         0-59<br />
hour           0-23<br />
day of month   1-31<br />
month          1-12 (or names, see below)<br />
day of week    0-7 (0 or 7 is Sun, or use names)</p>
<p><strong>To edit crontab file</strong></p>
<pre class="brush: plain; title: ; notranslate">
crontab -e
</pre>
<p>#change the editor used to edit file set the EDITOR environmental variable like this:</p>
<pre class="brush: plain; title: ; notranslate">
export EDITOR=/usr/bin/emacs
</pre>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2012/01/20/some-important-linux-commands-for-newbies/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2012/01/20/some-important-linux-commands-for-newbies/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery, JSON and jTemplates For Ajax driven Web app</title>
		<link>http://blog.jambura.com/2011/12/18/jquery-json-and-jtemplates-for-ajax-driven-web-app/</link>
		<comments>http://blog.jambura.com/2011/12/18/jquery-json-and-jtemplates-for-ajax-driven-web-app/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 17:35:46 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jTemplate]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[jQuery chat example]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[jTemplates]]></category>
		<category><![CDATA[jTemplates for loop]]></category>
		<category><![CDATA[template engine]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=452</guid>
		<description><![CDATA[jQuery is one best and easy JavaScript Library. There are thousand of plug-in to do endless thing to do on the web-page. The best thing is you don&#8217;t have to worry about will this code you written run on ie/opera etc. The Best way to make a web app or website is using Ajax. Obviously [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2011/12/JQUERY_LOGO2.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2011/12/JQUERY_LOGO2-300x300.jpg" alt="" title="jQuery logo" width="200" height="174"  class="alignleft size-medium wp-image-413" /></a>jQuery is one best and easy JavaScript Library. There are thousand of plug-in to do endless thing to do on the web-page. The best thing is you don&#8217;t have to worry about will this code you written run on ie/opera etc. The Best way to make a web app or website is using Ajax. Obviously when you get a HTML using Ajax and replace or add in a HTML element &#8211; it consumes some time which does not look good. There is another solution &#8211; we can use JSON and template engine like jTemplates. jQuery has it own template engine but its beta version. jTemplates is quite easy to understand and develop. Its has conditional structure and also has foreach loop. So you can do a lot of things using this. I have develop many Facebook apps and website using jTemplates. Here is link of chat application show <a href="http://apps.facebook.com/chat-rooms/" target="_blank">http://apps.facebook.com/chat-rooms/</a>. In this tutorial i will show you multiple examples which you can download here. There are couple of functions are not described here &#8211; the main focus of this tutorial is show you the basic things. </p>
<p>Before we start, First download jQuery v1.6.2 and jTemplates from http://jtemplates.tpython.com/. I have used <a href="http://api.jquery.com/delegate/" target="_blank">delegate</a> so use jQuery v1.6.2 instead of latest version. In the latest version delegate is relace by <a href="http://api.jquery.com/on/" target="_blank">on</a>. All the JSON object is retrieved by $T. The template written like this</p>
<pre class="brush: php; title: ; notranslate">
&lt;script type=&quot;text/html&quot; id=&quot;template&quot;&gt;
&lt;/script&gt;
</pre>
<p><strong>The Conditional Statement</strong><br />
In this first example, We will see how the if-else / if-elseif-else work in jTemplates. First let see the php file which we will call in ajax.</p>
<pre class="brush: php; title: ; notranslate">
$return_array['chk']=1;
echo json_encode($return_array);
</pre>
<p>The basic is always same. put all the data in an php array then json_encode the array. We echo the resulting json string.<br />
Then we develop the template</p>
<pre class="brush: php; title: ; notranslate">
&lt;script type=&quot;text/html&quot; id=&quot;template&quot;&gt;
	{#if  $T.chk==0}
		The result is 0
	{#elseif $T.chk==1}
		The result is 1
	{#else}
		The result is not 0 or 1
	{#/if}
 &lt;/script&gt;
</pre>
<p>The code is very simple. The main focus of This code is the $T.chk. As we set the php array like this $return_array['chk'] so chk json object will be available by $T.chk. </p>
<pre class="brush: php; title: ; notranslate">
$(function() {
	$('body').delegate('#click_me', 'click', function (event){
		$.getJSON('/jquery-json-and-jtemplate-for-ajax-driven-web-app/demo-2-ajax.php',{}, function(data)
		{
			$container = $('#result');
			$container.setTemplate($(&quot;#template&quot;).html());
			$container.processTemplate(data);
			$('#result').html($container.html());
		});
	});
});
</pre>
<p>Here is the code where the magic happens <img src='http://blog.jambura.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . $(&#8216;body&#8217;).delegate(&#8216;#click_me&#8217;, &#8216;click&#8217;, function (event){ means when any one click the element which id is click_me then the code snippet will run. <a href="http://api.jquery.com/jQuery.getJSON/" target="_blank">$.getJSON</a> will load the json sting from the server and convert it to json object</p>
<pre class="brush: php; title: ; notranslate">.
$container = $('#result');
$container.setTemplate($(&quot;#template&quot;).html());
$container.processTemplate(data);
$('#result').html($container.html());
</pre>
<p>This the code where all the json datas are put on html template, then using <a href="http://api.jquery.com/html/" target="_blank">html()</a> function to put the html on result div.<br />
You can see this on action <a href="http://fbapps.jambura.com/jquery-json-and-jtemplate-for-ajax-driven-web-app/demo-1.php"  target="_blank">http://fbapps.jambura.com/jquery-json-and-jtemplate-for-ajax-driven-web-app/demo-1.php</a></p>
<p><strong>The Loop foreach</strong><br />
Let first see the php code</p>
<pre class="brush: php; title: ; notranslate">
for($i=0;$i&lt;20;$i++)
{
	$imgs[$i]['img']='http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo.jpg';
	$imgs[$i]['name']='Ubuntu_'.$i;
}
$return_array['images']=$imgs;
echo json_encode($return_array);
</pre>
<p>The code is just add name and img in array. Then that array put in images key in $return_array array.</p>
<pre class="brush: php; title: ; notranslate">
&lt;table  width=&quot;261&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;&gt;
{#foreach $T.images as image}
    {#if $T.image$iteration == 0 || ($T.image$iteration%2)==0}
        &lt;tr&gt;
    {#/if}
    &lt;td width=&quot;130&quot; align=&quot;center&quot;&gt;{$T.image.name}&lt;/td&gt;
    &lt;td width=&quot;130&quot; align=&quot;center&quot;&gt;
        &lt;a href=&quot;{$T.image.img}&quot;&gt;&lt;img width=&quot;200&quot; height=&quot;178&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;{$T.image.img}&quot;&gt;&lt;/a&gt;
    &lt;/td&gt;
    {#if ($T.image$iteration%2)==1}
        &lt;/tr&gt;
    {#/if}
{#/for}
&lt;/table&gt;
</pre>
<p>Here the foreach code is same as php&#8217;s foreach. $iteration &#8211; id of iteration (next number begin from 0). The delegate code is same  </p>
<pre class="brush: php; title: ; notranslate">
$(function() {
	$('body').delegate('#click_me', 'click', function (event){
		$.getJSON('/jquery-json-and-jtemplate-for-ajax-driven-web-app/demo-2-ajax.php',{}, function(data)
		{
			$container = $('#result');
			$container.setTemplate($(&quot;#template&quot;).html());
			$container.processTemplate(data);
			$('#result').html($container.html());
		});
	});
});
</pre>
<p>You can see this on action <a href="http://localhost:8888/jquery-json-and-jtemplate-for-ajax-driven-web-app/demo-2.php"  target="_blank">http://localhost:8888/jquery-json-and-jtemplate-for-ajax-driven-web-app/demo-2.php</a></p>
<p>You can get more details about the jTemplates <a   target="_blank" href="http://jtemplates.tpython.com/">here</a>. You can download the code from <a href='http://blog.jambura.com/wp-content/uploads/2011/12/jquery-json-and-jtemplate-for-ajax-driven-web-app.zip'>jquery-json-and-jtemplate-for-ajax-driven-web-app</a>.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2011/12/18/jquery-json-and-jtemplates-for-ajax-driven-web-app/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2011/12/18/jquery-json-and-jtemplates-for-ajax-driven-web-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu Linux Setup and Configure a Domain Name Server Using BIND</title>
		<link>http://blog.jambura.com/2011/12/18/ubuntu-linux-setup-and-configure-a-domain-name-server-using-bind/</link>
		<comments>http://blog.jambura.com/2011/12/18/ubuntu-linux-setup-and-configure-a-domain-name-server-using-bind/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 08:42:57 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[BIND]]></category>
		<category><![CDATA[Setup and Configure a Domain Name Server]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=382</guid>
		<description><![CDATA[Recently i had to setup a LAMP server for one of client. As usual I chose Ubuntu. I setup the The LAMP. You can view the Setup LAMP With Ubuntu In 10 Minutes. Then my client wanted to setup domain on that server. So start searching for easy to setup domain name on Ubuntu server.So [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo-300x274.jpg" alt="" title="Ubuntu-logo" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>Recently i had to setup a LAMP server for one of client. As usual I chose Ubuntu. I setup the The LAMP. You can view the <a href="http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/" target="_blank">Setup LAMP With Ubuntu In 10 Minutes</a>. Then my client wanted to setup domain on that server. So start searching for easy to setup domain name on Ubuntu server.So i found out about BIND. Its pretty sweet DNS software. As I am using Ubuntu then setting it up will be one line code <img src='http://blog.jambura.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br /></br><br /></br><br /></br><br /></br><br />
<strong>Step # 1: Install BIND</strong><br />
First you need to install BIND server.<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ sudo apt-get install bind9
</pre>
</p>
<p><strong>Step # 2: Define foo.com domain</strong><br />
You need to add foo.com domain to bind configuration file /etc/bind/named.conf.local</p>
<p>Open this file and append following text (zone and reverse zone for foo.com):<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ sudo nano /etc/bind/named.conf.local
</pre>
</p>
<p>Add foo.com zone:<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
zone &quot;foo.com&quot; {
        type master;
        file &quot;/etc/bind/zones/foo.com.zone&quot;;
        };

zone &quot;1.55.202.in-addr.arpa&quot; {
     type master;
     file &quot;/etc/bind/zones/rev.1.55.202.in-addr.arpa&quot;;
};
</pre>
</p>
<p>Save the file.</p>
<p><strong>Step # 3: Create a /etc/bind/zones/ directory</strong><br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ sudo mkdir /etc/bind/zones
</pre>
</p>
<p><strong>Step # 4: Create a zone file for foo.com domain</strong><br />
Now create a zone file /etc/bind/zones/foo.com.zone<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ sudo nano /etc/bind/zones/foo.com.zone
</pre>
</p>
<p>Append following text:<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
foo.com. IN      SOA     ns1.foo.com. admin.foo.com. (
          2006071801
          28800
          3600
          604800
          38400 )
foo.com. IN      NS      ns1.foo.com.
foo.com. IN      MX     10 mta.foo.com.

www           IN      A       202.55.1.2
mta              IN      A       202.55.1.2
ns1               IN       A        202.55.1.2
</pre>
</p>
<p>Create the reverse zone file:<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ sudo nano /etc/bind/zones/rev.1.55.202.in-addr.arpa
</pre>
</p>
<p>Append following text<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
@ IN SOA ns1.foo.com. admin.foo.com. (
                        2006071801; serial
                        28800; refresh, seconds
                        604800; retry, seconds
                        604800; expire, seconds
                        86400 ); minimum, seconds

                     IN  NS ns1.foot.com.

2                  IN      PTR    foo.com
</pre>
</p>
<p>Save the file and restart the BIND server:<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ sudo /etc/init.d/bind9 restart
</pre>
</p>
<p>Test it:<br />
Code:</p>
<pre class="brush: php; title: ; notranslate">
$ nslookup foo.com

Server: 202.55.1.2
Address: 202.55.1.2#53

Name: foo.com
Address: 202.55.1.2
</pre></p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2011/12/18/ubuntu-linux-setup-and-configure-a-domain-name-server-using-bind/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2011/12/18/ubuntu-linux-setup-and-configure-a-domain-name-server-using-bind/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Add Your Own Validation in model On CakePHP</title>
		<link>http://blog.jambura.com/2011/10/26/add-your-own-validation-in-model-on-cakephp/</link>
		<comments>http://blog.jambura.com/2011/10/26/add-your-own-validation-in-model-on-cakephp/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 19:27:00 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[array_key_exists]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[Custom Validation]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[Own Validation]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=428</guid>
		<description><![CDATA[Update: Here is model file to download Download Code CakePHP has many validation rules that can make model data validation much easier. There are 26 core validation rules. You can see here. These 26 rules almost covers all the validation. You can also add multiple validation to one field. But some time you need your [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update:</b>  Here is model file to download <a href="http://blog.jambura.com/wp-content/uploads/2011/10/models.zip"><strong>Download Code</strong></a><br />
<br />
<a href="http://blog.jambura.com/wp-content/uploads/2011/08/cakephp_logo_250_trans.png"><img src="http://blog.jambura.com/wp-content/uploads/2011/08/cakephp_logo_250_trans.png" alt="" title="cakephp_logo_250_trans" width="150" height="150" class="alignleft size-full wp-image-311" /></a>CakePHP has many validation rules that can make model data validation much easier. There are 26 core validation rules. You can see <a href="http://book.cakephp.org/view/1181/Adding-your-own-Validation-Methods#!/view/1152/Core-Validation-Rules">here</a>. These 26 rules almost covers all the validation. You can also add multiple validation to one field. But some time you need your own validation or you need to check a value dependent on other value then you need your own validation. </p>
<p>
<p>
<p>
Lets build our scenario. We have a user table and we have user type table. There are two types of user one is admin and other is user i.e normal user. Now in user table we only save username only for admin. if we set validation notempty for username field then CakePHP will validate username even for normal user. This does not suit us. So we need custom validation. lets build our user model.</p>
<pre class="brush: php; title: ; notranslate">
class User extends AppModel {
	var $name = 'User';
	var $validate = array(
		'name' =&gt; array(
			'notempty' =&gt; array(
				'rule' =&gt; array('notempty'),
				'message' =&gt; 'Please enter first name',
				//'allowEmpty' =&gt; false,
				//'required' =&gt; false,
				//'last' =&gt; false, // Stop validation after this rule
				//'on' =&gt; 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'UserType' =&gt; array(
			'className' =&gt; 'UserType',
			'foreignKey' =&gt; 'user_type_id',
			'conditions' =&gt; '',
			'fields' =&gt; '',
			'order' =&gt; ''
		)
	);
}
</pre>
</p>
<p>Here a added a not empty validation for name field and also we made HABTM relation with user_type table. lets add username field in model. </p>
<pre class="brush: php; title: ; notranslate">
class User extends AppModel {
	var $name = 'User';
	var $validate = array(
		'name' =&gt; array(
			'notempty' =&gt; array(
				'rule' =&gt; array('notempty'),
				'message' =&gt; 'Please enter first name',
				//'allowEmpty' =&gt; false,
				//'required' =&gt; false,
				//'last' =&gt; false, // Stop validation after this rule
				//'on' =&gt; 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'username' =&gt; array(
			'custom' =&gt; array(
				'rule' =&gt; array('validateDependentFields'),
				'message' =&gt; 'Please enter height',
				//'allowEmpty' =&gt; false,
				//'required' =&gt; false,
				//'last' =&gt; false, // Stop validation after this rule
				//'on' =&gt; 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
}
</pre>
</p>
<p>Now lets build our custom function validateDependentFields. This function will have a parameter which will have the field name. One import thing to remember is that we will have all the post data in $this->data in this function. Lets think user_type_id=1 is for admin and user_type_id=2 is user.</p>
<pre class="brush: php; title: ; notranslate">
function validateDependentFields($field){
	$passed=true;
	switch(true){
		case array_key_exists('username',$field):
			if(  $this-&gt;data['User']['user_type_id']==1 and (!isset($this-&gt;data['User']['username']) or empty($this-&gt;data['User']['username'])) ){
				$passed=false;
			}else{
				$passed=true;
			}
		break;
	}
	return $passed;
}
</pre>
</p>
<p>This function will now check for the user type and then decide about the username field. You can check for other validation here. We can use this function for multiple fields.</p>
<pre class="brush: php; title: ; notranslate">
function validateDependentFields($field){
	$passed=true;
	switch(true){
		case array_key_exists('username',$field):
			if(  $this-&gt;data['User']['user_type_id']==1 and (!isset($this-&gt;data['User']['username']) or empty($this-&gt;data['User']['username'])) ){
				$passed=false;
			}else{
				$passed=true;
			}
		break;
		case array_key_exists('class_of',$field):
			if(  $this-&gt;data['User']['user_type_id']==1 and (!isset($this-&gt;data['User']['class_of']) or empty($this-&gt;data['User']['class_of'])) ){
				$passed=false;
			}else{
				$passed=true;
			}
		break;
	}
	return $passed;
}
</pre>
</p>
<p><strong> Easy, simple and highly customizable. </strong></p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2011/10/26/add-your-own-validation-in-model-on-cakephp/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2011/10/26/add-your-own-validation-in-model-on-cakephp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Setup LAMP With Ubuntu In 10 Minutes</title>
		<link>http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/</link>
		<comments>http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 08:10:23 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=415</guid>
		<description><![CDATA[I love Debian/Ubuntu based Linux because of this command apt-get. As a starter knowing this one command, It is so easy to install packages and you dont need to worry about package dependency and configuration. I first come use Ubuntu when i start using Amazon&#8217;s ec2. I was amazed how easily i can build up [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2011/10/Ubuntu-logo-300x274.jpg" alt="" title="Ubuntu-logo" width="200" height="174" class="alignleft size-medium wp-image-413" /></a>I love Debian/Ubuntu based Linux because of this command apt-get. As a starter knowing this one command, It is so easy to install packages and you dont need to worry about package dependency and configuration. I first come use Ubuntu when i start using Amazon&#8217;s ec2. I was amazed how easily i can build up a server. I am going to show how easy LAMP setup really is. I assume you have a Ubuntu setup-ed server and <a href="http://the.earth.li/%7Esgtatham/putty/latest/x86/putty.exe">PuTTy</a>.Note: Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server.</p>
<p>Before proceeding to install, update the necessary packages with Debian with this command.</p>
<pre class="brush: php; title: ; notranslate">
 apt-get update
</pre>
</p>
<p><strong>1. Installing Apache + PHP</strong><br />
To install PHP5, just run the following on Linux shell. Note that if you dont specify packages with &#8217;4&#8242;, PHP5 will be automatically installed.</p>
<pre class="brush: php; title: ; notranslate">
apt-get install apache2 php5 libapache2-mod-php5
</pre>
</p>
<p>Apache configuration file is located at: /etc/apache2/apache2.conf and your web folder is /var/www</p>
<p>To check whether php is installed and running properly, just create a test.php in your /var/www folder with phpinfo() function exactly as shown below.</p>
<pre class="brush: php; title: ; notranslate">
nano /var/www/test.php
</pre>
</p>
<p>And write this</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php phpinfo(); ?&gt;
</pre>
<p>Point your browser to http://ip.address/test.php or http://domain/test.php and this should show all your php configuration and default settings.<br />
To enable GD Enter this </p>
<pre class="brush: php; title: ; notranslate">
apt-get install php5-gd
</pre>
</p>
<p>To enabling mod rewrite with .htaccess </p>
<pre class="brush: php; title: ; notranslate">
a2enmod rewrite
</pre>
</p>
<p>Then open the apache config </p>
<pre class="brush: php; title: ; notranslate">
nano /etc/apache2/sites-enabled/000-default
</pre>
</p>
<p>Change AllowOverride none to AllowOverride All</p>
<pre class="brush: php; title: ; notranslate">
&lt;Directory /var/www/&gt;
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
&lt;/Directory&gt;
</pre>
</p>
<p><strong>2. Installing MySQL Database Server </strong><br />
The following commands will install mysql 5 server and mysql 5 client.</p>
<pre class="brush: php; title: ; notranslate">
apt-get install mysql-server mysql-client php5-mysql
</pre>
</p>
<p>To install PhpMyAdmin use the following code</p>
<pre class="brush: php; title: ; notranslate">
apt-get install phpmyadmin
</pre>
</p>
<p>Then restart Apache</p>
<pre class="brush: php; title: ; notranslate">
/etc/init.d/apache2 restart
</pre>
</p>
<p>Now When you develop web app or sites you need more packages then the default installation for that use the following command</p>
<pre class="brush: php; title: ; notranslate">
apt-get install curl libcurl3 libcurl4-openssl-dev php5-curl php5-mcrypt php5-xmlrpc
</pre>
</p>
<p>To install pear  use the following command</p>
<pre class="brush: php; title: ; notranslate">
apt-get install php-pear
</pre>
</p>
<p>How much time did it take &#8211; less than 10 Minutes right.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2011/10/18/setup-lamp-with-ubuntu-in-10-minutes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How To Setup SSL On Ubuntu</title>
		<link>http://blog.jambura.com/2011/10/10/how-to-setup-ssl-on-ubuntu/</link>
		<comments>http://blog.jambura.com/2011/10/10/how-to-setup-ssl-on-ubuntu/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 10:09:03 +0000</pubDate>
		<dc:creator>Zakir Hyder</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.jambura.com/?p=408</guid>
		<description><![CDATA[This the second part of the SSL setup tutorial. Before reading this make sure you have followed the step shown How To Create A Certificate Signing Request (CSR) For SSL. In This tutorial i am assuming you have only one domain and no sub-domains on the server. By now you have domainname.com.key,domainname.com.csr and domainname.com.crt file. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jambura.com/wp-content/uploads/2011/10/ssl_certificate_private1.jpg"><img src="http://blog.jambura.com/wp-content/uploads/2011/10/ssl_certificate_private1.jpg" alt="" title="ssl certificate" width="215" height="215" class="alignleft size-full wp-image-396" /></a>This the second part of the SSL setup tutorial. Before reading this make sure you have followed the step shown <a href="http://blog.jambura.com/2011/10/04/how-to-create-a-certificate-signing-request-csr-for-ssl/">How To Create A Certificate Signing Request (CSR) For SSL</a>. <strong>In This tutorial i am assuming you have only one domain and no sub-domains on the server</strong>. By now you have domainname.com.key,domainname.com.csr and domainname.com.crt file. Another crt file is provided by SSL certificate issuer companies which is called <strong>Intermediate Certificate</strong>. If you dont have it ask your provider to give it to you. </p>
<p>Now put all the certificate files in ~/domainname.com.ssl/ folder. First we will check is the ssl port which is 443 is open or not. </p>
<pre class="brush: php; title: ; notranslate">
 nano /etc/apache2/ports.conf
</pre>
</p>
<p>It should be like following command. If not then add the following code in the ports.conf file</p>
<pre class="brush: php; title: ; notranslate">
Listen 80
&lt;IfModule mod_ssl.c&gt;
    Listen 443
&lt;/IfModule&gt;
</pre>
</p>
<p>Now we are going to copy the default setting for the ssl .</p>
<pre class="brush: php; title: ; notranslate">
cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
</pre>
<p>Now we going add some lines to the ssl file so that apache will know where to find  the certificates for SSL.<br />
First lets open the file</p>
<pre class="brush: php; title: ; notranslate">
nano /etc/apache2/sites-available/ssl
</pre>
<p>Now the file looks like this </p>
<pre class="brush: php; title: ; notranslate">
NameVirtualHost *
&lt;VirtualHost *&gt;
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        &lt;Directory /&gt;
</pre>
</p>
<p>Now We going to make some changes so that the SSL file looks like the following </p>
<pre class="brush: php; title: ; notranslate">
NameVirtualHost *:443
&lt;VirtualHost *:443&gt;
        ServerAdmin webmaster@localhost
        SSLEngine On
        SSLCertificateFile /root/domainname.com.ssl/domainname.com.crt
        SSLCertificateKeyFile /root/domainname.com.ssl/domainname.com.key
        SSLCertificateChainFile /root/domainname.com.ssl/PositiveSSLCA.crt
        DocumentRoot /var/www/
</pre>
</p>
<p>PositiveSSLCA.crt is the intermediate SSL certificate. Now we are going to enable the ssl and reload the apache server.</p>
<pre class="brush: php; title: ; notranslate">
a2enmod ssl
/etc/init.d/apache2 force-reload
/etc/init.d/apache2 restart
</pre>
</p>
<p>See this so simple. But to implementing SSL with ip-based is quite a work. I will post about this next week. Be sure to subscribe the blog.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="medium" count="1" href="http://blog.jambura.com/2011/10/10/how-to-setup-ssl-on-ubuntu/"></g:plusone></div><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://blog.jambura.com/2011/10/10/how-to-setup-ssl-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Object Caching 1331/1541 objects using disk: basic

Served from: blog.jambura.com @ 2012-05-20 15:14:58 -->
