<?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/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://shahidz.com</link>
	<description>Passionate About Technology</description>
	<lastBuildDate>Wed, 18 Aug 2010 07:03:54 +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>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>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>
		<item>
		<title>404 Error &#8211; File Not Found</title>
		<link>http://shahidz.com/custom-404-error-page-file-not-found/</link>
		<comments>http://shahidz.com/custom-404-error-page-file-not-found/#comments</comments>
		<pubDate>Fri, 23 May 2008 16:25:51 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Micellanious]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[cferror]]></category>
		<category><![CDATA[error page]]></category>
		<category><![CDATA[file not found]]></category>
		<category><![CDATA[rewriteengine]]></category>
		<category><![CDATA[rewriterule]]></category>

		<guid isPermaLink="false">http://shahidz.com/?p=24</guid>
		<description><![CDATA[The 404 or Not Found error message is an HTTP standard response code indicating that the client was able to communicate with the server but either the server could not find what was requested, or it was configured not to fulfill the request and not reveal the reason why. 404 errors should not be confused [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>404</strong> or <strong>Not Found</strong> <a href="http://en.wikipedia.org/wiki/Error_message" title="Error message">error message</a> is an <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" title="Hypertext Transfer Protocol">HTTP</a> <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes" title="List of HTTP status codes">standard response code</a> indicating that the <a href="http://en.wikipedia.org/wiki/Web_Browser" class="mw-redirect" title="Web Browser">client</a> was able to communicate with the server but either the server could not find what was requested, or it was configured not to fulfill the request and not reveal the reason why. 404 errors should not be confused with &#8220;<a href="http://en.wikipedia.org/wiki/Web_server" title="Web server">server</a> not found&#8221; or similar errors, in which a connection to the destination server cannot be made at all.</p>
<p>If you request a non existent page on a server .It will not show up your normal Apache custom 404 page.</p>
<p>A trick to show a custom page ( eg: cferror.cfm ) when a non existant cfm page is accessed. This can be done with the <strong>.htaccess</strong> file. <strong>.htaccess</strong>                is a regular text file that contains &#8220;scripts&#8221; that allow                you to override certain things on your server &#8211; like creating a                custom 404 error document that replaces the server&#8217;s default 404                document.</p>
<p><strong>Method 1</strong></p>
<p>To be able to create your own 404 error document, first you need                to create the actual document (use your HTML editor of choice or                hand code it if you like), upload the document to the root directory                on your server, and finally include the following in your document root <strong>.htaccess</strong>                file:</p>
<pre>ErrorDocument 404 http://www.yourdomain.com/404.html</pre>
<ul></ul>
<p><strong> Method 2</strong></p>
<p>Add the following entry to the .htaccess file in your DocumentRoot</p>
<pre>RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /cferror.cfm?%{REQUEST_URI}</pre>
<p>All request to the non existent pages are passed to cferror.cfm page with the requested URL as argument.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fcustom-404-error-page-file-not-found%2F&amp;linkname=404%20Error%20%26%238211%3B%20File%20Not%20Found"><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/custom-404-error-page-file-not-found/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
