<?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>PHP on Trax Blog</title>
	<atom:link href="http://blog.phpontrax.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.phpontrax.com</link>
	<description>Rapid Application Development Made Easy</description>
	<lastBuildDate>Mon, 13 Dec 2010 15:24:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to make an open source load balancer (stunnel + haproxy)</title>
		<link>http://blog.phpontrax.com/2010/02/how-to-make-an-open-source-load-balancer-stunnel-haproxy/</link>
		<comments>http://blog.phpontrax.com/2010/02/how-to-make-an-open-source-load-balancer-stunnel-haproxy/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 15:39:58 +0000</pubDate>
		<dc:creator>johnpipi</dc:creator>
				<category><![CDATA[How To's]]></category>

		<guid isPermaLink="false">http://blog.phpontrax.com/?p=42</guid>
		<description><![CDATA[Our current setup we have multiple application and static content servers serving our ecommerce shopping software Veracart.  Instead of spending thousands of dollars on an expensive load balancer appliance we decide to go the open source route.  After looking at many different solutions what we finally ended up going with for our load [...]]]></description>
			<content:encoded><![CDATA[<p>Our current setup we have multiple application and static content servers serving our <a href="http://www.veracart.com">ecommerce shopping software</a> <a href="http://www.veracart.com">Veracart</a>.  Instead of spending thousands of dollars on an expensive load balancer appliance we decide to go the open source route.  After looking at many different solutions what we finally ended up going with for our load balancer machine is <a href="http://www.stunnel.org">stunnel</a> for the ssl decryption and <a href="http://haproxy.1wt.eu">haproxy</a> for the actual load balancing.  stunnel is need because haproxy doesn&#8217;t support ssl in http mode.</p>
<p><strong>Load balancer hardware:</strong> 1U, dual Intel Xeon 2.80GHz cpu&#8217;s, 4gigs of ram, sata drives.<br />
<strong>Software:</strong> freebsd (or linux), stunnel 4.32 with xforwarded-for patch, haproxy 1.4.8</p>
<h2><span style="text-decoration: underline;">Stunnel Installation</span></h2>
<p>First off if you want your web servers in your clusters to be able to know the connecting clients real ip address instead of the load balancers then you need to patch stunnel with xforwarded-for patch.</p>
<p>wget http://www.stunnel.org/download/stunnel/src/stunnel-4.32.tar.gz<br />
wget http://haproxy.1wt.eu/download/patches/stunnel-4.32-xforwarded-for.diff<br />
tar -zxvf stunnel-4.32.tar.gz<br />
cd stunnel-4.32<br />
patch -p1 < ../stunnel-4.32-xforwarded-for.diff<br />
./configure<br />
make &#038;&#038; make install</p>
<h2><span style="text-decoration: underline;">Haproxy Installation</span></h2>
<p>download: <a href="http://haproxy.1wt.eu/#down">http://haproxy.1wt.eu/#down</a><br />
or<br />
cd /usr/ports/net/haproxy (from freebsd ports)<br />
make &#038;&#038; make install</p>
<h2><span style="text-decoration: underline;">Stunnel Configuration</span></h2>
<p>Stunnel will receive all the https connections on port 443 and forward as http requests to haproxy on port 81 (or any port you want).   From there haproxy will send the http request to the webserver cluster.  Below the ip 1.2.3.4 represents your public ip that will goto your cluster.  You can have as many [secure.domain.com] sections as you want or have domains with ssl certs for.</p>
<p><strong>stunnel.conf</strong></p>
<pre class="brush: plain;">
sslVersion = all
options = NO_SSLv2
setuid = root
setgid = stunnel
pid = /var/run/stunnel.pid
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
output = /var/log/stunnel.log

[secure.domain.com]
cert = /usr/local/openssl/certs/secure.domain.com.crt
key = /usr/local/openssl/private/secure.domain.com.key
accept  = 1.2.3.4:443
connect = 1.2.3.4:81
xforwardedfor = yes
TIMEOUTclose = 0
</pre>
<h2><span style="text-decoration: underline;">Haproxy Configuration</span></h2>
<p>Haproxy will receive the decrypted https request, now just an http request, from stunnel on port 81.  It will then load balance those requests across however many servers you have listed.  I forward the request to port 81 on our apache webservers.</p>
<p><strong>haproxy.conf</strong></p>
<pre class="brush: plain;">
global
	daemon
	maxconn 10000
	nbproc 2
	log 127.0.0.1 syslog

defaults
	log global
	clitimeout 60000
	srvtimeout 30000
	contimeout 4000
	retries 3
	option redispatch
	option httpclose
	option abortonclose

listen domain_cluster_http 1.2.3.4:80
	mode http
	balance roundrobin
	cookie SERVERID insert nocache
	option forwardfor except 1.2.3.4
	reqadd X-Forwarded-Proto:\ http
	server server1 10.1.1.2:80 cookie s1 weight 1 maxconn 5000 check
	server server2 10.1.1.3:80 cookie s2 weight 1 maxconn 5000 check

listen domain_cluster_https 1.2.3.4:81
	mode http
	balance roundrobin
	cookie SERVERID insert nocache
	option forwardfor except 1.2.3.4
	reqadd X-Forwarded-Proto:\ https
	server server1 10.1.1.2:81 cookie s1 weight 1 maxconn 5000 check
	server server2 10.1.1.3:81 cookie s2 weight 1 maxconn 5000 check	

listen  lb1_stats [load balancer's public ip]:80
	mode http
	stats uri /
	stats auth username:password
	#stats refresh 5s
</pre>
<h2><span style="text-decoration: underline;">Apache Configuration</span></h2>
<p>Lastly there is some things you will want to do to apache so it will know the real clients ip address.  What I use is <a href="http://stderr.net/apache/rpaf">mod_rpaf</a>,  which changes the remote address of the client visible to other Apache modules from the X-Forwarded-For header.  On freebsd there is a port for this.</p>
<p>cd /usr/ports/www/mod_rpaf2<br />
make &#038;&#038; make install</p>
<p>This will install the Apache2 version.  After its installed open up your Apache&#8217;s http.conf file and add the following lines.</p>
<p><strong>httpd.conf</strong></p>
<pre class="brush: plain;">
# if DSO load module first:
LoadModule rpaf_module libexec/apache2/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips [load balancer's ip]
RPAFheader X-Forwarded-For
</pre>
<p>Next since we are forwarding https request to our webserver cluster nodes on port 81 we need to add the following line to http.conf</p>
<p><strong>httpd.conf</strong></p>
<pre class="brush: plain;">
Listen 81
</pre>
<h2><span style="text-decoration: underline;">Conclusion</span></h2>
<p>We don&#8217;t have a huge amount of traffic about a steady 5Mbps, and the load balancer is always idling along with barely any load at all.  This has worked out great for us.  All the ssl decrypting is off loaded from the web servers and haproxy is super fast and has a great stats page to see what&#8217;s going on with your cluster&#8217;s.  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phpontrax.com/2010/02/how-to-make-an-open-source-load-balancer-stunnel-haproxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Trax with EasyPHP (Windows)</title>
		<link>http://blog.phpontrax.com/2009/12/setting-up-trax-with-easyphp-windows/</link>
		<comments>http://blog.phpontrax.com/2009/12/setting-up-trax-with-easyphp-windows/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 05:12:03 +0000</pubDate>
		<dc:creator>johnpipi</dc:creator>
				<category><![CDATA[Installation]]></category>

		<guid isPermaLink="false">http://blog.phpontrax.com/?p=3</guid>
		<description><![CDATA[I soon found out that EasyPHP isn&#8217;t so easy to get PEAR and commandline php working.  Hopefully this will help people that are unfortunately stuck on windoze and want to use EasyPHP to develop their php apps.  I may look at WAMP next to see if it&#8217;s any easier.  As well will [...]]]></description>
			<content:encoded><![CDATA[<p>I soon found out that EasyPHP isn&#8217;t so easy to get PEAR and commandline php working.  Hopefully this will help people that are unfortunately stuck on windoze and want to use EasyPHP to develop their php apps.  I may look at WAMP next to see if it&#8217;s any easier.  As well will make a guide for setting up OSX and Trax which is what I use personally.</p>
<p>1. <a title="Download easyPHP" href="http://www.easyphp.org/download.php" target="_blank">Download</a> and install easyPHP 5.3.0.</p>
<p>2. EasyPHP&#8217;s version of PEAR is jacked.  To fix it, right click here on  <a href="http://pear.php.net/go-pear.phar">go-pear.phar</a> and save it to “<strong>C:\Program Files\EasyPHP5.3.0\php\PEAR</strong>”.  Just overwriting the existing go-pear.phar file.</p>
<p>3.  Open a command window (Start -&gt; Run, type cmd) and</p>
<pre class="brush: plain;">cd C:\Program Files\EasyPHP5.3.0\php</pre>
<p>4.  Install PEAR. In command window type <strong>go-pear</strong>.</p>
<p>5.   Now edit C:\Program Files\EasyPHP5.3.0\php\pear.bat file and change the line toward the top from this:</p>
<pre class="brush: plain;">IF &quot;%PHP_PEAR_PHP_BIN%&quot;==&quot;&quot; SET &quot;PHP_PEAR_PHP_BIN=.\php.exe&quot;</pre>
<p>to this:</p>
<pre class="brush: plain;">IF &quot;%PHP_PEAR_PHP_BIN%&quot;==&quot;&quot; SET &quot;PHP_PEAR_PHP_BIN=C:\Program Files\EasyPHP5.3.0\php\php.exe&quot;</pre>
<p>6.  Edit your system path so you can run commandline commands without putting in the complete path.</p>
<ul>
<li>Right-click <strong>My Computer</strong> and click <strong>Properties</strong>.</li>
<li><!--StartFragment-->In the System Properties window, click on the <strong>Advanced</strong> tab.</li>
<li><!--StartFragment-->In the Advanced section, click the <strong>Environment Variables</strong> button.</li>
<li>In the Environment Variables window, highlight the <strong>Path</strong> variable in the Systems Variable section and click the <strong>Edit</strong> button. Add the path &#8220;<strong>;C:\Program Files\EasyPHP5.3.0\php</strong>&#8221; to the end of whatever is in there already but be sure to have the &#8220;;&#8221; separating the addition from the old path.</li>
</ul>
<p>7.  Open a new command window.  If you type in now &#8220;<strong>php -v</strong>&#8220;  you should show the version of php you are running in my case 5.3.0.  Next type &#8220;<strong>pear</strong>&#8221; and you should see a bunch of output about pear options.</p>
<p>Now everything up until this point was just to get pear and php installed working from the commandline. <img src='http://blog.phpontrax.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   Now lets install PHP on Trax.</p>
<p>8.  Install Trax.  Instructions can be found <a title="Installing Trax" href="http://www.phpontrax.com/downloads" target="_blank">here</a>.  Following the instructions on that page you do the following commands.</p>
<p>First add the Trax channel server:</p>
<pre class="brush: plain;">pear channel-discover pear.phpontrax.com</pre>
<p>Next install Trax:</p>
<pre class="brush: plain;">pear install trax/PHPonTrax</pre>
<p>Lastly if you are using mysql you can run:</p>
<pre class="brush: plain;">pear install -f pear/MDB2#mysql</pre>
<p>9. Last thing to do is make a <strong>trax.bat</strong> file and place it in the folder C:\Program Files\EasyPHP5.3.0\php.  The file contents will be the one line below.</p>
<pre class="brush: plain;">php &quot;C:\Program Files\EasyPHP5.3.0\php\PEAR\PHPonTrax\trax.php&quot; %1</pre>
<p>To verify your Trax install is working at the commandline type</p>
<pre class="brush: plain;">trax -v</pre>
<p>You should see the output Trax 0.16.0</p>
<p>If you want to start making an app cd into the directory for your project and type:</p>
<pre class="brush: plain;">trax .</pre>
<p>This will generate all the basic files needed to make a new Trax app.</p>
<p>That&#8217;s it now you should be ready to start making Trax apps!</p>
<p>Edit: Also need to change some Apache/PHP configurations.  Right click the e icon next to the time.  Then goto Configuration =&gt; Apache.  This will open up the httpd.conf file for Apache.</p>
<p>1.  uncomment the line:</p>
<pre class="brush: plain;">LoadModule rewrite_module modules/mod_rewrite.so</pre>
<p>2.  Scroll to the bottom and add the following replacing &#8220;c:/projects/traxtest/public&#8221; with the correct path to your trax public folder for your app:</p>
<pre class="brush: plain;">
NameVirtualHost *:80
&lt;VirtualHost *:80&gt;
    DocumentRoot &quot;c:/projects/traxtest/public&quot;
    ServerName localhost
	&lt;Directory &quot;c:/projects/traxtest/public&quot;&gt;
		Options FollowSymLinks Indexes
		AllowOverride All
		Order deny,allow
		Allow from 127.0.0.1
		deny from all
	&lt;/Directory&gt;
&lt;/VirtualHost&gt;
</pre>
<p>Next edit PHP Configuration.  Right click the e and go to Configuration => PHP.  Change the following lines:</p>
<pre class="brush: plain;">
short_open_tag = On
error_reporting = E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED
</pre>
<p>In Trax Edit two files.<br />
1.  In your app&#8217;s public folder the .htaccess file make sure that the seperator on the include_path is a &#8220;;&#8221; and not a &#8220;:&#8221; and that the path to your app&#8217;s config folder is correct.</p>
<pre class="brush: plain;">php_value include_path .;C:\projects\traxtest\config</pre>
<p>2.   In your app&#8217;s config folder edit the environment.php file and uncomment and set the PHP_LIB_ROOT constant.</p>
<pre class="brush: plain;">define(&quot;PHP_LIB_ROOT&quot;,    &quot;C:\Program Files\EasyPHP5.3.0\php\PEAR&quot;);</pre>
<p>Then in your browser you should be able to goto the url:  http://localhost  and see the default trax welcome page.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.phpontrax.com/2009/12/setting-up-trax-with-easyphp-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

