How to install Laravel to a subdirectory

Simple! Just need to change a setting in the .htaccess file. I am using Laravel 4, you might be using some other version but the method should apply nevertheless. I use an alias to point to this directory.

Add this line “RewriteBase /l4″ to your .htaccess where l4 is your sub directory or folder.

[code language=”php”]<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /l4
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Have fun!

How to install Composer in Windows

I wanted to install PHP Composer in Windows. And to begin, I already have a copy of XAMPP 1.8.1, I think if you have a different way to get your PHP that should not matter. I tested this to work for Windows 7 but it should work for all versions of Windows.

0. Download and install XAMPP

You can download XAMPP here. I got the 7zip version rather than the installer itself. The ZIP version is similar, just with a larger file size. I extract the xampp folder into my C: drive, i.e. to C:xampp. Then install it by opening the file C:xamppsetup_xampp.bat. That will set the paths in XAMPP’s configurations.

1. Setting up environment variables

Continue reading “How to install Composer in Windows”

How to use sudo without a password

This may sound like a bad idea in general but I do this in my testing virtual machine (VM) with Ubuntu or Debian operating systems. It makes it easier to restart servers.

First you need to edit your /etc/sudoers file through:

[code language=”bash”]visudo[/code]

In the editor, locate this:

[code language=”bash”]# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL[/code]

Change to this:

[code language=”bash”]# Allow members of group sudo to execute any command

Now you can use sudo without a password.

How to add Ruby string interpolation highlighting for Sublime

To add Ruby string interpolation highlighting for Sublime Text 2, you need to edit your .tmTheme file. It can be found in your SublimeText 2, go to Preferences, then Browse Packages. This will open up your finder or Windows Explorer. Look for the folder “Color Scheme – Default”, you should be able to find themes like Monokai and others inside.

In order to add the syntax highlight for Ruby’s ${} in strings, for example:

[code language=”ruby”]puts "Working in #{pwd}"[/code]

Open up your .tmTheme file and add the following lines:

[code language=”xml”]
<string>Embedded Ruby Punctuation</string>
<string>string punctuation.section.embedded.ruby</string>
<string>Embedded Ruby Source</string>
<string>string source.ruby.embedded.source</string>

You can change the colors of background and foreground to your liking too. Hope you’ll find this useful!

How to set SVN global ignores

There are some customizations that I make that pertains to my development computer only and because I work in a team environment I cannot commit in things that are customized towards my development environment. In order to do this, I do a global ignore on the file. Here’s how to do a global ignore. The subversion config file for Ubuntu 12.04 LTS or 12.10 is here:

[code language=”bash”]sudo nano /etc/subversion/config[/code]

There is a section that looks like this

[code language=”bash”][miscellany]

Set global-ignores to a set of whitespace-delimited globs

which Subversion will ignore in its ‘status’ output, and

while importing or adding files and directories.

‘ matches leading dots, e.g. ‘.rej’ matches ‘.foo.rej’.

global-ignores = .o *.lo *.la *.al .libs *.so *.so.[0-9] *.a *.pyc *.pyo

.rej *~ ## .#* .*.swp .DS_Store[/code]

You can uncomment that “global-ignores” part.

How to run multiple applications on a single tomcat

I do this in Ubuntu 12.10 but I think it applies to Windows 7 configurations too. I wanted to run more than one application in a single instance of tomcat. I have to say this is not the best decision I have made.

You can load two apps in one server instance if you put them in different directories and have two different host names.

In my case, my two hostnames are and, yours will be different. You can edit your hosts here in your /etc/hosts

Both of my apps would be called app1 and app2. I put them into the corresponding directories, as specified in appBase. In my case, I placed them in:

  • /var/lib/tomcat7/app1
  • /var/lib/tomcat7/app2

You can open up your /etc/tomcat7/server.xml file. In Windows 7, it would be where ever your central tomcat configuration files are at. This is my server.xml file:

[code language=”xml”]<?xml version=’1.0′ encoding=’utf-8′?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />


You can refer to it. Unfortunately I cannot provide much support for this.


Well, this method has a key disadvantage, each time you rebuild your Java classes, you need to restart the server and it would be better to be able to restart one application at a time rather than both applications together due to a longer loading time. Most of the time you will only make changes to one application anyway. It is better to have a configuration with two servers and each of them supporting just one application. That’s my take and I learnt it the hard way.

Too much magic in Java IDEs

I am very bothered by the way a typical Java web site development works. Java website developments, through JSP (Java Server Pages) is largely supported by IDEs such as Eclipse and Netbeans. It is not in any way the easiest to utilize. And at worst these huge IDEs are too kludgy for my liking.

Take the current Java project that I am working on, it’s a website that has sign in and numerous data presentation tools. Everything .java compiles into a .class file and the remaining JSP files are deployed into this WAR file through Apache Maven into tomcat. With an IDE, everything seems seamless. You don’t even need to know how it works. Just by magic. You configure the servers and paths and it just works.

You could of course decide to dump WAR files again and again to the server paths and watch it automatically deploy after you do a manual restart of tomcat. Unfortunately that’s too unproductive, starting a tomcat server takes 2 seconds for me, and starting the application takes 10 seconds in debug mode. That’s unacceptably slow because it all adds up.

So, IDEs make you more productive by deploying the files in the server for you and compiles the .java files into .class and .jar files or something like that. Essentially you only need to restart the tomcat7 server if you updated the controller. Updates to the views do not require compilation. However — there’s always a caveat — you have the .jsp file edited on the server path rather than your workspace.

Now, under the hood of the IDE, each time you save a .jsp file, what you are essentially doing is:

  1. Saving the file in your workspace.
  2. Copying the file from your workspace to the server path.

Your workspace can be managed by revisioning tools such as SVN or git and the remnants don’t get copied over to the server space. It’s pretty well thought except that you really need a proper IDE set up to save you all theĀ repetitiveĀ work.

So the reason why I am writing this is because I wanted to use Sublime Text and Sublime Text doesn’t have Java and tomcat integration features at all. At first this seemed surprising, after all Java is so common. Upon discovering what Eclipse and Netbeans actually does, I can’t help but to feel that there is a certain amount of over-engineering.

Forgive me if that’s not the way Java IDEs work. I’m uncovering new things every day still, so please correct my mistakes, I want to understand the platform better too.

Tomcat paths in Ubuntu 12.10

And so I have the displeasure of working with Java — a platform I once swear to avoid for the rest of my life — and I had to have my Ubuntu 12.10 environment set up. This is also verified to be similar in Ubuntu 12.04.

If you install tomcat7 from the official repository using “sudo apt-get install tomcat7”, the following paths and commands are probably helpful to you too.

Your WAR files

WAR files (.war) typically go into:

[code language=”bash”]/var/lib/tomcat7/webapps[/code]

Your log files

Your log files should be here:

[code language=”bash”]/var/lib/tomcat7/logs[/code]

It should be called “catalina.out”. It’s useful to check here for troubleshoot Apache Tomcat. It doesn’t mean that tomcat’s successful start would mean the application to be working. catalina.out has saved me on several occasions.

Your tomcat7 configuration files

Server settings goes here:

[code language=”bash”]/etc/tomcat7/server.xml[/code]

You might find the other properties files useful as well:

[code language=”bash”]/etc/tomcat7[/code]

Your tomcat7 and catalina startup shell files

You might need to edit some .sh files like in my case to change Catalina options. You can find the shell scripts here:

[code language=”bash”]/usr/share/tomcat7/bin[/code]

You can read more on setting up Catalina environment options.

Other notes

If you know of other paths worth including, do post a comment. While this is documented more for personal use, I hope you can find it useful too!

How to set Catalina options in Ubuntu 12.10

This is more of a personal note and a really specific topic. This tutorial assumes you are using Ubuntu 12.10 or Ubuntu 12.04 and installed tomcat7 package. If you haven’t already installed tomcat7, use:

[code language=”bash”]sudo apt-get install tomcat7[/code]

After doing so, create and edit the file Putting in CATALINA_BASE/bin allows you to keep your customizations separate.

[code language=”bash”]sudo nano /usr/share/tomcat7/bin/[/code]

I set my environment variables (in my case) as in

[code language=”bash”]
CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m"

If the file is present, will pick it up and add to the runtime parameters.

To restart tomcat7, use:

[code language=”bash”]sudo service tomcat7 restart[/code]

Verifying that it works

After the server restart, run this to check:

[code language=”bash”]ps aux|grep jar[/code]

This should return:

[code language=”bash”]tomcat7 14140 63.8 11.4 4001076 918296 ? Sl 12:26 1:37 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/ -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 org.apache.catalina.startup.Bootstrap start
kahwee 15564 0.0 0.0 13580 936 pts/1 S+ 12:29 0:00 grep jar[/code]

You should be able spot your line of customization. And that’s the proper way to setting up Catalina options. You can also set JAVA_OPTS through this method too.

Degraded performance in Amazon EC2

Amazon Elastic Compute Cloud (N. Virginia) or EC2 is down. This brought down Heroku and Reddit together with many others. It kinda serves as a reminder how reliant companies are on Amazon if anything.

What’s worse is that Amazon EC2 console is down too. Amazon says, “We are experiencing elevated error rates with the EC2 Management Console.”

The North Virginia facility seemed more unreliable than other availability sites. I used to run 2 EC2 instances in Singapore (Asia Pacific) for work and they’re much more reliable than this. There was a case where they had to do some hardware migration but that’s mostly minor.