Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.

Bin-Blog

Multiple Versions of Apache on a Single System

Some times it is necessary to have multiple versions on Apache in your system. The system I am currently working on has two versions of Apache - the first is Apache 1.3 with PHP 4 and MySQL 3. The second apache is Apache 2.0 with PHP 5 and MySQL 5. It is very easy to install multiple versions of Apache in your system - the only limitation is that you can't have all the versions run at once - only one instance of apache must be running at any one point.

I installed multiple versions of apache by using the 'prefix' keyword while compiling the software. To do this, you must have the source tarball of the apache program. Install it using the commands...

./configure --prefix=/usr/local/apache2
make && make install

The prefix keyword is the location where apache will be installed to. When create multiple installation of apache, keep changing this location - so that the previous installation will not be overwritten. You can start apache using the command...

/usr/local/apache2/bin/apachectl start

This command will start the apache server at /usr/local/apache2/ folder. The configuration files for this installation will be at /usr/local/apache2/conf/. Open the folder '/usr/local/apache2/' and you will see the other folders in this directory - like document root, logs etc. You can change the default locations of these folders using the httpd.conf file.

Apache can be stopped using any one of the following commands...

service httpd stop

OR

/usr/local/apache2/bin/apachectl stop

Make sure that the running instance of Apache is stopped before starting a new instance - else a failure message will be shown. You can do this by using the command line...

$ service httpd stop
Stopping httpd:                        [  OK  ]
$ /usr/local/apache2/bin/apachectl start

Or you can use a neat script I created in Tcl/Tk. Save the following code into a file, say, 'ApacheRemote.tcl' and execute it using the command 'wish ApacheRemote.tcl'. NOTE: You must have Tcl/Tk on your system for this to work.


#!/usr/bin/wish
# ApacheRemote V 2.00.A
# http://www.bin-co.com/tcl/

proc showMsg { result } {
 .txt insert end "$result\n"
}

############################### GUI Code ####################################
label .lab_top -text "Apache Remote"
pack .lab_top

frame .frm_common
button .frm_common.but_stop -text "Stop Apache" -command {
 catch { exec "service" "httpd" "stop" } result
 showMsg $result
}
button .frm_common.but_status -text "Status" -command {
 catch { exec "service" "httpd" "status" } result
 showMsg $result
}
pack .frm_common.but_stop .frm_common.but_status -side left
pack .frm_common

frame .frm
button .frm.but_start -text "Start /usr/local" -command {
 catch { exec "/usr/local/apache/bin/apachectl" "start" } result
 showMsg $result
 #exit
}
button .frm.but_start_default -text "Start Default" -command {
 catch { exec "service" "httpd" "start" } result
 showMsg $result
 #exit
}

pack .frm.but_start .frm.but_start_default -side left
pack .frm

#Result Display Area
text .txt 
pack .txt -fill both -expand 1 -side top

bind . <Key-Escape> { exit }

Filed Under...

Read More...

Practical Uses for mod_rewrite

I have explained how to use mod_rewrite to create structured URLs and about the most used mod_rewrite directives. Now to see some practical use of mod_rewrite in various situations.

URL Change

Good URLs don't change - but sometimes you have to do it. Move one file from its previous location to a new one. Even I have done it - I moved my site from http://www.geocities.com/binnyva/ to Bin-Co, OpenJS and BinnyVA. When you make such a move, you want to make sure that your visitors move with you. This can be done using mod_rewrite.

Lets say you are moving the a page from http://www.domain.com/oldfile.html to http://www.domain.com/stuff/newfile.html. Now when ever someone visits the oldfile.html file, they get a 404 error. You can use the following script to make sure that all visitors to the old page is redirected to the new one...


RewriteRule ^oldfile\.html$ http://www.domain.com/stuff/newfile.html [R]

Escape the Slashdot Effect

Slashdot Effect is a situation when a link to a smaller site appear in a heavy traffic site like Slashdot or Digg. Due to the huge traffic this brings, many site with low bandwidth will crumble. One method to prevent this is to deny access to all visitors who have come from the high traffic site(let us assume it is slashdot.org). There are other methods also(eg. mirroring). So you have two requirements...

  • Deny access to all from slashdot.org
  • Allow access to all others.

RewriteCond %{HTTP_REFERER} ^http://slashdot\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://www\.slashdot\.org [NC]
RewriteRule ^.*$ /denied.html [F]

The logic behind the above code goes somewhat like this...

RewriteCond %{HTTP_REFERER} ^http://slashdot\.org [NC,OR] - If the visitor have come from http://slashdot.org OR,
RewriteCond %{HTTP_REFERER} ^http://www\.slashdot\.org [NC] - if he have come from http://www.slashdot.org
RewriteRule ^.*$ /denied.html [F] - Show a 'Forbidden' message.

Prevent Image Hot Linking

Hot Linking is when someone links to a file from our server directly in a way that our bandwidth will be used when anyone visits the other person's site. For example, let say we have a cool picture called, say, 'cool_picture.jpg'. We have kept it in 'http://www.our-domain.com/pictures/cool_picture.jpg'. Now some guy from another site, likes this picture and decided to show the image in his site - so he uses the HTML code...

<img src="http://www.our-domain.com/pictures/cool_picture.jpg" />

So whenever someone visits this guys site, the image is fetched from our server - thus increasing our bandwidth costs. For this reason, this method is also known as bandwidth theft.

So how do we prevent it? The same method used in the last situations - look at the referrer, and if it is not ours, show a forbidden message.


RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.our-domaincom/\.org [NC]
RewriteCond %{HTTP_REFERER} !^http://our-domain\.com/\.org [NC]
RewriteRule ^.*$ /denied.html [F]

Using Different Files for Different Browsers

As all good web designers know, different browsers have different ways of parsing the same CSS file. So your masterpiece in IE will look like something the cat brought in Firefox. One simple way of solving this problem is to use mod_rewrite and provide a different css file based on the visitor's browsers. Lets say we have a CSS file called 'style.css'. But for IE, we have created a special CSS file called 'style_ie.css'. For firefox, we have yet another CSS file called 'style_ff.css'. Our pages uses the HTML code...

<link href="style.css" type="text/css" rel="stylesheet" />

Now to provide different files based on the user agent of the visitor...


RewriteCond %{HTTP_USER_AGENT} ^Mozilla/(.*)MSIE
RewriteRule (.*)style.css$ $1style_ie.css [L]

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/(.*)Firefox
RewriteRule (.*)style.css$ $1style_ff.css [L]

For more solutions to situations like this, see the URL Rewriting Guide from Apache Docs.

Read More...

mod_rewrite Directives - RewriteCond and RewriteRule

In the last post on mod_rewrite, I used a basic example from http://del.icio.us to explain the working of the mod_rewrite module. Now I will try to explain the various options available in mod_rewrite.

RewriteEngine

This directive turns the rewrite engine on or off.
Syntax : RewriteEngine (on|off)
Example: RewriteEngine on

If you wish to disable rewriting, use RewriteEngine off instead of commenting out all the other lines. Since the rewrite engine is off by default, you have to turn it on every time you wish to use the mod_rewrite module. So the first line will be always...

RewriteEngine on

RewriteCond

The 'if' statement of mod_rewrite. The commands given below a RewriteCond line will be evaluated only if this returns a true value.
Syntax : RewriteCond TestString ConditionPattern [Flags]
Example: RewriteCond %{HTTP_REFERER} ^http://www.google.com [NC]

The RewriteCond has two arguments plus an optional third one.

TestString

There are three main types of strings that can be used in TestString part of the directive.

RewriteRule Regular Expression Captures - $N

Here N is a number between 0 and 9. If you use the string $1 in the TestString part of the RewriteCond directive, it will be replaced by the first capture from the regular expression for the corresponding RewriteRule - ie. the RewriteRule that will follow this condition.

RewriteCond Regular Expression Captures - %N

For this string, N is a number between 1 and 9. If you use the $1 in the TestString part of the RewriteCond directive, it will be replaced by the first capture from the regular expression for the corresponding RewriteCond - ie. the RewriteCond above this condition.

Server Variables

This are given in the format...

%{VARIABLE_NAME}

The most commonly used Server variables are given below. To see the full list of available server variables, see the apache manual page on mod_rewrite.

HTTP_USER_AGENT
A string containing the name of the browser the visitor is using. Eg 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5'
HTTP_REFERER
The URL of the page from where the current visitor came form.
REMOTE_ADDR
The IP of the visitor.
REMOTE_HOST
The visitor's host name.
SCRIPT_FILENAME
The filename of the page that was requested.
QUERY_STRING
The queries that was passed to the page.
REQUEST_URI
The called URI
REQUEST_FILENAME
The path of the file - ie. the URL of the page without the domain.

CondPattern

CondPattern is a regular expression - with some extra features...

!
You can prefix the '!' operator to any condition pattern to make RewriteCond return true if the pattern does NOT match.
<CondPattern
Compares the two string and return true if the TestString is lexically lower than the given pattern
>CondPattern
Return true if the TestString is lexically greater than the given pattern.
=CondPattern
Return true if the TestString and pattern are equal.
-d
Return true if TestString is a directory(folder)
-f
Return true if TestString is a file

Flags

Flags are given inside squire brackets([FLAGS]). Two flags are available for RewriteCond...
NC
No Case - the case is ignored in matching.
OR
Use this to combine two consecutive RewriteCond with a logical OR - if this is not given, an AND condition is implied

RewriteRule

Provides the rules for rewriting URLs.
Syntax : RewriteRule Pattern Substitution [Flags]
Example: RewriteRule ^/user/(.*) get_data.php?user=$1 [NC]

This is were the URL rewriting actually happens. This directive has two arguments plus an optional third one.

Pattern

The pattern is a perl compactable regular expression used to match the current URL. You can capture this by using the parenthesis ie. '(' and ')'. All text between these will be captured and could be used in the Substitution part of RewriteRule.

Substitution

The actual URL that is to be called is given here. This involves the path of the script and the parameters that should be given to it. This supports all the special features of TestString(like $N, %N and Server variables) besides plain text. It also supports the '!','<','>' and '=' prefix operators as we saw in the CondPattern.

Flags

Flats are the third argument to the RewriteRule directive. This should be given inside square brackets([FLAGS]). Flags is a comma-separated list of these flags...

R - Redirect
The URL in the address bar will change if this flag is used - as the server will use the HTTP response of 302 (MOVED TEMPORARILY) when redirecting the page.
F - Forbidden
Using this flag immediately sends a HTTP response of 403 (FORBIDDEN). Use this flag with appropriate RewriteConds to conditionally block some URLs - for example image hot linking from external sites.
G - Gone
Sends a HTTP response header of 410 (GONE). This flag is used to mark pages which no longer exist as gone.
L - Last
Stop the rewriting process in this rule and don't apply any more rules. Think Perl's last command or the break command of C.
NC - No Case
Makes the Pattern case-insensitive.
QSA - Query String Append
This flag will append the query string from the current URL to the substitution string.

Eg.

RewriteRule ^/user/(.*?)/ get_data.php?user=$1 [NC,QSA]

Please keep in mind that this is just the most commonly used Flags - for the full list, go to the apache manual page on mod_rewrite.

Happy rewriting...

Read More...

mod_rewrite module for Apache

Along with the ability to password protect folders on the web server, another major use of the .htaccess file is the ability to 'rewrite' the URL. This will let you create more structured and easy to remember URLs. This module will redirect the user to one page while showing another URL in the address bar.

Application of mod_rewrite

Used in del.icio.us

This method is used to great effect in sites like Wikipedia and Del.icio.us. For example let us take a del.icio.us URL...

http://del.icio.us/binblog/javascript+ajax

This does not mean that there is a folder called binblog in the root of del.icio.us site. Nor does this mean that there is a file with the name 'javascript+ajax'. This trick is done using URL manipulation. In this example, the URL can be split into three parts....

http://del.icio.us/binblog/javascript+ajax
         ^^^         ^^^          ^^^           
      Site URL     User ID        Tags
    del.icio.us    binblog    javascript and ajax

The actual URL being called may be something like...

http://del.icio.us/show_bookmarks.php?format=html&user=binblog&tags=javascript+ajax

So how do the user see one URL and the server use another? That is the subtle art of URL manipulation. Before we see the details of this method, a small warning. You may not be able to get the concept at the first glance - it may be sometime before you understand mod_rewrite completely. So - don't give up, grasshopper. As one person puts it...

Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo.
Brian Moore

Before going any further, let me also warn you that you must know regular expression to understand how this works. OK, now we can go further.

Using mod_rewrite

First we need a regular expression to extract the necessary elements from the URL. We will ignore the site URL(http://del.icio.us/) part. The URL is

http://del.icio.us/binblog/javascript+ajax

The Regualar Expression is...

^([^\/]+)\/([^\/]+)$

The extracted strings will be...

$1 = binblog (First Match)
$2 = javascript+ajax (Second Match)

To make this effect using the mod_rewrite module, open the .htaccess file your favorite editor and type in the following lines...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^\/]+)\/([^\/]*)$ show_bookmarks.php?format=html&user=$1&tags=$2
</IfModule>

Now to test this, create a file called 'show_bookmarks.php' in the document root of your web server. I hope that I don't have to tell you that you need a LAMP setup to do this. You will need atleast Apache and PHP to do this.

After creating the 'show_bookmarks.php' file, enter the following code into it...

<pre><?php print_r($_GET); ?></pre>

Since this is just a test, I did not bother with all the HTML tags like <html>,<body> etc. But if you are a sticker for the rules, go ahead and make the full document.

Next, open this URL in the browser...

http://localhost/show_bookmarks.php?format=html&user=binblog&tags=javascript+ajax

You should get this result - the contests of the GET request...

Array
(
    [format] => html
    [user] => binblog
    [tags] => javascript ajax
)

Now try it with the URL...

http://localhost/binblog/javascript+ajax

If everything went well, this also should have the same output - that is...

Array
(
    [format] => html
    [user] => binblog
    [tags] => javascript ajax
)

Explanation

IfModule

<IfModule mod_rewrite.c>

This is an if condition - the code inside these tags will only be executed if the mod_rewrite module is loaded with apache.

RewriteEngine

RewriteEngine On

The 'RewriteEngine' directive enables or disables runtime rewriting engine. Here we are turning on the re-write Engine. Use the value 'off' if you want to turn of all rewriting.

RewriteRule

RewriteRule ^([^\/]+)\/([^\/]*)$ show_bookmarks.php?format=html&user=$1&tags=$2

This is the important statement. The proper syntax for RewriteRule directive is given below...

RewriteRule Pattern Substitution

The Pattern is a perl compactable regular expression.

Substitution part of the rewriting rule is the string which replaces the original URL for which Pattern has matched. You can use $n to insert regular expression captured strings - $1 is the first capture, $2 will be the second and so on.

One than one line of RewriteRule can be used. The order of useage is important as the second line will use the result of the first substitution as its input

</IfModule>

End of the if condition we started earlier.

Conditions

Some of you must have already seen a big problem in this approach. To see this problem, create a folder called, say, 'data' in your document root. Now create a file called 'something.txt' in this folder. Then try to access this folder from a browser using the URL.

http://localhost/data/

Now you see the problem, don't you? The above URL will result in the output...

Array
(
    [format] => html
    [user] => data
    [tags] => 
)

Our mod_rewrite rules have captured the URL of a valid file along with the other URLs. To solve this problem, we will use a feature of mod_rewrite called Conditions. Insert these lines in the .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\/]+)\/([^\/]*)$ show_bookmarks.php?format=html&user=$1&tags=$2
</IfModule>

See the line RewriteCond %{REQUEST_FILENAME} !-d? This will make sure that the requested file is not a directory. The line RewriteCond %{REQUEST_FILENAME} !-f will prevent files from being caught by the rewrite rule. The algorithm of these statements will look something like this...

if( 'Requested Filename' IS NOT Directory ) {
 if( 'Requested Filename' IS NOT File ) {
  Rewrite the URL.
 }
}

I hope you got the logic behind this - it took me a while to understand. Anyway, as I said earlier, don't be dissappointed if you don't get it at the first try - there is a lot of black magic involved.

Now try to access the file we created a little while back...

http://localhost/data/something.txt

You will see that it works perfectly(hopefully). Now try...

http://localhost/data/

Again the folder is being accessed. Now try a URL that must be re-written...

http://localhost/binblog/javascript+ajax

If all goes well, this URL will be caught by our system and will be redirected to the show_bookmarks.php file.

More about mod_rewrite in the next post(mod_rewrite Directives - RewriteCond and RewriteRule).

Read More...

Password protecting a folder using .htaccess

The password protection feature of '.htaccess' can be used to secure entire folders or files on your web server. This is much easier than having to code the entire authentication system by hand.

This feature had been a life saver for me on several occasions. One time a project I was working on was overdue and I still had to do the admin side of the system. I did not have the time to create an authentication system at that stage. So I made a .htaccess file and used it to password protect the whole admin folder. What would have take me hours was over in a few seconds. .htaccess saves the day. Afterwards, I had to code the authentication system myself in PHP because the project needed some features like multiple admins, password retrieval etc. Anyway, it saved me from work the first day.

Try it out...

Let's say that we are trying to protect the '/var/www/htdocs/top_secret' folder. We will make this folder inaccessible to all but our user 'james_bond'. He will access it using the highly secure and unguessable password 'secret'.

  • Username : james_bond
  • Password : secret

First we go to the folder we are protecting(ie '/var/www/htdocs/top_secret') and create the .htaccess file in this directory. Put these lines in the .htaccess file...

AuthUserFile /var/www/safe/.htpasswd
AuthGroupFile /dev/null
AuthName TopSecret
AuthType Basic

require user james_bond

Open the location /var/www/safe/(create this folder if it doesn't exist) and create a file called '.htpasswd' with this line...

james_bond:tbuUG6kXINUbo

Fire up your favorite browser(it should be Firefox - anything less is sacrilege) and point it to the location http://127.0.0.1/top_secret. If all went well, you should see a Username/Password prompt. You will only be allowed in if you provide the valid username and password(james_bond/secret).

Explanation

.htaccess

AuthUserFile /var/www/safe/.htpasswd
AuthGroupFile /dev/null
AuthName TopSecret
AuthType Basic

require user james_bond

The first line says the location of the file with the username and password. For security reasons, this file is kept outside the document root. We don't want any yahoos with a web browser accessing our .htpasswd file. You will have to change this to the location where you kept your .htpasswd file.

The second line is the full path of a text file containing the list of user groups that should be allowed in. This line is not relevent in our context as we don't have any groups - we are just pointing it to a null file.

The third line 'AuthName TopSecret' is the name of the area you are protecting. You can change this as you see fit. This text will appear in the prompt for the username and password - like this...

Enter username and password for "TopSecret" at ...

The fourth line 'AuthType Basic' is used because we are using the basic authentication scheme.

The last line 'require user james_bond' says that only user 'james_bond' can enter. If you have multiple users in the .htpasswd file, you can use the line...

require valid-user

Now any user in the .htpasswd file can enter.

.htpasswd

This file is a list of all users in the format... <USERNAME>:<PASSWORD>

The username is given in plain text while the password is encrypted using the 'crypt' function. You can generate this password using the 'htpasswd' command in linux. For example running the command...

htpasswd -c .htpasswd james_bond

will ask for a password. Once the password is provided, the program will create the file '.htpasswd' in the current folder with the user 'james_bond' and the given password.

If you are not on linux or if you are afraid of typing commands in the console, you can create the password using one of the many online password generators out there...

Or if you want to create the password yourself, the PHP code is given below...

$username = 'binny';
$password = '';

//Create a random salt
$chars = str_shuffle( "012456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+=-`[];',./\{}:\"<>?|" );
$salt  = $chars[rand(0,strlen($chars))] . $chars[rand(0,strlen($chars))];

//Print the username:password pair
print $username . ':' . crypt($password,$salt);

If you don't understand the above code, just use this...

crypt('password');

This will return the encrypted password. For more information, see the PHP manual entry on crypt.

Problems

No matter what you do, you can't get the username/password prompt. You just go to the page directly. This is because your apache server is not reading the .htaccess file. Open the server configuration file(usually /etc/httpd/conf/httpd.conf). Search for the text 'AllowOverride'. Find the AllowOverride setting for the document root folder(something like /var/www/htdocs). Change this line to...

AllowOverride All

This setting will make sure that the apache server reads and uses the .htaccess file. After making this change, restart the server with the command 'service httpd restart'.

For more information, see the apache documentation.

Filed Under...

Read More...

Configuring Apache with .htaccess

.htaccess files are used by apache to enable the web developer to specify the server configure for the folder that the .htaccess file recides in.

.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
Apache Manual

.htaccess is a very powerful way to control the server on a folder-to-folder basis. But if possible, it is advised to use the main server configuration file(httpd.conf). The apache server can be configured in a folder by folder fashion in the <directory> section of the main configuration file. There are two disadvantages of using .htaccess file rather than the main configuration file(httpd.conf) are...

Disadvantages of .htaccess

Performance
Apache will look for .htaccess file in every parent folder of the file whenever a request is made for the file. So if you turn on the .htaccess file support, there will be a performance hit - even if you don't use them - as apache will search for the files anyway.
Security
Anyone with access to the document root(through FTP or Shell Access) will be able to modify the server configuration. You don't want to do that.

Advantages of .htaccess

If we have a large site with a lot of directory based options, the httpd.conf file will soon become a big and unmaintainable file. Putting the configuration of each directory in that directory(as in the case of .htaccess) is a more maintenance friendly solution.

You may not have access to the main server configuration file. If your site is hosted on a shared server(like mine is), this is often the case. In such cases .htaccess is a life saver.

If you make a change to the httpd.conf, you must restart Apache for it to take effect. On the other hand, .htaccess file have no such problems.

More on .htaccess in the next post.

Reference

Filed Under...

Read More...

Multiple Site in Apache with Virtual Hosts

As you may know already, I have more than one site. When I use my linux system as the development server, I cannot use two different servers to run the two sites - I use one apache server with virtual hosting. This is a very useful site - it enables you to run multiple sites using just one server.

The term Virtual Host refers to the practice of running more than one web site (such as www.company1.com and www.company2.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.

Apache manual

In this post I will show how to create multiple virtual hosts on your server. To keep matters as simple as possible, I will create two virtual hosts - 127.0.0.5 and 127.0.0.10. The first will point to the location /var/www/htdocs/binco/(Bin-Co Site) and the second to /var/www/htdocs/openjs/(OpenJS.Com). The IPs 127.0.0.5 and 127.0.0.10 should be safe to use as they are in the loopback address range(127.*.*.*).

First open the apache configuration file (usually at /etc/httpd/conf/httpd.conf). Next find the line that says '# Virtual hosts'. Look at the lines below this line. In my system they are...

<VirtualHost *>
  DocumentRoot /var/www/html/
  ServerSignature email
 DirectoryIndex index.php index.html index.htm index.shtml 
  LogLevel debug
  HostNameLookups off
</VirtualHost>

This is the default virtual host. To add two new virtual hosts, add these lines below it...

<VirtualHost 127.0.0.5>
 ServerAdmin binny@example.com
 DocumentRoot "/var/www/html/binco"
 DirectoryIndex index.php index.html index.htm index.shtml
 HostNameLookups off
</VirtualHost>

<VirtualHost 127.0.0.10>
 ServerAdmin binny@example.com
 DocumentRoot "/var/www/html/openjs"
 DirectoryIndex index.php index.html index.htm index.shtml
 HostNameLookups off
</VirtualHost>

This will create the virtual hosts - but as the IPs we have given (127.0.0.5 and 127.0.0.10) will be not recognized by apache and it will try to do a host name look up everytime apache is started. This will take a lot of time(and fail). To disable this 'feature' open the file /etc/hosts file and add the following lines to the end.

127.0.0.5  binco.localdomain binco
127.0.0.10  openjs.localdomain openjs

After doing all these steps, you should restart the server with the command service restart httpd. If everything went as planned, you can open Firefox(or your favorite browser), point it to http://127.0.0.5/ and see your site appear there. Of course, I don't have to say that you will have to use your own directory paths and names on your system.

The instructions I have given are for Linux OS running Apache 2 - if you using a different setup, you may have to do a few thing differently. I have done this in a Windows XP system also - only very small differnce between the two.

Filed Under...

Read More...

Apache

So far, we have covered editors and browsers in linux. Next we will be looking at one of the flagship products for Open Source Software - Apache. The web server of choice for most web developers. The 'A' in LAMP.

Apache or HTTPD server is most used web server - beating all other servers - even IIS from Microsoft. Other web servers available in Linux are...

lightTPD
lightTPD is an Open Source web server designed and optimized for high performance environments. With a small memory footprint compared to other bigger servers, effective management of the cpu-load, and advanced feature set (FastCGI, CGI, Auth, Output-Compression(deflate, gzip, bzip2), URL-Rewriting and many more) LightTPD is the perfect solution for every server that is suffering load problems..
Abyss
Abyss Web Server is a compact web server available for Windows, MacOS X, Linux, and FreeBSD operating systems. Despite its small footprint, it supports HTTP/1.1, dynamic content generation through CGI/FastCGI scripts, ISAPI extensions, native ASP.NET support, Server Side Includes (SSI), custom error pages, password protection, IP address control, anti-leeching, and bandwidth throttling.

Installing Apache is not very hard - just reffer to the official apache documentation. Make sure that you have enabled all the necessary modules while installing apache. There are some very useful modules in apache like mod_rewrite and mod_deflate. In most distributions, apache is already available.

Some useful tricks for Apache in the next post.

Filed Under...

Read More...

Subscribe to : Posts