Install Apache, PHP and MySQL on Ubuntu 16.04 in one command

Ubuntu is one of the most user friendly distributions of Linux operating system. If you want to do PHP and MySQL development on an Ubuntu based machine or want to host an application developed in these technologies on a virtual server that runs Ubuntu, then you will first need to install the LAMP stack on that system.

Fortunately, it is very easy and simple to do so. First of all, update your repositories:

Now, install  tasksel . It is a helper program that provides easy installations for a number of related software packages, one of which is LAMP stack.

It might be already installed on your Ubuntu distro, as was the case on my DigitalOcean droplet. Now, run tasksel. Continue reading Install Apache, PHP and MySQL on Ubuntu 16.04 in one command

Fix: Tomcat taking very long to serve first request on fresh install on Ubuntu 14.04

Yesterday, I was trying to setup Apache Tomcat 7 on Ubuntu 14.04 on a new DigitalOcean droplet. But it was taking VERY long (10-15+ minutes) to serve first request. After that, it started serving requests normally. If the Tomcat was restarted, it again took very long to serve the first request.

I tried large droplets with more memory. Also, I tried installing Tomcat from both the Ubuntu repository package and from official Tomcat website. But in every case, I faced the same problem.

Turns out, the solution is pretty simple. We just need to install a package named  haveged like this:

Now restart Tomcat and you will see that it starts serving requests immediately at normal speed.

Basically what happens is that the entropy pools run dry on our virtual server running in the cloud. As a result, Tomcat blocks on /dev/random waiting for random numbers to be generated. Haveged seeds our system’s random source (usually /dev/random) using differences in our processor’s time stamp counter (TSC) after executing a loop repeatedly. Please refer to this article on DigitalOcean for details of this process.

Linux: Check from command-line if your OS is 32 bit or 64 bit

Do you need to find out if your Linux installation is 32 bit or 64 bit? I usually need this information when manually installing a piece of software (e.g. Netbeans Profiler Remote Pack).

There are two alternative commands which produce identical output. You can use any one of these:

  1. arch
  2. uname -m

If any of these commands outputs  x86_64 then your Linux is 32 bit. On the other hand, if the output is  i686 or  i386 then you are running a 64 bit Linux distro.

For detailed discussion of these and some other useful, related commands, please checkout:

Programmatically Get Absolute Path of Java Executable in a Running Program

Do you want to get absolute path of the specific Java executable that was used to launch a program, from within that program itself? May be you want to launch another Java program P2 from a program P1 and you want to make sure that P2 is launched using the same version of Java that was used to launch P1?

It is possible. Java runtime makes available a system property  java.home which contains the path to its installation or root directory. Java executable is usually located (tested on Windows and Mac) inside  java.home in a folder named  bin . We can combine these two facts to get absolute path of the Java executable that was originally used to launch a program. Here is a code snippet that does exactly this:

You will need to import in your source code to compile it. After these couples of lines have executed,  javaExe will contain our required path. You can use it for whatever purpose you want. Here is a sample code snippet that uses this Java executable to launch another Java program in a separate JVM. Continue reading Programmatically Get Absolute Path of Java Executable in a Running Program

SOLUTION: No Java runtime present, requesting install – Mac OS X Yosemite

I was working on a simple java based desktop application today. It was packaged in an executable jar. One of its required features was to launch another executable jar in a separate instance of JVM. Here is my code dealing with this requirement:

This is equivalent of running following command on terminal.

This code was working fine on Windows and Ubuntu. But on Mac, it resulted in a dialogue like this: Continue reading SOLUTION: No Java runtime present, requesting install – Mac OS X Yosemite