Shadow's Shadows











{December 4, 2009}   Tale of the two Brilliant Idiots

This small tale starts with me and my dear friend sarath going to the practical session of the “Red Hat Certified Engineer” course that we have registered and paid for. Usually we don’t go to these classes, but this time it is during the vacation and we are jobless anyway, so we decided to go. The sir was more than happy because we are the first batch that he is handling and he wants at least a few of us to finish the course.

Anyway, let me come to the actual story, one fine day we go there and we try to implement a FTP server and a NFS. We started doing it in my laptop and everything was going fine. We installed and configured both vsFTPd and NFS and it was working fine in my Ubuntu, but sarath told me there is no point in doing it in Ubuntu we should be able to do it in RedHat too.

So we decide to do it in one of the lab systems, we chose the nearest one(we did not know that we had chosen the wrong one!!) and tried implementing NFS and the service was up and running so now we moved on to FTP now. The vsFTPd package was not installed in the machine, so we try installing it using ‘yum’, but its not working. It was telling us that the repository was missing!!. We checked the repository list and the local repository’s ‘.repo’ file was missing. We googled it and wrote the ‘repo’ file.We thought we had resolved the issue(Ha Ha Ha!!)

We tried again and it was telling us that the local repository was also missing!!. We loged into the server cheked if the files were really missing, but there they were sitting in the server. Now i asked sarath to mount the NFS share that we had configure earlier, he tried it and to our surprize the system replied “Sorry (dumbass), cannot mount specified location”, by now you might have figured out the problem but we didn’t.

This time we were really confused, we thought that there was some configuration error and we started going through the configuration files. We rewrote the configuration files and restarted the services again, but still the problem persisted. Just this had taken half a day!!. We were completely clueless and we had lost all interest in doing anything.

Just then i had a spark(Finally!!) and i tried pinging our client from the server, guess what was the reply i got??

Request timed out.

Request timed out.

Request timed out.

Ping statistics for 172.24.24.5:

Packets: Sent = 3, Recieved = 0, Loss = 3 (100% Loss)

And just now I understood why our glorious efforts did not work……….

“THE ETHERNET CABLE WAS NOT EVEN PLUGGED IN THE COMPUTER”

Still sarath didn’t know this yet, so I asked him to take a peek behind the CPU. He asked me why?, I just insisted that he should look…. He took a peek….Took his notebook, walked straight out of the lab……

I typed “poweroff” in the terminal, took my laptop and traced his path out of the lab.

LOL :-O



Finally i got back to my senses after wasting too much time. I thought of finishing whatever I’ve left incomplete, so I took up php to start with. First of all I needed to install Apache and php. I had no idea that just this would take one whole day, but still it was worth it……..
I use a Ubuntu 9.04(Jaunty Jackalope) Desktop Edition, I thought this collective info on Installing and configuring apache2 along with PHP and MySQL would help people spend lesser time on just installing it rather than using it.

Installing Apache2

Apache HTTP Server is a free software/open source web server for Unix-like systems.
#sudo apt-get install apache2

This will complete the installation of apache2 web server. To check whether your Apache server is running, just open your web browser and type “http://localhost“, you will get a default page which says “It works!“. Now you need to know where the configuration files and document root for your Apache web server.
By default all the configuration files are located at /etc/apache2

Editing the document root
Default document root for apache2 is /var/www. If you want to change the default document root you need to edit the /etc/apache2/sites-available/default file and look for this line “DocumentRoot /var/www/” here you can change where ever you want to change.For example if you want to change /home/wwww the above line looks like this “DocumentRoot /home/www/”.
The main configuration file located at /etc/apache2/apche2.conf. At this stage reading through all the ‘.conf‘ files inside the /etc/apache2/ directory will be a good option.

Installing php in Apache
If you want to add support of php and cgi scripts install the following packages libapache2-mod-php4,php4-cli,php4-common,php4-cgi

#sudo apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

This will complete the installation of php support for apache2.
Restart your Apache server

#sudo /etc/init.d/apache2 restart

To check whether your Apache server is parsing  you php scripts just do this.

#sudo gedit /var/www/index.php

Enter the following script and save the file
<html>
<body>
<?php echo “Hello World!!“; ?>
</body>
</html>

Now go to your web browser and type “http://localhost/index.php“, you should be able to see a page which says “Hello World!!“.

Troubleshooting PHP 5
I got stuck at this point for a long time, my browser kept asking me if I  wanted to download the php file instead of actually displaying it!!.
This will happen if Apache is not actually parsing the php after you restarted it, to resolve this just install libapache2-mod-php5.

#sudo apt-get install libapache2-mod-php5

It is installed when you install the php5 package, but may have been removed inadvertently by packages which need to run a different version of php.

You may also need to actually enable it, by doing

#sudo a2enmod php5

followed by

#sudo /etc/init.d/apache2 restart

If sudo a2enmod php5 returns “$ This module does not exist!“, you should purge (not just remove) the libapache2-mod-php5 package and reinstall it.

Be sure to clear your browser’s cache before testing your site again.

Recommended module
The worker MPM provides a threaded implementation for Apache2. It is considerably faster than the traditional model,and is the recommended MPM.You can install this using the following command.

#apt-get install apache2-mpm-prefork

Installing MYSQL with PHP 5

#sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

This will install MySQL. Once MySQL is installed it will ask you for a mysql-root password, note that it is just mysql-admin password and not your system’s root password.

Set mysql bind address
Before you can access the database from other computers in your network, you have to change its bind address. Note that this can be a security problem, because your database can be accessed by others computers than your own. Skip this step if the applications which require mysql are running on the same machine.

#sudo gedit /etc/mysql/my.cnf
and change the line:
bind-address           = localhost
to your own internal ip address e.g. 192.150.1.34
bind-address           = 192.150.1.34
If your ip address is dynamic you can also comment out the bind-address line and it will default to your current ip.

If you try to connect without changing the bind-address you will receive a “Can not connect to mysql error 10061“.
You might have to go through the MySQL commands from a proper reference to create a user and play with the database.

Once you are done with all this, to verify that Apache and mysql are running just nmap your own system and if you’ve done everything right you will see something like this.

#nmap localhost

Starting Nmap 4.76 ( http://nmap.org ) at 2009-11-30 13:00 IST
Warning: Hostname localhost resolves to 2 IPs. Using 127.0.0.1.
Interesting ports on localhost (127.0.0.1):
Not shown: 997 closed ports
PORT     STATE SERVICE
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds

I got a lot of help from the Ubuntu forums, a special thanks to all the guys who ask questions and to the guys who answer those. :-)



{June 20, 2009}   3-Way Handshake

Ever wondered what a Three-way handshake is ?……….
Ofcourse it is not three people shaking hands with each other!!…… It is a method used to establish and tear down connections in TCP(Tramsmission Control Protocol). It is also known as three message handshake. To be more technical it is it is reffered as SYN, SYN-ACK, ACK handshake. The TCP handshaking mechanism is designed so that two computers attempting to communicate with each other can negotiate the parameters of the network connection before beginning communication. This process is also designed so that both ends can initiate and negotiate separate connections at the same time.

It goes like this……….

SYN, SYN-ACK, ACK

SYN, SYN-ACK, ACK

1’st shake: The machine which wants to establish the connection or ‘Host-A’ sends a TCP SYNchronise packet to the machine that has to be communicated with or in our case it is ‘Host-B’.
2‘nd shake: On recieving the Host-A’s SYN packet Host-B sends a SYNchronise-ACKnowledgement packet if the connection is possible.
3‘rd  and the final shake: On receiving the SYN-ACK Host-A sends an ACKnowledgement back to Host-B and the connection is established.

If the communication is complete any one of the Host will send a FINish packet to the other host signaling the end of communication and the connection will be terminated sucesfully.
On recieving the SYN packet in the second step, If Host-B is not ready or if the port is closed or if the connection is not possible in one way or the other, Host-B sends a RST packet to terminate the connection witout establishing it completely.
Refer a good TCP/IP text for further info.



{June 1, 2009}   The First time

For so long I thought blogs are extremely difficult to make and only great people have blogs, but later I understood that, I can also do difficult tasks and by doing so i’ve become one of the great people I talked about (In short, I created a blog). So, This is my first blogging attempt and I will see to that it is not perfect, because you guys can post comments and I can know that you do exsist and you do care on how my blog looks (And because writing comments is fun rite!!!, i want you to have some fun.).

Better now or Never. Thats why Now.



et cetera