Related tags
Making FirePHP Accessible to Every PHP Page
I heart FireBug. I loved FireBug so much, I even made a simple Ruby on Rails plugin to log to FireBug, called FireBug Logger.
It was rudimentary, but it did its job. Lucky for me, a similar project exists in the PHP world, appropriately labelled FirePHP.
FirePHP
FirePHP is bit fancier, in that it can format the output that is sent to the FireBug console. But because of this feature, it requires to be installed as a Firefox extension.
This post will not discuss on the benefits of using FirePHP, or how to install it. There are lots more material available out there on that.
Making FirePHP Easily Accessible
Sadly to get FirePHP available to every PHP script, you are required to call the code to load FirePHP (fb.php). But this is not necessarily true.
In your php.ini, there is an option called auto_prepend_file which will automatically include a PHP file before executing the requested PHP file.
So with this can call load FirePHP prior to any execution, and thus making it accessible via any script that is executed.
Lets enable the auto_prepend_file and give it a value to another PHP file.
auto_prepend_file = /Users/aizat/src/firephp/firephp.php
Don't forget to restart your Apache, else your changes won't be applied!
Now inside /Users/aizat/src/firephp/firephp.php, I will require the main FirePHP library like so:
<?php
require_once('lib/FirePHPCore/fb.php');
if (php_sapi_name() != 'cli' && ini_get('output_buffering') == false) {
ob_start();
}?>
Make sure that the require_once on line 3 points to the location of the fb.php.
require_once('lib/FirePHPCore/fb.php');
Testing
Now lets test it with a very simple file. Create a php file and dump this inside:
<?php
fb("auto_prepend_file successfully worked!", FirePHP::LOG);
?>
Open the file in your web browser, and it should load successfully!
There you have it, easy debugging without manually requiring the FirePHP libraries, and accessible in all PHP files. What more do you want?
Why I Support Free Culture
So I got an interesting comment the other day from James.
Hey aizat,
I have been reading your blog for over a year and I was just wondering, why do you support open source technology?
Why?
What a great question. Many readers, friends, families, colleagues alike are probably wondering the same thing.
But I won't stop at there. I'll answer the bigger question.
Why I support Free Culture
This is because Free Culture, encompasses all things that I have been involved in. Free and Open Source Software, Open Content, and Open Standards. And they are all interrelated with one another.
One line answers

Let's ignore the economical benefits of Free Culture, and just look at the personal benefits.
The one line (and non philanthropic) answer: Because I have benefited from Free Culture, and I know that others can benefit as well.
The philanthropic answer: Because it's the right thing to do.
Now, most readers probably aren't satisfied with that. So let's continue.
A discrete answer
Free Culture gave me the ability to remix, to hack, to build upon, to enhance, to study, to learn off existing works.
If you look at the definition of Free Cultural Works, there are four key points that stand out.
- the freedom to use the work and enjoy the benefits of using it
- the freedom to study the work and to apply knowledge acquired from it
- the freedom to make and redistribute copies, in whole or in part, of the information or expression
- the freedom to make changes and improvements, and to distribute derivative works
All of these are beneficial to a person to let them learn on their own and experiment.

It's like making everyone a kid with scissors and glue, and letting them make their own collages, from what is already out there.
I myself have defined Free Culture to be:
The empowerment of the individual through the collaboration of the many, through the free sharing of knowledge
The background to the answer
[block:warning]Warning: Reminiscing about the past. Point, and or topic may be lost somewhere along the way.[/block]
I will cover.
- Education
- Community Involvement
- Jobs
- Other Gains
My Education
I've previously written about the effects of FOSS on my education last year on the Open Malaysia Blog. Continue on if you want to read a more up to date version.
My programming, technical, computer science, IT, whatever-you-guys-want-to-classify-it skills were built on Free and Open Source Software. My parents purchased me one of the first G4 iMacs (yes the one that looks like a lamp), and at the time getting software (even pirated ones) was difficult and inaccessible to me. I knew at the time that the new Mac OSX was running this 'Unix' thing, but to be honest, I wasn't so sure what it was.
Having a natural interest in computers, I signed up for the IB HL Programming Class in High School, where I attempted to learn C++. That went bad, and I mean really bad. I learned nothing out of it. I struggled with the concepts of classes and objects. Simply put I learned nothing. Now, it could be for many reasons. It could be the lecturer, or it could be myself. But I really tried for this one. I loved computers, so I tried.
![]()
In my childhood days I created websites on Geocities. Eager to return to making websites again, I noticed that most websites ended in ".php" and started investigating from there.
During my investigation I realized that my computer was already setup for web development. So I continued further. Apache and PHP was already setup on the machine. Now the remaining part, was the database.
I was treading unfamiliar ground here. I've heard of people using MySQL, and thus, well I wanted to try as well. Back then I got it running via DarwinPorts, which was a great repository of software for me.
Found tutorials online, and just messed and messed and messed around. Downloaded lots of FOSS projects off the Internet just to study how to do things. One day it finally dawned on me, how classes and objects worked. One project I remember looking at profusely was PHPBB, because at the time it was a very popular PHP Forum.
Running into problems with styling issues, looks and feel, I dropped out of using Dreamweaver and began looking at other WYSIWYG tools. Realizing that most of those tools were complete crap, I decided to jump straight into the code itself. And picked up Eclipse, where I would later pick up vim.
I also got employed to do some PHP work, so that was cool, especially with no formal education on programming.
But I hadn't graduated from College/University yet, and I was pushing it back. In the end, I had to bite the bullet.
I applied to several places Monash University (ironically) , and Nottingham to name a few. But none of them accepted me, due to my lack luster results in High School. I wasn't a very good student. Even the recommendation from my employers didn't help.
![]()
Luckily one college did accept me, and I got enrolled into APIIT, a supposedly good college for computer science. I even got to skip foundation year. Joy! (sarcasm)
To be honest, I feared entering APIIT, because I was afraid that by skipping my foundation year, I would be behind the other students. I would have alot to catch up on. I've had no formal education on programming, everything I know had been self taught. I felt that I would be handicapped.
That first week was a real eye opener it was for me. Those fears were quickly dissolved, and I realized that I wasn't handicapped at all. I knew a far greater amount of programming than these people did.
Shortly after starting APIIT, I also got introduced to the MyOSS gang via a PHP Meetup, and later the MyOSS Meetups. I thought the PHP meetups would be a great opportunity to see other interested (and hopefully like minded individuals).
Another eye opener. I learned so many things that day. But there is one person who left a strong impression on me, and is a good friend of mine now, Ditesh. That day Ditesh showed off some of the coolest things with PHP that I didn't even think of was possible. That night, feeling impressed by the wide range of technical skills that the small group had, I took to attending the MyOSS meetup.
I remember that day. Straight after college, in my APIIT 'uniform', I drove to KL, parked my car and was the first one to arrive. One by one people started pouring in. I was introduced to Khairil, Prabu, and a few others.
I was simply overwhelmed with the wealth of information that these people had, and I am still learning from many of them. I'll discuss more about my involvement in MyOSS in a later section.
Over the course of my first year, APIIT couldn't satisfy my hunger for knowledge. Plus I believed APIIT had many problems. I took it to myself with the exorbitant amounts of free time studying at APIIT gave, to learn the ins and outs. Getting advice from people in MyOSS and what not.
I managed to pass APIIT with flying colors, and at ease. Something I had never done before in the history of my education. How was this possible?
There was a long break between the 1st and 2nd year of APIIT. Something like four months. With even more free time on my hands I decided to try something different. Exploring C, OpenGL, SDL, Python and Ruby.
![]()
![]()
Many of you can guess what I ended up using
. That's right, Ruby.
I found Ruby to be interesting, unique, different, and fun. So once again, back to my lessons learned from learning PHP, I downloaded code, and poured over them profusely. And aligning back to my web development background, I picked up Ruby on Rails.
I've ran into many problems with Ruby on Rails, and every time I would dive in Rails source code, and look at how it works, and figured out how to fix my bug.
Over the course of these months, I assisted with the Asia Open Source Symposium and got involved slightly with the Malaysia - United States Free Trade Agreement.
![]()
Soon after my 2nd year started, I would drop out of APIIT, and enroll into Monash University, which coincidently finally accepted me, and gave me a high number of credits (I heard maximum) for my APIIT results. I didn't carry the same fear I had when I entered APIIT, infact I was expecting a challenge. How little I knew...
Here was the opportunity to see how a renowned university students skills would fare against mine. When I arrived the impression I got, and still believe is that Monash University students are a lot better than APIIT.
In the end Monash University was alot more difficult than APIIT, and it did provide a challenge for me. I finally got the opportunity to learn something.
Then the moment arrived, where I would have a chance to pit my skills against not just my peers, but other people (situated in Kuala Lumpur at least). The eGenting Programming Competition.
I knew I was good. The question was, how good? I've only seen a limited pool to test with. This was the way to solve it. This was the way to see how through my own education, by downloading, and studying FOSS, I fare against a larger set of people, and I think we all know the results.

I got 1st place. There are others who took the competition who have been trying it for many years already. This was my first time. There are even graduates, and master students taking part.
One comment I'm fond of is (somewhere along the lines of):
How did you do that, you don't learn databases until year 2
Year 2. I'm only a 1st year student.
As can be seen the freedom to let me just take code online, read it, study it, remix it, hack it, has been extremely beneficial to me in terms of my education. This code can be just not any code, but code from professionals working in the fields, so I can build off and learn from their experience. Learn why they made the design choices they did.
Community Involvement
See my slides about the local community
By getting involved with MyOSS, I got the chance to mingle with professionals and to learn from them. They have been a catalyst for my knowledge about FOSS, and amongst other things.

Similarly when joining the Open Document Format Special Interest Group, I got to learn many things about the politics in technology amongst a host of other things. Things which seemed to make absolutely no sense a year ago, is now clearly understood. Kudos to Hasan, and the rest of the gang.
The unintended result of joining these, is that more people know who I am.
Jobs
I have received jobs from United Nations Development Program International Open Source Network. Though the job may "appear" like little to many, I still get to put them as a client under my resume
. Similarly I got payed for Rapporteur-ing the AsiaOSS Symposium last year. I similarly have gotten a job for doing Rails development.
Plus the Job Offer from eGenting for winning first place.
Getting paid for what you enjoy, how much better can it be?
Similarly, as I'm not done yet with university, so what other opportunities will open up for me?
Other Gains

In the interest of being knowledgeable about my current stance towards the norm. I took up to learning the issues of Copyright, Software Patents, Digital Restrictions Management, Technology Protection Measures, Intellectual Property Rights, and even Contract Law.
Yes, Contract Law. Something completely not even related to Technology.
Why did I learn these? Well besides from being knowledgeable, being involved in FOSS, articles concerning these topics will continually arise, and you are kept aware of what is happening in the technological world.
Cons
Yes there are is one con I can think of.
People think you are older than you look.
For example, a few weeks ago, a lady thought I was 29.
Last year, a friend asked me "So how old is your daughter?" After seeing pictures of me and my sister together.
So if you two people feel ashamed, don't worry, I've gotten other people making the same statements.
Conclusion
As can (hopefully) be seen, I have benefited greatly from Free Culture, and I am not the only one who shares this experience. Even the FLOSS World Survey seems to correlate well with my own personal findings.
Having the ability to access, create, modify, is the major key factor. Without the ability to procure the large amounts of source code out there, I simply would not have been able to learn on my own.
I am only one example, of how Free Culture has benefited me. There are hundreds, probably thousands, if not millions more.
This is not just about the software. Even leading institutions such as MIT are releasing their coursework under a Creative Commons license.
Want to bridge the digital divide? Want to help build local capacity? Want to build the local economy? I believe Free Culture is the solution. May not be the end all solution, but it will help to play a large part.
If there are things left unanswered. Please post up a comment, and I'll update the post.
Deploying Ruby on Rails on Ubuntu Feisty Fawn via Mongrel Cluster and Apache
Note:
- A quick, down and dirty solution. There are more verbose resources on how to setup Mongrel Cluster and Apache. But this is also specifically tailored for Ubuntu Feisty Fawn.
- After installing mongrel, when executing
./script/server, you will not useWebrickanymore, but insteadmongrelfor development. You can still useWebrickif you want, but there isn't much of a difference.
Plan of Attack
- Install, configure, and test Mongrel Cluster
- Install and test Apache
- Start Mongrel Cluster on boot
Installing Mongrel Cluster
sudo apt-get install ruby1.8-dev sudo gem install -y mongrel mongrel_cluster
Note: If you see the following make sure you select the latest version of mongrel for ruby. In this case option 2.
Select which gem to install for your platform (i486-linux)
1. mongrel 1.0.1 (mswin32)
2. mongrel 1.0.1 (ruby)
3. mongrel 1.0 (mswin32)
4. mongrel 1.0 (ruby)
5. Skip this gem
6. Cancel installation
>
Configuring Mongrel Cluster
Go to your Rails application directory and execute:
mongrel_rails cluster::configure -p 8000 -n 3
This allows mongrel to spawn 3 instance to handle the load. Each instance will open on port 8000, and succeeding. So that is 8000, 8001, and 8002.
Note: The mongrel_rails command has alot of options. Executing mongrel_rails -h will get you more information. All of these options can be changed later.
This will create the a mongrel_cluster configuration file in RAILS_ROOT/config/mongrel_cluster.yml 
Testing Mongrel Cluster
In your Rails application directory, execute:
mongrel_rails cluster::start
Now open up http://localhost:8000/, http://localhost:8001/, and http://localhost:8002/ to ensure that your site is working perfectly fine.
Installing Apache
Enter into the Terminal:
sudo apt-get install apache2 sudo a2enmod proxy_balancer sudo a2enmod proxy_http sudo a2enmod rewrite
We will now create a common rails configuration file. As root open up /etc/apache2/mods-available/rails.conf
, and insert the following:
ServerName railsapp.com
DocumentRoot /var/www/railsapp.com/public
<Directory "/var/www/railsapp.com/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
# Uncomment for rewrite debugging
#RewriteLog logs/railsappapp_rewrite_log
#RewriteLogLevel 9
# Check for maintenance file and redirect all requests
# ( this is for use with Capistrano's disable_web task )
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/css
# ... text/xml application/xml application/xhtml+xml text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Uncomment for deflate debugging
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog logs/myapp_deflate_log deflate
Now we'll set up the virtual host for our site railsapp.com For the last time as root open up /etc/apache2/sites-available/railsapp
and insert the following:
Listen 8080
<VirtualHost *:8080>
<Location />
SetHandler balancer-manager
Deny from all
Allow from localhost
</Location>
</VirtualHost>
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>
<VirtualHost *:80>
Include /etc/apache2/mods-available/rails.conf
ErrorLog /var/log/apache2/rails_errors_log
CustomLog /var/log/apache2/rails combined
</VirtualHost>
The first VirtualHost enables a front end for load balancing, available only to localhost on port 7999.
The second VirtualHost is our rails application. Notice how it is pulling in our default configuration (/etc/apache2/mods-available/rails.conf
). If you want to make changes you can specify it here. Need to specify a ServerName directive? Put it in here.
Lets enable the virtual host
sudo a2ensite railsapp
and restart Apache.
sudo /etc/init.d/apache2 restart
Now pull up your the domain you entered and your Rails application should load!
Note: If you can't seem to access your site, its because the default virtual host has a higher precedence. Execute sudo a2dissite default
. Similarly ensure that you are access your site via the domain you specified in the ServerName directive. In this case railsapp.com
If everything is work, you are on your way to more production based hosting solution.
Start Mongrel Cluster on Boot
Create mongrel_cluster conf directory (/etc/mongrel_cluster).
sudo mkdir /etc/mongrel_cluster
In the Mongrel Cluster gem, there is an init.d script you need to copy.
sudo cp /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster/mongrel_cluster /etc/init.d
Now let's make the script executable.
sudo chmod +x /etc/init.d/mongrel_cluster
Now we need to add th init.d script to startup.
On Ubuntu:
sudo update-rc.d mongrel_cluster defaults
On RHEL/CentOS:
/sbin/chkconfig --level 345 mongrel_cluster on
Now create a symbolic link from RAILS_ROOT/config/mongrel_cluster.yml to a file in /etc/mongrel_cluster:
sudo ln -s /path/to/railsapp/config/mongrel_cluster.yml /etc/mongrel_cluster/railsapp
There you have it, you should be good to go!
Comments, bugs, problems, improvements
Have any bug, or problem? Leave a comment please.
