PHP gallery Ruby port part 1

Yesterday I told about rack-legacy. I started new project https://github.com/samitheberber/galleria and will write the progress in here.

I had old PHP application with my own "framework". My route dispatching wasn't bullet proof, so I needed to patch it a little. Patching was few oneliners in few places to get all edge cases to work. At first I used rack-rewrite to direct all requests to PHP. Initial step is completed.

Next I created public directory and moved assets there. Then I rewrote assets rewrite rule and application was back in action. It was time to get sinatra in use. To do so I had to change my generic rewrite rule to specify each route I had in use. If rewrite rule matches, PHP will handle it and if not, sinatra will do the rest. After that is was possible to remove public rewrite rule and let sinatra provide public directory functionality.

Next I need to replace rewrite routes one by one with sinatra routes. At first I replace my json "API", because it doesn't need any UI writing and I can create application core parts, like models. The progress will be visible in GitHub and I will provide url for the result when I get it deploy ready :)


Ruby and legacy applications

This post isn't about JRuby + Rails + Spring (or other Java web frameworks) like my first intuition would tell to me.

I'm currently helping my friend to renew her website and I was looking looking for pow-like application for PHP, because didn't want full apache on my laptop. I googled and found way to run PHP website in pow. This operation is possible with rack-legacy gem.

rack-legacy provides middleware where you can run legacy php and cgi in rack stack. gem is in alpha state and in production you should use apache or some other server software for performance. For my local development environment this suited perfectly.

What did I want to do then. Well I wanted to have PHP powered website running on my local environment without too much configuration. I also wanted quick way to show currently working site to my friend and she isn't a technical person so git cloning wasn't the answer. So I wrote this config.ru-file, which runs index.php with correct parameters in every request. Symbol link under the .pow dir and I got undulaatit.dev site visible on my laptop. I have used localtunnel before so it was first choice this time too. rackup and localtunnel 9292 ftw. I pasted localtunnel url to my friend and she could see my changes in real time.

I think I find this approach useful in future too. I have done lots of stuff in PHP before moved to Ruby and some of the stuff I have planned to port in Ruby as well. Now I can do the migrations in little parts. At first using rack-rewrite to direct all request to PHP. Then I take one page, write it in Ruby and don't redirect it to PHP. Now the functionality stays same all the time, but the implementation changes under the hood.

Feel free to leave a comment about this kind of approach to rewrite legacy applications in Ruby.

PS. rack-rewrite is heroku friendly http://icelab.com.au/articles/useful-heroku-friendly-rewrites-with-rack-rewrite/

Long silence ends

Hi, I'm going to write now own more often. The subjects are going to be from things I face on developing by working or in free time.

This blog also has new address http://blog.samisaada.com Setting dns-records is one of the new things I have learned in one and half years.

My blog will mainly keep on geeky stuff, but maybe I will write about not so geeky stuff too :) I'm not good writer so I have prefered micro-blogging lately with twitter and it wont go anywhere. I hope this writing will help me to express myself more clearly, also in verbal way.