<?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>Linux, Programming, Telephony, Asterisk, Apache, Tips &#38; Tricks &#187; Apache</title>
	<atom:link href="http://shahidz.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://shahidz.com</link>
	<description>Passionate About Technology</description>
	<lastBuildDate>Sun, 10 Jan 2010 17:38:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>URL Redirecting (301,302) in Varnish</title>
		<link>http://shahidz.com/url-redirecting-301302-in-varnish/</link>
		<comments>http://shahidz.com/url-redirecting-301302-in-varnish/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 17:37:04 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[302]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[url redirection]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[vcl]]></category>

		<guid isPermaLink="false">http://shahidz.com/url-redirecting-301302-in-varnish/</guid>
		<description><![CDATA[There is no straight forward method for 301/302 URL redirection as we did with rewrite rule. But there are some situations where we need to redirect a URL on a host to some URL on different host. In this situation we need to use 301/302 redirection.  There are two ways we can implement this.
First method [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">There is no straight forward method for 301/302 URL redirection as we did with <a href="http://shahidz.com/apache-url-rewriting/" title="Rewrite Rule" target="_blank">rewrite rule</a>. But there are some situations where we need to redirect a URL on a host to some URL on different host. In this situation we need to use 301/302 redirection.  There are two ways we can implement this.</p>
<p align="justify">First method is to use  <em>set req.http.host</em> and <em>set req.url</em> in the vcl.conf file. Using these two methods we perform normal redirection. Using these method we will redirect the url to some other URL on the same host. For example say the URL http://example.com/error500.php will be redirect to the URL http://example.com/redirect.php. We specify 301/302 redirection to the URL http://foo.com/index.php in the redirect.php file using header method.</p>
<ul>
<li>In the sub vcl_recv method use the following code.</li>
</ul>
<pre>sub vcl_recv {
   if (req.http.host ~ "example.com") {
      if (req.url ~ "error500.php") {
         set req.http.host = "example.com";
         set req.url = "/redirect.php";
      }
   }
}</pre>
<ul>
<li>In the redirect.php file use the following method.</li>
</ul>
<pre>&lt;?php
header("HTTP/1.1 302 Moved Temperarly");
header('Location:http://foo.com/index.php');
exit;
?&gt;</pre>
<p>Second method is to use <em>vcl_error</em> error method. In this error method we can specify HTML tags, so using meta tags we can implement redirection. This option is available with the latest version of varnish.</p>
<ul>
<li>In the sub vcl_recv method use the following code.</li>
</ul>
<pre>sub vcl_recv {
   if (req.http.host ~ "example.com") {
      if (req.url ~ "error500.php")
         error;
      }
   }
}
sub vcl_error {
        set obj.http.Content-Type = "text/html; charset=utf-8";
        if (req.http.host ~ "example.com") {
                if (req.url ~ "error500.php") {
                        synthetic {"
                                &lt;?xml version="1.0" encoding="utf-8"?&gt;
                                &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
                                &lt;html&gt;
                                        &lt;head&gt;
                                                &lt;meta http-equiv="refresh" content="0;url=http://foo.com/index.php"&gt;
                                        &lt;/head&gt;
                                &lt;/html&gt;
                        "};
                }
        }
        deliver;
}</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Furl-redirecting-301302-in-varnish%2F&amp;linkname=URL%20Redirecting%20%28301%2C302%29%20in%20Varnish"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/url-redirecting-301302-in-varnish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logrotate in linux</title>
		<link>http://shahidz.com/logrotate-in-linux/</link>
		<comments>http://shahidz.com/logrotate-in-linux/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 06:17:18 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[logrotate]]></category>

		<guid isPermaLink="false">http://shahidz.com/logrotate-in-linux/</guid>
		<description><![CDATA[Logrotate
Log files are important for Linux system security and trouble shooting.  Log files tend to grow, and if a log grows too much you compress it and takes the backup. Logrotate enables you to do this in a much better way. The process that is in charge of compressing and rotating these logfiles is called [...]]]></description>
			<content:encoded><![CDATA[<h2>Logrotate</h2>
<p>Log files are important for Linux system security and trouble shooting.  Log files tend to grow, and if a log grows too much you compress it and takes the backup.<span style="font-size: 85%"><span style="font-family: arial"></span></span> Logrotate enables you to do this in a much better way. The process that is in charge of compressing and <em>rotating</em> these logfiles is called <tt>logrotate</tt> and it is executed once per day upon Debian installations.</p>
<p>Here you will find the <tt>logrotate</tt> driver script. Every day this script runs and examines two things:</p>
<ul>
<li>The configuration file <em><tt>/etc/logrotate.conf</tt></em></li>
<li>The configuration directory <em><tt>/etc/logrotate.d/</tt></em></li>
</ul>
<p>A typical logrotate configuration file looks like this:</p>
<pre>/var/log/apache/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if [ -f /var/run/apache.pid ]; then
                        /etc/init.d/apache restart &gt; /dev/null
                fi
        endscript
}</pre>
<p>If you want to add new log rotate for any other file you can new <em>logrotate</em> configuration file to <em>/etc/logrotate.d</em> <em><tt> </tt></em></p>
<p>Assuming we have a new service &#8220;mon&#8221; which produces its output in <tt>/var/log/mon/mon.log</tt> we can cause this to be rotated every day with a script like this:</p>
<pre>/var/log/mon/*.log {
  daily
  missingok
  rotate 7
  compress
  delaycompress
  create 640 mon mon
  sharedscripts
     /etc/init.d/mon restart
  endscript
}</pre>
<p>For more help <em>man logrotate</em></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Flogrotate-in-linux%2F&amp;linkname=Logrotate%20in%20linux"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/logrotate-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Load Balance Using Haproxy</title>
		<link>http://shahidz.com/apache-load-balance-using-haproxy/</link>
		<comments>http://shahidz.com/apache-load-balance-using-haproxy/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 17:25:32 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[acl]]></category>
		<category><![CDATA[apache load balance]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[load balance]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://shahidz.com/apache-load-balance-using-haproxy/</guid>
		<description><![CDATA[Haproxy
HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation [...]]]></description>
			<content:encoded><![CDATA[<h1><strong>Haproxy</strong></h1>
<p>HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.</p>
<h2><strong>1. Preperation</strong></h2>
<p>For configuring haproxy you need the following setups. Here I used ACL.</p>
<h3>1.1. Using ACL</h3>
<p>The use of Access Control Lists (ACL) provides a flexible solution to perform content switching and generally to take decisions based on content extracted from the request, the response or any environmental status. The principle is simple</p>
<h3>1.2. Load Balancer</h3>
<p>Hostname: <span class="system">lb.example.com</span></p>
<p>IP: <span class="system">192.168.0.110</span></p>
<h3>1.3 Web Server 1</h3>
<p>Hostname: <span class="system">http1.example.com</span></p>
<p>IP: <span class="system">192.168.0.111</span><span class="system"></span></p>
<h3>1.4. Web Server 2</h3>
<p>Hostname: <span class="system">http2.example.com</span></p>
<p>IP: <span class="system">192.168.0.112</span></p>
<h3>1.5. First download and install haproxy</h3>
<p>To get latest version click <a href="http://haproxy.1wt.eu/#down" title="Download Haproxy" target="_blank">here </a></p>
<pre>$ wget  http://haproxy.1wt.eu/download/1.2/src/haproxy-1.2.18.tar.gz
$ tar -xzvf haproxy-1.2.18.tar.gz
$ cd  haproxy-1.2.18
$ sudo make  TARGET=linux24</pre>
<h3><strong> 1.6. Configuring Load Balancer System IP : <span class="system">192.168.0.110</span></strong></h3>
<p>set <em><strong><span class="system">E</span></strong><span class="system">NABLED</span></em> to <em><span class="system">1</span></em> in <em><span class="system">/etc/default/haproxy</span></em></p>
<pre> $ sudo vim /etc/default/haproxy</pre>
<pre># Set ENABLED to 1 if you want the init script to start haproxy.

ENABLED=1

# Add extra flags here.
#EXTRAOPTS="-de -m 16"</pre>
<p>We back up the original <span class="system">/etc/haproxy.cfg</span> and create a new one like this</p>
<pre>cp /etc/haproxy.cfg /etc/haproxy.cfg_orig
cat /dev/null &gt; /etc/haproxy.cfg
vi /etc/haproxy.cfg</pre>
<p>Sample haproxy configuration file<strong> /etc/haproxy.cfg</strong> which uses ACL. In the below example if you use the domain <em>example.com</em> haproxy always uses <strong>web server 1</strong>,if you use <em>loadbalancer.com</em></p>
<pre>global
global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        pidfile /var/run/haproxy.pid
        daemon
#       debug           # If you want to start haproxy in debugging mode uncomment this line and comment the above line.
        nbproc      4   # Number of processing cores. Dual Dual-core Opteron i    s 4 cores for example.
defaults
        log     global
        mode    http
        option  httplog
        option  httpchk
        option  dontlognull
        retries 3
        option          redispatch
        maxconn 2000
        contimeout      50000
        clitimeout      500000
        srvtimeout      500000

backend back_std
        balance roundrobin
        option redispatch
        cookie JSESSIONID prefix
        option httpclose
        option forwardfor
        option httpchk HEAD /check.txt HTTP/1.0
        server ws4 192.168.0.111:82 weight 1 check
#      stats uri /status   # Custom status URI
        stats auth username:password
        stats enable
        stats refresh 10

backend back_lb
        balance roundrobin
        option redispatch
        cookie JSESSIONID prefix nocache indirect
        option httpchk HEAD /check.txt HTTP/1.0
        server ws1 192.168.0.111:81 cookie ws1 weight 1 check
        server ws2 192.168.0.112:81 cookie ws2 weight 1 check
        option httpclose
        option forwardfor
        stats enable
        stats refresh 10

frontend http-in
        bind :80
        acl hosts_std hdr_end(host) -i example1..com          # Which is not load balanced
        acl hosts_std hdr_end(host) -i example1.com:80

        acl hosts_lb hdr_end(host) -i loadbalancer.com      # Which is load balanced
        acl hosts_lb hdr_end(host) -i loadbalancer.com:80

        use_backend back_std if hosts_std       # If requests comes to the domain which is in <em>host_std</em> then that URL will use <em>back_std</em>
        use_backend back_lb if hosts_lb          # If requests comes to <em>the domain which is in host_lb</em> then that URL will use <em>back_lb</em></pre>
<p>To allow HAProxy to bind to the shared IP address, we add the following line to <span class="system">/etc/sysctl.conf</span>:</p>
<pre>$ sudo vim /etc/sysctl.conf</pre>
<pre>[...]
net.ipv4.ip_nonlocal_bind=1
[...]</pre>
<p>and run</p>
<pre>$ sudo sysctl -p</pre>
<h3>1.7 Start haproxy</h3>
<pre>$ sudo /etc/init.d/haproxy start</pre>
<h3><strong>1.8. Configuring </strong><strong>Web Server 1 &amp; </strong><strong>Web Server2</strong></h3>
<p>We will configure HAProxy as a transparent proxy, i.e., it will pass on the original user&#8217;s IP address in a field called <span class="system">X-Forwarded-For</span> to the backend web servers. Of course, the backend web servers should log the original user&#8217;s IP address in their access logs instead of the IP addresses of our load balancers. Therefore we must modify the <span class="system">LogFormat</span> line in <span class="system">/etc/apache2/apache2.conf</span> and replace <span class="system">%h</span> with <span class="system">%{X-Forwarded-For}i</span>:</p>
<pre> $ sudo vim /etc/apache2/apache2.conf</pre>
<pre>#LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
#LogFormat "%{Referer}i -&gt; %U" referer
#LogFormat "%{User-agent}i" agentLogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %&gt;s %b" common
LogFormat "%{Referer}i -&gt; %U" referer
LogFormat "%{User-agent}i" agent</pre>
<p>Also, we will configure HAProxy to check the backend servers health by continuously requesting the file <span class="system">check.txt</span> (translates to <span class="system">/var/www/check.txt</span> if <span class="system">/var/www</span> is your document root) from the backend servers. Of course, these requests would totally bloat the access logs and mess up your page view statistics (if you use a tool like Webalizer or AWstats that generates statistics based on the access logs).</p>
<p>Therefore we open our virtualhost configuration (in this example it&#8217;s in <span class="system">/etc/apache2/sites-available/default</span>) and put these two lines into it (comment out all other <span class="system">CustomLog</span> directives in your vhost configuration):</p>
<pre>$ sudo touch /var/www/check.txt
$ sudo vi /etc/apache2/sites-available/default</pre>
<pre>[...]
SetEnvIf Request_URI "^/check\.txt$" dontlog
CustomLog /var/log/apache2/access.log combined env=!dontlog
[...]</pre>
<p>Adds the ports to <em>/etc/apache2/ports.conf</em> file.</p>
<pre>Listen 81
Listen 82
&lt;IfModule mod_ssl.c&gt;
    Listen 443
&lt;/IfModule&gt;</pre>
<p>Afterwards we restart Apache:</p>
<pre>$ sudo /etc/init.d/apache2 restart</pre>
<p>Now to check the status of haproxy use the custom URI or use <em>http://example1.com/haproxy?stats</em></p>
<p>I hope it helped, a comment with your questions are welcome  <img src='http://shahidz.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fapache-load-balance-using-haproxy%2F&amp;linkname=Apache%20Load%20Balance%20Using%20Haproxy"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/apache-load-balance-using-haproxy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Monitoring services using Mon</title>
		<link>http://shahidz.com/mon/</link>
		<comments>http://shahidz.com/mon/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 12:09:27 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mysql]]></category>

		<guid isPermaLink="false">http://shahidz.com/mon/</guid>
		<description><![CDATA[Monitoring services using Mon
mon is a general-purpose scheduler and alert management tool used for monitoring service availability and
triggering alerts upon failure detection.
Mon uses some Linux command and services such as ping command to check host connectivity and mail servers for sending mail, so you must install postfix and other packages so that mon should work [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Monitoring services using Mon</strong></p>
<p>mon is a general-purpose scheduler and alert management tool used for monitoring service availability and<br />
triggering alerts upon failure detection.</p>
<p>Mon uses some Linux command and services such as ping command to check host connectivity and mail servers for sending mail, so you must install postfix and other packages so that mon should work smoothly.</p>
<p><strong>Installing and configuring Mon in Ubuntu </strong></p>
<p>Now we will see how we can install and configure mon in Ubuntu.</p>
<p><strong>Install process</strong></p>
<pre>$ sudo apt-get install mon</pre>
<p><strong>Start mon </strong></p>
<pre>$ sudo /etc/init.d/mon start</pre>
<p><strong>Configuring Mon </strong></p>
<p>For configuring mon edit the configuration file <strong>/etc/mon/mon.cf</strong></p>
<pre>hostgroup servers 192.168.1.6  #There must be a one line gape after hostgroup line.

watch servers
    service ping
        interval 1m
        monitor fping.monitor
        period wd {Mon-Fri} hr {7am-10pm}
            alert mail.alert user@example.com
            alertevery 3m
        period wd {Sat-Sun}
            alert mail.alert user@example.com</pre>
<p>First we define the hosts that we want to monitor. Then we create the a &#8220;watch&#8221; section for this hosts with only one service to monitor, the <strong>&#8220;ping&#8221;</strong> service. The service will be monitored using the monitor <strong>&#8220;fping.monitor&#8221;</strong> that you can find in &#8220;<strong>/usr/lib/mon/mon.d/fping.monitor&#8221;</strong>. Then we define the periods in which we want to monitor the hosts and the alert we will use if the monitor detects a fail. In this case we use the <strong>&#8220;mail.alert&#8221;</strong> agent that you can find in <strong>&#8220;/usr/lib/mon/alert.d/mail.alert&#8221;</strong>. An email to &#8220;user@example.com&#8221; will be sent if a fail is detected in the monitor.</p>
<p>Sample example for configuring mon for monitoring a host connectivity, mysql, apache and a web page.</p>
<pre>hostgroup ping_services 192.168.1.6

hostgroup webservers itswork.com

hostgroup mysql_server localhost

hostgroup apache_service 192.168.1.6

watch ping_services
service ping
    interval 1m
    monitor fping.monitor
    period wday {Mon-Sun} hour {0-23}
        alert mail.alert user@example.com
        alertevery 1m

watch webservers example.com
service site
        interval 1m
        monitor http.monitor -p 80 -u /index.php
        period wday{Mon-Sun} hr {0am-24pm}
            alert mail.alert user@example.com

watch apache_service 192.168.1.6
service apache
        interval 1m
        monitor http.monitor
        period wday{Mon-Sun} hr {0am-24pm}
            alert mail.alert user@example.com

watch mysql_server
    service mysql
        interval 1m
        monitor mysql.monitor --username=mon --password=mon --database=mon localhost
        period wday {Mon-Sun}
            alert mail.alert -S "Host 1 Mysql Server is down!!" user@example.com
            upalert mail.alert -S "Host1 MYSQL server is back up" user@example.com
            alertevery 60s
            alertafter 3</pre>
<p>For more help click <a href="http://www.us.kernel.org/pub/software/admin/mon/html/man/mon.html" target="_blank">here</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fmon%2F&amp;linkname=Monitoring%20services%20using%20Mon"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/mon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monit a service monitoring tool in linux</title>
		<link>http://shahidz.com/monit/</link>
		<comments>http://shahidz.com/monit/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 10:30:58 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[monitoring apache]]></category>
		<category><![CDATA[monitrc]]></category>

		<guid isPermaLink="false">http://shahidz.com/monit/</guid>
		<description><![CDATA[ Monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://shahidz.com/wp-content/uploads/2008/06/monit-logo.gif" alt="monit-logo.gif" /> <a href="http://www.tildeslash.com/monit/" title="Monit" target="_blank">Monit</a> is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamps changes, checksum changes or size changes.  Monit will monitor a service and in case of any problems monit will will raise an email alert.</p>
<p><strong>Install the package monit using apt on Ubuntu.</strong></p>
<pre>$ sudo apt-get install monit</pre>
<p>First edit the file  <strong>/etc/default/monit</strong> and change <strong>startup=0</strong> to  <strong>startup=1</strong>. The file should look like below text.</p>
<pre># Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Fredrik Steen &lt;stone@debian.org&gt;
# You must set this variable to for monit to start

startup=1

# To change the intervals which monit should run uncomment# and change this variable.
# CHECK_INTERVALS=180</pre>
<p>Edit the monit configuration file<strong> /etc/monit/monitrc</strong> and uncomment the following lines</p>
<pre>$ sudo vim /etc/monit/monitrc</pre>
<p>Start monit in background (run as daemon) and check the services at 2-minute intervals.</p>
<pre>set daemon  120</pre>
<p>You can set the alert recipients here, which will receive the alert for each service. The event alerts may be restricted using the list.</p>
<pre>set alert abc@xyz.com                                   # receive all alerts
set alert hij@xyz.com only on { timeout }       # receive just service-</pre>
<p>Monit has an embedded webserver, which can be used to view the configuration, actual services parameters or manage the services using the web interface.</p>
<pre>set httpd port 2812 and
     use address localhost  # only accept connection from localhost
     allow localhost        # allow localhost to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'</pre>
<p>Next session in the configuration file is where the monit monitors the services,  for that we need to specify the service which needs to be monitored. A sample example for monitoring apache is as follows.</p>
<pre>check process apache with pidfile /var/run/apache2.pid
    start program = "/etc/init.d/apache2 start"
    stop program  = "/etc/init.d/apache2 stop"
    if cpu &gt; 60% for 2 cycles then alert
    if cpu &gt; 80% for 5 cycles then restart
    if totalmem &gt; 200.0 MB for 5 cycles then restart
    if children &gt; 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop
    if 3 restarts within 5 cycles then timeout
    group server</pre>
<p>For more examples click <a href="http://www.tildeslash.com/monit/doc/examples.php" title="Monit Examples" target="_blank">here </a><br />
Next we will see some monit commonds.</p>
<p>To satrt monit</p>
<pre>$ sudo /etc/init.d/monit start</pre>
<p>To start the services which the monit is monitorin, sudo monit start all will start all the services in the monit configuration file, if specify a name insted of start all monit will start only the specified service.</p>
<pre>$ sudo monit start all
$ sudo monit start apache</pre>
<p>To get the status of monit services</p>
<pre>$ sudo monit status</pre>
<p>To get the summary of mont services</p>
<pre>$ sudo monit summary</pre>
<p>To stop all the services monitored my monit use <strong>stop all</strong>, or specify the name of the servive you need to stop</p>
<pre>$ sudo monit  stop all
$ sudo monit stop apache</pre>
<p>For more help click <a href="http://www.tildeslash.com/monit/doc/manual.php" target="_blank">here</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fmonit%2F&amp;linkname=Monit%20a%20service%20monitoring%20tool%20in%20linux"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/monit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Symfony Framework in Ubuntu</title>
		<link>http://shahidz.com/installing-symfony-framework-in-ubuntu/</link>
		<comments>http://shahidz.com/installing-symfony-framework-in-ubuntu/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 16:24:27 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://shahidz.com/installing-symfony-framework-in-ubuntu/</guid>
		<description><![CDATA[Install these packages with apt:
php5
php5-cli
php5-dev
php5-sqlite
php-pear
$ sudo apt-get install php5 php5-cli php5-dev php5-sqlite php-pear
Test if Apache and PHP are up and running typing in the browser:
http://localhost/
You should see something like:
Apache/2.0.55 (Ubuntu) PHP/5.1.2-1ubuntu1 Server at localhost Port 80
From the command line, as root:
$ sudo pear upgrade PEAR
$ sudo pear channel-discover pear.symfony-project.com
Edit /etc/php5/cli/php.ini and change the line:
memory_limit = [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Install these packages with apt:</strong></p>
<p>php5<br />
php5-cli<br />
php5-dev<br />
php5-sqlite<br />
php-pear</p>
<pre>$ sudo apt-get install php5 php5-cli php5-dev php5-sqlite php-pear</pre>
<p>Test if Apache and PHP are up and running typing in the browser:</p>
<p>http://localhost/</p>
<p>You should see something like:</p>
<p>Apache/2.0.55 (Ubuntu) PHP/5.1.2-1ubuntu1 Server at localhost Port 80</p>
<p><strong>From the command line, as root:</strong></p>
<pre>$ sudo pear upgrade PEAR
$ sudo pear channel-discover pear.symfony-project.com</pre>
<p>Edit /etc/php5/cli/php.ini and change the line:</p>
<p>memory_limit = 8M To memory_limit = 16M</p>
<p>Then</p>
<pre>$ sudo pear install symfony/symfony
$ sudo pear install –alldeps http://phing.info/pear/phing-current.tgz</pre>
<style type="text/css">- 		@page { size: 21cm 29.7cm; margin: 2cm } 		P { margin-bottom: 0.21cm } 	--> 	</style>
<p>Using the command:</p>
<pre>$ sudo pear config-show</pre>
<p>we find the symfony libraries have been installed in:</p>
<pre>$ php_dir/symfony/ /usr/share/php/symfony/ main libraries
$ data_dir/symfony/ /usr/share/php/data/symfony/ skeleton of symfony applications, default modules and configuration
$ doc_dir/symfony/ /usr/share/php/docs/symfony/ documentation</pre>
<p>From the command line enter bellow command:</p>
<pre>$ symfony -Vsymfony version 0.6.2</pre>
<p>From the command line, as root:</p>
<pre>$ mkdir /var/www/myproject
$cd /var/www/myproject
$ symfony init-project myproject
$ symfony init-app myapp</pre>
<p>Edit /Virtual Host configuration file , and append the following at the end:</p>
<pre>&lt;VirtualHost 192.168.1.2:81&gt;
ServerAdmin webmaster@localhost
ServerName servername.com
ServerAlias www.servername.com
DocumentRoot /var/www/project/web
Alias /sf /usr/share/php/data/symfony/web/sf
&lt;Directory /var/www/project/web&gt;
     Options FollowSymLinks MultiViews
     AllowOverride all
     Order allow,deny
     allow from all
&lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Finstalling-symfony-framework-in-ubuntu%2F&amp;linkname=Installing%20Symfony%20Framework%20in%20Ubuntu"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/installing-symfony-framework-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
