serving legacy PHP apps alongside Pow Feb 3, 2014
I have started using Pow lately, which I have avoided for a long time, without any explicit reasoning. Now that I have actually tried it, I can definitely say that using Pow is really a breeze, and is really powerful at the same time. Before this, I used to run Phusion Passenger for my needs, and while that was a lot more powerful, it was a lot more fuss for my naive needs.
Now, Pow is really great for Rack based applications, but does not work well enough with other applications, e.g. the ones using PHP. What makes it worse is that the default Pow configuration takes over the port 80, and thereby, my Apache server will never be hit. Great.
I, quickly, googled some stuff and found a way to make Apache and Pow play
nicely with each other, and at the same time remove the need for
which I am, currently, using to resolve arbitrary top-level domains. This post
contains my notes on this topic.
The first step we need to perform is to uninstall Pow, if it is already installed. That way, we make sure that nothing interferes with our setup.
1 curl get.pow.cx/uninstall.sh | sh
Add Configuration for Pow
We will tell Pow to use the port 3100, instead of taking over port 80, and let
the poor Apache be. Furthermore, I will tell Pow to resolve a number of TLDs to
1 2 echo 'export POW_DST_PORT=88' >> ~/.powconfig echo 'export POW_DOMAINS=dev,pow,lab,test' >> ~/.powconfig
From the above list of TLDs, we want
pow to serve applications
using Pow, while
test will be serving Apache based applications
using VirtualHost directives.
Adding Apache VirtualHosts
First, we will tell Apache to pass any requests for
pow TLDs to
Pow using reverse proxy:
1 2 3 4 5 6 7 8 <VirtualHost *:80> ServerName pow ServerAlias *.dev *.pow *.xip.io ProxyPass / http://localhost:20559/ ProxyPassReverse / http://localhost:20559/ ProxyPreserveHost On </VirtualHost>
Having done that, we tell Apache to serve up the remaining TLDs from a particular directory:
1 2 3 4 5 <VirtualHost *:80> ServerName lab ServerAlias *.lab *.test VirtualDocumentRoot "/Users/nikhgupta/Code/legacy-apps/%1" </VirtualHost>
Now, make sure that the above directives are being served up by Apache by
including them in your
httpd.conf somewhere, somehow.
Apache will use the above VirtualHost directives upon restart/reload:
1 sudo apachectl restart
All that remains is to install Pow:
1 curl get.pow.cx | sh
Oh, yes, this is my favorite. Simply, install Powder to further simplify your life.
1 gem install powder
For starters, I can serve up any rack based application by simply running
powder list in that directory, and then access it using
appname.pow. And, this also works for static websites as well e.g.
Jekyll (note that, this requires that the current
directory has a
public sub directory which contains an
Moreover, my old Apache configurations run without any implications. And, therefore, I can keep on working on applications that are served using PHP.
Effectively, I can run a ruby/rails based application in a single step by
powder link, and a php application in zero steps by simply placing it
at the correct location.