Configuring Apache Webserver

This tutorial is for those people who want to start using PHP + MySQL on windows instead of Linux. This tutorial is written entirely from scratch and is based on my personal experience using WAMP. No guarantee is given on the working of WAMP if you make any changes.
The Apache Webserver’s configuration file is named as httpd.conf and is located in the directory C:\wamp\Apache2\conf if WAMP is installed in C:\Wamp directory.
The rules are simple; any line beginning with # is a comment and is simply ignored by Apache while reading its configuration. Line numbers are given for quick reference. They are the default values and can be different is you have changed your settings. Just look out up or down with reference to the line number for what you are searching for. The Apache version used in this tutorial is 2.2.4. For each change to take effect, you have to restart the server

Changing Server Root:
The directory of Apache where Apache is installed and all configuration files is kept. This includes all error and log files. This can be changed by changing them in line 42.
It reads as ServerRoot “c:/wamp/apache2”
You can change this to “c:/Program Fileswamp/apache2” if you had installed WAMP in program files directory. Note the front slashes as opposed to backslashes which is normally used on windows. All paths on Apache contain slashes no matter what is the Operating System.

Making Apache listen to specific IP address or none:
For this just uncomment out the line which reads out like #Listen 12.34.56.78:80 on line 52. If you want Apache to listen to some IP say 122.65.23.87, change 12.34.56.78 with the required IP address. Setting this to 0.0.0.0 blocks all incoming requests.

Making Apache listen on port other than 80:
By default Apache is made to listen on port 80, but sometimes other webservices are also running on the same port which may give rise to ambiguous situations, you can make Apache to listen to any other port other than 80, the best alternative is port 8080, which is the alternate HTTP port, if some other service is running on it then better try out 8180. To change it just change Listen 80 on line 53 with other port no eg Listen 8080 or Listen 8180

Loading Modules:
Its pretty easy to do so, just uncomment out the # before the LoadModule word. Its starts on line no 67 by default.
The general look for a loaded module looks like
LoadModule modulename_module modules/modulename.so
And that of an unloaded module
#LoadModule modulename_module modules/modulename.so

Changing the root directory of Apache where you keep your scripts:
You are provided with a folder where you have to keep your scripts and execute it via the Webserver. In Linux it is /var/www and /var/www/html in older versions of Apache. In windows it is C:\wamp\www\. This is given in line 150. It is written as
DocumentRoot “C:/wamp/www”
Change C:/wamp/www with any other location like C:/windows/myfolder or any other. Take care of slashes, they are not backslashes.

Configuring you server to be accessed remotely:
Go to line 178, under this are the features for the root directory which Apache accesses. In line 206 change Deny from all to Deny from none and Allow from 127.0.0.1 to Allow from all. You may even try appending a line Satisfy all after the Allow line.

Making your custom error pages:
It’s not much of a headache, just create the page in any file type e.g. html, php etc. Now in line 425 just see the format of adding files. An error code 404 is most famous. It means that the file you requested in not present. Append an extra line to the code and write
ErrorDocument 404 /error404.php

This file should be present in the root directory where Apache is installed. Similarly you can try out other errors by just replacing 404 with any that error’s code.

FAQ for Beginners (Volume-I)

What is meant by FREE software?
By free software we do not mean free of charge, by FREE we mean FREE to use or FREEDOM. We may refer it by two terms ‘free beer’ and ‘free speech’. Free software does not always mean free of charge (though most of them are free of charge). By FREE we mean that you have the freedom to USE, copy, modify and redistribute the software. It’s perfectly legal to do the above.

What is meant by OPEN SOURCE SOFTWARE?
Open source software refers to those types for softwares of which the source code if freely available. You can see the source code and understand how the software works. Open source software is not always a FREE one. There are some software which releases their source code. You can compile them for your use by changing the code is not allowed. These types of software fall under NON-FREE software category even though they may be available free of charge. Thus all FREE softwares are OPEN SOURCE but the reverse is not true.

Is Linux an Operating System or just the Kernel?
Strictly speaking Linux is just the kernel. Linus Torvalds-who wrote the kernel called it Linux. The proper name for the Operating System is GNU/Linux. GNU movement started in 1984 and was started by Richard Stallman for developing a completely FREE (mark the word FREE) operating system. By 1991 the GNU project created a lot of stuffs and excellent tools and softwares, but the kernel was missing, this gap was bridged by Linus Torvalds, a Finnish student at the University of Helsinki aged 21. So we should properly call this Operating System GNU/Linux to pay some acknowledgement to Richard Stallman-The founder of GNU Project.

What is a kernel by the way?
Literary speaking a kernel is a heart. In GNU/Linux the core of the Operating system is the kernel. It is the work of the kernel to communicate with the hardware. Think it as an interface between the software and hardware. You know computer is dumb enough to understand even English.
Linus Torvalds first designed a monolithic kernel in Sep 1991 as a small project and put it up on FTP servers with the source code of course. Soon people liked and its popularity rose. Though he got some stiff resistant from some people like Andy Tanenbaum, the noted Professor for Networks, Operating Systems and the creator of Operating System MINIX. Linus damn cared about this and went ahead to achieve his mission.

What is GCC? Is it better than my Turbo Compiler?
GCC is the C compiler developed by the GNU project. It was developed by Richard Stallman with the help of his community members. It is the most robust and reliable C compiler till date. It strictly compiles with the ANSI and C standards. If you have heard the name g++, it’s the GNU C++ compiler. The GNU C and C++ compiler are better than Turbo Compiler, though some people might not agree.

Can I know about the history of GNU/Linux? What led to its creation?
Earlier when computers were not so widespread, Operating systems we not as user-friendly at all as it’s nowadays. At that time computers users had to be programmers themselves. All the software’s source codes were included with the shipment. That was the era of Open Source softwares. At that time computers hardware were very costly, and softwares were bundled by default.
As the time advanced, the price of hardware dropped significantly. Now manufactures saw a scope of profit in software itself. They started unbundling the source code of the softwares and drivers with the system.
UNIX was developed by AT&T at the famous Bell Labs, initially it was free to be used and taught in the universities and its source was also open for everyone. When AT&T started facing bad days, it looked up at its creation UNIX to survive, it forced universities to sign a non-disclosure agreement. Thus UNIX turned into a so called proprietary OS. And GNU/Linus is a clone of UNIX but written entirely from scratch by Linus.

What is GNU? Why was it started?
Richard Stallman was not very much impressed by the happenings there at AT&T. He wanted that the source code should be freely available. His movement was called GNU which is a recursive acronym for GNU Not Unix. His movement brought radical changes there in the computer world.
Stallman was working in MIT. The printer provided to him by Xerox Corporation through MIT frequently jammed. He wanted to have the source code to improve the driver so as to improve the performance. He contacted Xerox for the same which was refused. This annoyed him a lot. Closed source and proprietary softwares and drivers were hindering the development and advancement of technology. This led to the GNU movement.

Can I get some examples where Open Source and Free Software have succeeded?
Surely! We can point out a lot of examples.
1) Take for example GNU/Linux. According to a rough estimate around 80% of the web servers run on Linux, this is all due to reliability, robustness and security for which Linux is known for.
2) Second example is Apache web server. This is an excellent piece of software used to run web servers. It is extremely light, robust and highly reliable. 80% of the websites run on Apache web server.
3) Third Example is Mozilla Firefox, this award winning, lightweight and loved by all Web browser has won acclaims of people all over the world. It came as a rescue to people from the sick Microsoft Internet Explorer. Millions of copy of this browser was downloaded. People liked it and got attached to it with their heart.
4) Fourth example is VLC Media Player. Sick of downloading codecs again and again only to find that your video clip doesn’t play because some codec is missing. VLC Media Player gives you the solution. I never had to download another codec desperately after I got VLC. It plays all audio and video formats. Not a single audio and video format I have come to know which it does not play! Amazing enough!!!
Can’t we end the explanation here? Otherwise the list would be too long.

What is this Mozilla Firefox! Is it really great?
Mozilla Firefox is an award winning Web Browser known a lot for its features. In such a short time span it has become the most acclaimed web browser. Most people there out use Internet Explorer not because they like it but due to the fact that it comes packed by default with every version of Windows. All those who tried out Firefox properly with open minds would surely like it.
The Source code of Firefox is open. If you have great programming skills you are invited to see the code, modify and pass it on. This is the faith of Free Software.
You might have usually experienced many times your Internet Explorer (IE) behaving strangely. This is usually due to spyware and malwares. If IE can’t protect itself from malwares how dumb browser would it be? Just think! In contrast Firefox is a very intelligent browser. Its anti-phishing features are really marvelous. It had introduced tabbed browsing even before it was implemented in IE7! (Microsoft acted too swiftly).
When you try to install IE7, you would be asked to validate your copy of windows, turn off anti-virus and all that crap and after installing you will be asked to restart your system. What the hell is this all? It consumes so much time! In sharp contrast, installing Firefox is just a matter of clicks. For default installation it needs you to press Next and Next until you encountered Finish. Voila! Installation did take some 5-10 seconds. Is it a magic? No man! It’s Mozilla Firefox.

What is that that Penguin which shows up with Linux?
Dear! That’s the mascot of Linux! It’s really a cute and sweet logo. There are some stories relating why penguin is the mascot. Actually this mascot was given by Linus himself. Once he was bitten by a penguin in his hand. He developed a light disease called penguinista. It’s a disease in which you start having a lot of love for penguins. Though there are many other small variations of this story, it does not matter much.

Installing Compilers (GCC,G++ and Java) on UBUNTU

This tutorial is not written from scratch. I would like to thank all people who
enlightened me about Linux and Open source. This tutorial acknowledges the
help of Ubuntu Community (Docs) and people at online forums who cleared
my doubts on compilers.
Installing compilers is one of the easiest things there out at Linux. It
may seem a bit tough and complicated in the beginning but apt-get
and Synaptic Package Manager simplify your work a lot. As a newbie
developer you would require a C/C++ and a Java compiler. Installing
them is a matter of few commands.
The GNU C and GNU C++ Compiler:
The GNU C compiler is also called gcc and C++ is called g++. You
may also require the GNU make utility. All of them can get installed
by getting the build-essential package.
Just use this command:
sudo apt-get install build-essential
The GNU Java Compiler:
Firstly note that this compiler is not the one provided by Sun. The GNU
Java compiler is named as gcj. Just install the package gcj
To install the GNU Java bytecode interpreter, install the gij package.
To have gcj compile to executables, install libgcj6-dev
Use the command:
sudo apt-get install gcj gij libgcj6-dev

UPDATE ON 10th July,2006:

Some people complain that the above method does not work on their system. Errors like “build-essential not found” are displayed. Here is an alternate way of doing the same:
Most people want to use linux in GUI mode just like windows. If this the case then why use the terminal? Just open the Synaptic Package Manager and search for the package gcc. Select the package, some more packages will be highlighted and will be asked to also be included in the install process. These are dependencies. Select them also and click on Apply. The packages are download and installed. To install g++,make and gcj just do the same as above mentioned for gcc package.
Well its done, now try compiling, it should work.

Installing and configuring ClamAV Antivirus on your UBUNTU

This tutorial is not written from scratch. I would like to thank all people who
enlightened me about Linux and Open source. This tutorial acknowledges the
help of Ubuntu Community (Docs) and some online tutorials from where I
gained some initial knowledge about Linux antivirus.
Now you might be wondering that why I mentioned this Anti-Virus tool. Linux
is supposed to be virus free? Actually calling Linux virus free is not correct.
Linux is carefully engineered in such a way that it’s pretty tough for viruses
to run. There is a concept called permissions or authorization which restricts
running of viruses. This concept lacks in windows which makes it so much
susceptible to virus threats.
Now the question is why a Linux antivirus? Just think of the case, you are
hosting a website on your Linux system and the site allows uploading of files
by users. If a user (by mistake) running windows uploads a virus infected
file? Your OS will not suffer but just think of the case that file is downloaded
by another user running windows and executed. The site will become a
source of virus infection. To prevent this there are many antivirus for Linux
which detect windows viruses though not much viruses are present around
for Linux. This can be used to scan attachments of the mail that are sent
from your server. Here I use ClamAV, it’s a command line antivirus with no
GUI, who needs it now when command line works better? It only detects
viruses but does not remove it. It can detect viruses for nearly all platforms.
Installing ClamAV:
You can install one of the two packages depending upon how you are going
to use the antivirus. If you are going to use it manually, means starting the
antivirus when required. In this case you should get the clamav package.
sudo apt-get install clamav
For automated use install the package clamav-daemon
sudo apt-get install clamav-daemon
After installing you may be asked to configure the antivirus like updates, I
recommend automatically since its updates are very small.
Scanning Using ClamAV:
Use the command clamscan
Let’s check out some examples
To check each file, displaying name of each file: clamscan –r /
To check all files,display only infected file and ring a bell if infected files are
found: clamscan -r –bell -i /
After scan is completed it generates a scan summary.
Updating virus definitions:
Use the command freshclam
Finally one more point, clamscan can inspect only those file for which the
user is authorized to read. For checking all files use sudo prefix.

Setting up LAMP Stack on your UBUNTU System

This is to help people set up LAMP on their desktops. Ubuntu server edition comes with LAMP but desktop users must download all the necessary files. This tutorial owes its credits to Ubuntu Community Docs and lots of people around the world who enlightened me about LAMP and Ubuntu. Let’s start.We first need some important packages. These are:

apache2 php5-mysql libapache2-mod-php5 mysql-server

You can get these via apt-get or from your Synaptics Package Manager. For getting via apt-get you must have an active internet connection. Type this command in the terminal:

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

If you are in the Packages Manager, just search the packages and select them. This is the easiest method.

You may want to configure your LAMP, but before starting it is advisable to change the installation defaults. The default root user of MySQL has no password or a blank string as password. This should be changed. It is always advisable to create another user with full privileges as that as root. Use this alternate user instead as root. Root is the superuser.

Go to terminal: Type

mysql -u root

At MySQL console type

SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);

Just put your password instead of yourpassword within single quotes as shown above.

After setting the password if you want to login as root,just enter this at the terminal:

mysql -u root -p

Create a new user and give all the privliges to it as explained above:

grant all privileges on *.* to ‘yourusername’@’localhost’

identified by ‘yourpassword’ with grant option;

Replace yourusername with the username you want and yourpassword with a proper password. If you want this user to deny Grant Option just remove WITH GRANT OPTION from the above statement.

Run, Stop, Test, And Restart Apache:

Start: sudo /usr/sbin/apache2ctl start

Stop: sudo /usr/sbin/apache2ctl stop

Test: sudo /usr/sbin/apache2ctl test

Retart: sudo /usr/sbin/apache2ctl restart