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.


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.


Send Emails from PHP on Ubuntu localhost LAMP setup

In this article, I will walk you through the process of configuring your local, Ubuntu based development machine to send emails from within PHP and also from the command line terminal. In a nutshell, you need to install and configure a mail server on your local computer. The mail server that we are going to use is Postfix. So without any further delay, lets get started.

Open up the terminal and, first of all, enter the following command:

It will make available the “mail” command on your terminal and also will install all the programs that it depends on. Our desired mail server Postfix is one of them. During installation, accept the defaults as configuration options of Postfix when asked.

Once the installation is complete, type following command:


Ubuntu 13.10: Touchpad Stops Working After Suspend – Solution

I am running Ubuntu 13.10 64bit on my Lenovo G500 laptop. I was facing a strange problem. Whenever my laptop went to the suspended state and I resumed it afterwards, its touchpad was not working. A little bit of Googling returned a simple solution that worked like a charm. I am summarizing that solution here in this post for future reference of me and anyone else facing a similar problem.

Open up the terminal and type following command:

It will create a new file named “0000trackpad” in the /etc/pm/sleep.d/ directory and subsequently open it for editing in gedit. Paste following code snippet in this window, save the file and close it.

Back to the terminal, type following command to make the newly created file executable:

And … that’s it. Above steps solved the problem for me and hopefully will do the same for you too. Suspend/Resume your laptop a few times to make sure that your touchpad no longer gets disabled automatically.


MongoDB Tips and Tricks

mongo shell – JavaScript execution failed: Error: couldn’t connect to server – Quick Fix

I have just installed MongoDB v2.4.5 on my Ubuntu 13.04 64 bit system and when I tried to connect to the server from command line using the mongo shell provided with the installed mongodb-10gen package, I got the following error:

I tried to start, stop and restart the mongodb service using these commands but the error remained there:

Finally, I looked at the log file ( /var/log/mongodb ) and found the following error message listed there: