Tag Archives: server

Tools of the trade

This is a quick update of the tools I used these days. I am a web user interface developer now so some of these tools might be kinda niche!

  • Text editor: SublimeText 2, because it loads fast and I swear by its open by file name feature
  • Computer: MacBook Air 13″, a decent screen size with good portability. I like working at cafés and this gadget fits my lifestyle.
  • Browser: Chrome 25. I lost track of Chrome’s version, comes with Chrome is the excellent debugger I cannot live without.
  • CSS generator: Less, because Less can be compiled by JavaScript on the client side. It’s easy to get started developing.
  • Revision control: Git or SVN. My vote is to Git but my company is on SVN.
  • Image editor: Photoshop. We use Photoshop for general slicing.
  • Programming and markup languages: Mainly JavaScript, HTML and CSS. We have quite a bit of Handlebars.js stuff as well. We use JavaScript extensively these days.
  • JavaScript framework: Backbone.js and Marionette.
  • Web server: Apache Tomcat. We have a Java stack.
  • Page profiling: Just Chrome.
  • Automation: Ruby Guard and Grunt.js. There’s a bit of LiveReload as well, but only when I develop on a Mac.
  • Quality checks: JShint and Chrome Audit in the console.

I can see what I use previously as a more general web developer.

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 app1.internal.kw.sg and app2.internal.kw.sg, 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:

<?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" />

	<GlobalNamingResources>
		<Resource name="UserDatabase" auth="Container"
			type="org.apache.catalina.UserDatabase"
			description="User database that can be updated and saved"
			factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
			pathname="conf/tomcat-users.xml" />
	</GlobalNamingResources>

	<Service name="app1">
		<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" redirectPort="8443" />
		<Engine name="app1" defaultHost="app1.internal.kw.sg">
			<Host name="app1.internal.kw.sg"  appBase="app1" unpackWARs="true" autoDeploy="true">
				<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
			</Host>
		</Engine>
	</Service>

	<Service name="app2">
		<Connector port="8082" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" redirectPort="8443" />
		<Engine name="app2" defaultHost="app2.internal.kw.sg">
			<Host name="app2.internal.kw.sg"  appBase="app2" unpackWARs="true" autoDeploy="true">
				<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
			</Host>
		</Engine>
	</Service>
</Server>

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

Disadvantages

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.

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.

Tools of the trade

Every web developer uses his/her set of preferred tools. Here’s mine:

  • Text editor: SublimeText 2, because it loads fast and I swear by its open by file name feature
  • Computer: MacBook Air 13″, a decent screen size with good portability. I like working at cafés and this gadget fits my lifestyle.
  • Browser: Chrome 18 or 19. I lost track of Chrome’s version, comes with Chrome is the excellent debugger I cannot live without.
  • CSS generator: Less, because Less can be compiled by JavaScript on the client side. It’s easy to get started developing.
  • Database engine: MySQL InnoDB.
  • Database browser: Sequel Pro, never found a replacement for this. I’ve been using this for 3 years, by far the best.
  • Revision control: Git or SVN. My vote is to Git but my company is still on SVN.
  • Image editor: Photoshop. Embarrassingly I am one of those that will just launch Photoshop to make PNGs with alpha-transparency. There are probably better tools out there but I can’t get used to them.
  • Programming languages: PHP for web development. JavaScript or Ruby on scripting automation. I still use Expect for a bunch of server-side tasks, I cannot move away from that still.
  • Web server: Apache for development. It’s all because of PHP’s xdebug. My colleagues use .htaccess often too. I use nginx for production usually.
  • Load profiling: Seige, it’s simple and reliable.

Other tools include:

  • LiveReload 2 has been extremely convenient and it has been part of my workflow for months. I never looked back.
  • Bash alias lets me quickly navigate through the trenches of my messy directories. I also use it to pull for Git quickly.

How to install PHP GeoIP in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

kahwee:~ kahwee$ sudo pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date

Continue reading “How to install PHP GeoIP in CentOS” »

How to let PHP send emails

PHP not sending emails? You need a mail transfer agent (MTA). If you’re in the Ubuntu platform, you can use postfix for this:

sudo apt-get install postfix

You can read on more information here.

Previously my Contact Form 7 WordPress plugin didn’t work, it works fine after I install and configured postfix. I can’t go through the specifics of the configuration with you since yours would probably differ. I selected “Internet Site” and press the return key (Enter) all the way selecting the default options. On doing so, Contact Form 7 starts to work already.

Should you need to configure postfix again, you can reconfigure too:

sudo dpkg-reconfigure postfix

Contact Form 7 uses WP_Mail which uses PHP’s mail() function. If you do need to troubleshoot, try sending emails with mail().

If you need additional configuration, you may need to update the following:

  • Settings SMTP and smtp_port need to be set in your php.ini
  • Also, either set the sendmail_from setting in php.ini, or pass it as an additional header.

I did not have to configure anything more than postfix. I am using Ubuntu server, on nginx web server.

How to install PHP APC in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

kahwee:~ kahwee$ sudo pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date

Continue reading “How to install PHP APC in CentOS” »