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 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:

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

</Server>
[/code]

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.

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 setenv.sh. Putting setenv.sh in CATALINA_BASE/bin allows you to keep your customizations separate.

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

I set my environment variables (in my case) as in setenv.sh:

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

If the file is present, catalina.sh 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/logging.properties -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 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp 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.

How to install PHP GeoIP in Ubuntu

This instructions will install GeoIP over Ubuntu. It is tested over Ubuntu 12.04 LTS.

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

Continue reading “How to install PHP GeoIP in Ubuntu”

How to automate GeoIP updates on Linux

This works for Ubuntu, Debian and CentOS distributions. You need a valid license key from MaxMind. This is available as a subscription at a nominal fee.

If you have installed GeoIP successfully, you should have the geoipupdate program. If you don’t, you need the run the following.

Install over Ubuntu or Debian:

[code lang=”bash”]sudo apt-get install geoip-bin geoip-database libgeoip-dev[/code]

Install over CentOS:

[code lang=”bash”]sudo yum install re2c geoip geoip-data geoip-devel[/code]

Both libgeoip-dev and geoip-devel are required for compiling PHP’s GeoIP.

Once you run geoipupdate the first time, it tells you about a missing GeoIP file.

[code lang=”bash”]root@gladlycode:~# geoipupdate
Error opening GeoIP Configuration file /etc/GeoIP.conf[/code]

Now you copy over from the default file:

[code lang=”bash”]mv /etc/GeoIP.conf.default /etc/GeoIP.conf[/code]

If you now run geoipupdate, you get the following:

MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684
Invalid UserID

Continue reading “How to automate GeoIP updates on Linux”

How to install APC in Ubuntu 12.04

This installation is through PEAR. You can install it in other methods too. This has installed APC 3.1.9 for me over Ubuntu 12.04 LTS.

[code lang=”bash”]sudo apt-get install build-essential libpcre3-dev php5-dev
sudo pear update-channels
sudo pecl install apc[/code]

Continue reading “How to install APC in Ubuntu 12.04”

How to text search in terminal

There’re times when I need to quickly search through occurrences of certain phrases in my PHP source files. Here is when I have to search for ‘giraffes’.

This is an example finding the word ‘giraffes’ in all PHP source files from the current directory recursively.

[code lang=”bash”]find . -name “*.php” -exec grep -i -H -n “giraffes” {} ;[/code]

This works for Ubuntu, CentOS and Mac OS X.

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:

[code lang=”bash”]sudo apt-get install postfix[/code]

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:

[code lang=”bash”]sudo dpkg-reconfigure postfix[/code]

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 mysql2 gem in Ubuntu

Got an error message when you install the mysql2 gem in Ubuntu? Before you install mysql2, make sure you have libmysqlclient-dev installed or you’ll get the following:

[code lang=”bash”]kahwee@kahwee-desktop:/$ gem install mysql2
Building native extensions. This could take a while…
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.

/home/kahwee/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for rb_thread_blocking_region()… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lmygcc… no
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/home/kahwee/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
–with-mysql-config
–without-mysql-config
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mlib
–without-mlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-zlib
–without-zlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-socketlib
–without-socketlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-nsllib
–without-nsllib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mygcclib
–without-mygcclib
–with-mysqlclientlib
–without-mysqlclientlib

Gem files will remain installed in /home/kahwee/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6 for inspection.
Results logged to /home/kahwee/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/ext/mysql2/gem_make.out[/code]

To resolve it, install libmysqlclient-dev:

[code lang=”bash”]sudo apt-get install libmysqlclient-dev[/code]

And now you can install mysql2 successful:

[code lang=”bash”]kahwee@kahwee-desktop:/$ gem install mysql2
Building native extensions. This could take a while…
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6…
Installing RDoc documentation for mysql2-0.2.6…[/code]

Great!

[I tried this on Ubuntu 10.10.]