Install LAMP – Apache2, PHP5 and MySQL on Ubuntu 12.04 LTS

Install mysql:
sudo apt-get install mysql-server mysql-client

Install apache2:
sudo apt-get install apache2
To update home directory, modify the file /etc/apache2/sites-available/default

Install php5:
sudo apt-get install php5 libapache2-mod-php5 php5-mysql

For detailed version, refer this link


2011 in review

The stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 2,300 times in 2011. If it were a cable car, it would take about 38 trips to carry that many people.

Click here to see the complete report.

Create new mysql user with grant option

Login in mysql using:

$ mysql -u root -p

First create a database using:

mysql> create database dbname;
Query OK, 1 row affected (0.00 sec)

Then in mysql shell create new user using:

mysql> create user 'username'@'localhost' IDENTiFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on dbname.* to 'username'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec)

Or you can use ‘%’ wildcard if you want to connect mysql from any host:

mysql> create user 'username'@'%' IDENTiFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on dbname.* to 'username'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

For more details visit mysql manual.

Create and Import dumpfile or SQL datafile into mysql database

Here are few commands to easily create and import MySQL data.

To create dumpfile:
mysqldump -u USER -p PASSWORD DATABASE > filename.sql

To import dumpfile:
mysql -u USER -p PASSWORD DATABASE < filename.sql

Export MySQL database structure only:
mysqldump -u USER -p PASSWORD --no-data DATABASE > filename.sql

Export data of MySQL database only:
mysqldump -u USER -p PASSWORD --no-create-info DATABASE > filename.sql

To create dumpfile of all databases:
mysqldump -u USER -p PASSWORD --all-databases > filename.sql

To import dumpfile when either database name is not known or dump has database info:
mysql -u USER -p PASSWORD < filename.sql

USER : database username
PASSWORD : password
DATABASE : database name to which datafile is to be imported

cls: command not found

I used ‘cls’ for it does clear screen and ls.
After I upgraded my ubuntu, i can’t use that any more. It showed:

cls: command not found

Finally I have found the solution.

You have to create a alias for the command you want to use.
For example, for cls

$ alias cls='clear;ls'

You can make more aliases,

$ alias cll='clear;ls -lh'

These aliases will vanish on your next login. So to make the change permanent you can add it to your ~/.bashrc or ~/.bash_profile. Just add the whole alias line as these files are executed (as bash scripts) on login.

Install network simulator on ubuntu

This blog post is regarding installing network simulator on Ubuntu.

Make sure you have the following packages installed:

build-essential autoconf automake libxt-dev libx11-dev libxmu-dev

Download ns-allinone-2.34.tar.gz. Then execute the following using command prompt:

tar -xzf ns-allinone-2.34.tar.gz 
cd ns-allinone-2.34

For Ubuntu 9.10 (karmic), you may encounter this error in the linking of otcl:

otcl.o: In function `OTclDispatch':
  /your/path/ns-allinone-2.34/otcl/otcl.c:495: undefined reference to
  otcl.o: In function `Otcl_Init':
  /your/path/ns-allinone-2.34/otcl/otcl.c:2284: undefined reference to
  ld: hidden symbol `__stack_chk_fail_local' isn't defined
  ld: final link failed: Nonrepresentable section on output
  make: *** [] Error 1

This error is because the linker being used is “ld -shared” instead of “gcc -shared”. If you edit one line in otcl-1.13/configure, and rerun install, it should work:

--- configure.orig      2009-11-02 12:14:52.556167945 -0800
 +++ configure   2009-11-02 12:17:28.966706099 -0800
 @@ -6301,7 +6301,7 @@
 -        SHLIB_LD="ld -shared"
 +        SHLIB_LD="gcc -shared"

After a long wait and a whole lot of text, you should see the installation finish up with text like the following:

Nam has been installed successfully.
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.4.11:      /your/path/ns-allinone-2.34/{bin,include,lib}
tk8.4.11:               /your/path/ns-allinone-2.34/{bin,include,lib}
otcl:           /your/path/ns-allinone-2.34/otcl-1.13
tclcl:          /your/path/ns-allinone-2.34/tclcl-1.19
ns:             /your/path/ns-allinone-2.34/ns-2.34/ns
nam:    /your/path/ns-allinone-2.34/nam-1.14/nam
xgraph: /your/path/ns-allinone-2.34/xgraph-12.1
gt-itm:   /your/path/ns-allinone-2.34/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns

Please put /your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.19/unix:/your/path/ns-allinone-2.29/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.


(1) You MUST put /your/path/ns-allinone-2.34/otcl-1.13, /your/path/ns-allinone-2.34/lib, 
    into your LD_LIBRARY_PATH environment variable.
    If it complains about X libraries, add path to your X libraries 
    If you are using csh, you can set it like:
                setenv LD_LIBRARY_PATH 
    If you are using sh, you can set it like:
                export LD_LIBRARY_PATH=

(2) You MUST put /your/path/ns-allinone-2.34/tcl8.4.19/library into your TCL_LIBRARY environmental
    variable. Otherwise ns/nam will complain during startup.

(3) [OPTIONAL] To save disk space, you can now delete directories tcl8.4.18 
    and tk8.4.18. They are now installed under /your/path/ns-allinone-2.34/{bin,include,lib}

After these steps, you can now run the ns validation suite with
cd ns-2.34; ./validate

For trouble shooting, please first read ns problems page Also search the ns mailing list archive
for related posts.

If your ubuntu version is 9.10, you must change the variable of environment CC if not set

$ export CC=gcc-4.3

Now, You have to set environment variables

$ gedit ~/.bashrc 

Replace /your/path with the path to parent directory of ns-allinone-2.34.




Ensure that it immediately takes effect:

$ source ~/.bashrc

Validation of the installation can be tested by:

$ cd ns-2.34
$ ./validate

Now, installation of network simulator is done. Enjoy coding.

How to delete useless file in Ubuntu

Using gedit creates lot of temp files of pattern “*~”. And if you are working in multiple directories its really hard to get to all these directories and delete these files.
Also, people want to delete “Thumbs.db” from windows directories but don’t know how.

Here is a solution:

This will find all the files,

find /path_to_directory -type f -name "file_pattern"

To delete these files, you can use

find /path_to_directory -type f -name "file_pattern" -exec rm -f {} \;

where /path_to_directory is path to directory from which you want to delete the files having pattern or name file_pattern recursively.

For example, to remove files like program.cpp~ created by gedit you can use

find /home/user -type f -name "*~" -exec rm -f {} \;

and to remove Thumbs.db from windows directories you need to do

find /media -type f -name "Thumbs.db" -exec rm -f {} \;

If you want to examine the files that are going to be deleted before doing it, you should execute the same command, changing ‘rm’ for ‘ls’, like this:

find /path_to_directory -type f -name "file_pattern" -exec ls -f {} \;

In this way you may control the list of files to delete.

PS: \; is necessary.
I hope this helps.