John Bokma Windows tips and tricks
freelance Perl programmer

Comments: Installing and configuring Apache on Windows XP

66 comments

If you design websites you might want to install a web server on your computer in order to test your sites in an environment that matches the real thing as close as possible. This article describes how to install and configure the open-source Apache HTTP (web) server and how to make it work with not one site but as many as you require using a technique called name-based virtual hosting.

Read the rest of Installing and configuring Apache on Windows XP.

Comments

Hi John

Now don't laugh but I am 70 yrs old guy trying to understand this modern technogley. You lesson on Apache is the first I have understood. I am looking forward to your PHP lesson. Thanks for making things more clearer

WIlf

Posted by Wilf at 19:34 GMT on 16 March 2006

You're welcome Wilf, and I am not laughing, but hoping that I am able to do such things when I am 70.

Thanks

Posted by John Bokma at 20:23 GMT on 16 March 2006

Just wanted to say thank you for your tutorial it helped me tremendously.

gf

Posted by gf at 14:29 GMT on 31 March 2006

sir, Thanks for making things more clearer.

Posted by sundar at 05:24 GMT on 7 April 2006

Hi John;

Your tutorial on Apache Installation is great!

Thanks a lot.

Regards.

Boboy

Posted by boboy at 03:20 GMT on 10 April 2006

I just installed Apache following your instructions. Very easy, indeed.

I am having problems when pointing to http://localhost/cgi-bin/printenv.pl - I get 500 Internal Server Error.

When I go to command prompt and change directory to C:\Perl\cgi-bin\ and type perl printenv.pl I get response, but not with the browser http://localhost/cgi-bin/printenv.pl

WHY?

Posted by Daniel at 07:56 GMT on 10 April 2006

For PC security, I have both administrator & limited user accounts on an XP machine. Daily usage is on 'limited' user and all installations & maintenance is done through 'admin' user.

Having searched for 'start stop apache server xp user', ( as I needed to start/stop apache & sql servers logged in as a limited user in WinXP ), I immediately found this article and it answered everything & more.

The 'run as Administrator' fix is so obvious I could kick myself. However, had I not done this search I wouldn't have picked up the tips for directory structuring to mirror my Web Server.

It also shed more light on my Virtual Servers, which currently work fine, but I can now tweak them a little more for ease of future implementation.

My thanks to you and your Apache Help page, John.

Happily running Apache-2.054, MySql-3.23.58, Perl-5.8.6.811, php-4.4.0, phpMyAdmin-2.6.2, MySqlCC-0.9.4, Smarty-2.6.9, DreamweaverMX on local Win32 platform for a Unix Hosting Server.

php-5 & MySql-4 currently seem reluctant to work so I must defer to the old adage 'if it ain't broke .... don't fix it'.

regards, Jake

Posted by Jake at 15:50 GMT on 17 April 2006

Forgot to mention in last message :

As far as Windows OS go, I am a Win98 kind of guy.

I reluctantly moved to Win2k in 2002.

I loath XP with a passion and have only just got round to installing it permanently, hence my disbelief at the simplicity of the solution to my problem.

Linux Rocks - hell, anything OpenSource is better than the regurgitated offal from Casa Gates - If only I could do everything I need to from this platform..........

Annyhoo, hope you enjoy your life south of the border...

regards, Jake

Posted by Jake at 16:12 GMT on 17 April 2006

@Daniel: you might want to change the first line of printenv.pl to contain the path to perl.exe. It probably now states:

#!/usr/local/bin/perl

Changing it to:

#!C:/perl/bin/perl.exe

does the trick, if on your system this is the path to the perl program as well.

Another option is using:

ScriptInterpreterSource registry

in your configuration file (httpd.conf, or a file you include by adding an Include directive to httpd.conf)

Posted by John Bokma at 19:39 GMT on 17 April 2006

I've made several attempts in the past few years to do this. I've always got caught up with the Apache docs. I think they're written for people with a lot more network knowledge than I have. I've always been able to get the server installed, but tripped up on getting the virtual hosts thing working.

Your article cleared the fog away and I now have it all working. Simple, straightforward and now I know what I missed before.

Thank you!

Although .... even though I took the options you said (or I thought I did) it doesnt run on port 80 - only on port 8080. Is that because IIS was running when I installed? Should I delete Apache again and reinstall or can I reconfigure it?

Posted by Mike Kear at 02:56 GMT on 24 April 2006

@Mike Kear - yes, IIS uses port 80, so Apache won't run on port 80 as well. I have IIS configured to run on port 8080 since I use it only for one project I am developing for a customer.

Apache is used in several projects, so I prefer port 80 for Apache.

Posted by John Bokma at 20:24 GMT on 28 April 2006

Thank you! Thank you! Thank you! You've just saved my life....this is a really great tutorial...

Posted by sorcha at 16:32 GMT on 1 May 2006

I have to say that your site was the first I hit on a google search for setting up a local host server to test webpages before publishing them. Very informative and helpful, as I now have a successfully running apache 2.2 web server hitting the loopback address for all my websites.

Thanks!

Posted by TheSquirrel at 05:09 GMT on 15 May 2006

I got a 500 Internal Server Error

when run perl(pl)of cgi

Any one can help ?

Posted by new boy at 22:34 GMT on 16 May 2006

This is the best article I have read on the subjuct!

However - I still cannot get it to work.

What exactly do I type in the browser to access my local site? For apache's default page, I type http://localhost No problem there.

For my virtual host setup (dev.ffcc.org) I try typing http://dev.ffcc.org

It wants to connect me to the internet, instead of serving up the page locally. I must be missing something.

Runing apache 1.3.27 on windows xp.

I have followed the instructions to the letter, modifying the httpd.conf and the hosts files. Re-boot.

I did get it to serve up my web site site under "localhost" instead of apache's default page, by removing the virtual host directive for local host.

any help would be appreciated.

Chris

Posted by Chris at 22:43 GMT on 26 May 2006

Great tutorial. Thank you very much

Posted by vlad at 01:07 GMT on 27 May 2006

Follow up to my earlier post - IE wants to dial up when I try to access my virtual hosts. I thought my vhost setting were wrong. But I nearly went crazy, because one moment it worked, and the next it did not. And so forth many times over. If I did not connect to the internet, my page would not found (because I was then "working offline").

I will share my solution for anyone else who may bang their heads up against the wall ...

My internet connections setting was the problem "always dial my default connection". Being on dial-up service this is convenient, but problematic. I could not access virtual hosts without being online (the whole point is to be able to access them without being online!) Because I was searching for a solution, I was online, following instructions which seemed to work. Then I would disconnect, go about setting everything up, test, and it wouldn't work!

Solution: change the setting to "never dial a connection". Maybe it's a windows/ IE thing.

Once again, your page is really great, the best I have seen written. Except for this little snafu, it all works beautifully. I am thrilled to finally have this set up properly!

Thank you!

Posted by Chris at 02:59 GMT on 28 May 2006

Thanks. Its a great great tutorial to work with. I installed Apache 2.2 and PHP 5 on Windows XP machine for a testing server. Virtual Host is functioning just fine except that only the first Virtual Host opens up and rest of the domains take me to the first mentioned domain again. I'll try to explain: I've set up 3 domains in hosts file

127.0.0.1
127.0.0.1 www.mysite1.com
127.0.0.1 www.mysite2.com
127.0.0.1 www.mysite3.com

and I included the right syntax in virtual-hosts.txt file like this

# Use name-based virtual hosting.
NameVirtualHost *:80
<VirtualHost *>
    ServerName www.mysite1.com
    DocumentRoot "E:/www/mysite1"
</VirtualHost>
<VirtualHost *>
    ServerName www.mysite2.com
    DocumentRoot "E:/www/mysite2"
</VirtualHost>
<VirtualHost *>
    ServerName www.mysite3.com
    DocumentRoot "E:/www/mysite3"
</VirtualHost>

All of the above 3 directories exist with contents. But opening any domain takes me to first virtual host (i.e. www.mysite1.com). When I try to browse www.mysite3.com, it is supposed to take me to the contents of E:/www/mysite3, it doesn't, rather it takes me to the contents of E:/www/mysite1. same is the case when I try to open www.mysite2.com. it takes me to mysite1.com. what might be wrong?

Posted by Sana at 19:38 GMT on 6 June 2006

Thanks very much for this - it's the first comprehensible tutorial on this topic I've ever come across!

However, for some reason the method you describe doesn't quite work on my computer, but with a little playing around with hosts and the virtual-hosts.txt file, I managed to get it to work. In case it's of any use to anyone:

I found that if all my virtual hosts were 127.0.0.1, it would only direct to one of them. However, if I set them up in the 'hosts' file as:

127.0.0.1 localhost
127.0.0.2 lc.example.com
...

and so on, and then instead of I used , and so on in the 'virtual-hosts.txt' file, then everything worked fine.

Is that a sensible alternative way of doing things, do you think?

(One other thing: I found that it seems I have to close and re-open my browser for it to register changes in the 'hosts' file - worth trying if you're having problems getting things to work).

Once again thanks for a tutorial that finally helped me to do something I've been trying intermittently for weeks to get to work.

Nick

Posted by Nick at 00:21 GMT on 7 June 2006

Hi John,

Thanks for a great article. It is easily the most understandable I have come across.

I have a question for you:

In addition to the apache/cgi-bin folder I have an additional cgi script folder for an application in c:/docorg/program/cgi-bin.

I have given permission for cgi scripts to be run from this folder using the following in the httpd.conf file:

<Directory "C:/docorg/program/cgi-bin/">
    Options +ExecCGI
    Allow from all
</Directory>

And have associated the extension .pl with perl.exe in the windows registry. But, although I can successfully run a perl test file in apache/cgi-bin, when I try to run it in docorg/program/cgi-bin it does not work. Instead, it looks as though the browser tries to download something (presumably the perltest.pl file?) and then nothing happens.

Any ideas on what I am doing wrong.

Thanks in advance on any advice you can offer.

Nick.

Posted by Nick at 10:37 GMT on 13 June 2006

If only this tutorial had been available when I first set up my Apache Server! Very well written and very easy to understand, and great tips on virtual hosting, I can now clean up my conf file. Good tips about keeping the security stuff ABOVE root as well, very sensible advice. PHP advice would be most welcome now as I have never properly used it before.

Posted by Steve at 21:23 GMT on 25 June 2006

Hello!

I've got the latest Apache installed, and the default localhost message is "It works!". When I try to access lc.myweb.com I get the same message, even if there isn't a index.html there. BUT when I try to access 127.0.0.1 I get a 403 error.... is this a problem?

Thanks - otherwise a perfect tutorial!

Posted by Richard at 02:39 GMT on 13 July 2006

Hi! Sorryo ther you again...

I've checked the syntax of my virtual hosts file, and when I use

NameVirtualHost *:80

<VirtualHost *>

Apache reports that NameVirtualHost *:80 has no virtual hosts...

Any thoughts?

Posted by Richard (Again!) at 03:13 GMT on 13 July 2006

Dag John, Bedankt voor deze heldere uitleg.

Posted by Kees at 08:22 GMT on 14 July 2006

Hi John,

I am installing Apache into my WIndows XP and I've encountered error messages about the httpd.conf "Os 10048". Something like only one usage of each socket address ..."

I am trying to install Apache and PHP into my XP.

It would be much appreciate it if you could help me.

Kind regards,

Alvin

Posted by Alvin at 12:18 GMT on 14 July 2006

Hi Alvin,

It sounds like something else is already using port 80. I understand that Skype uses port 80 but there might be other programs as well (for example IIS, the web server of Microsoft).

Posted by John Bokma at 19:11 GMT on 16 July 2006

This is a good tutorial - it will come in handy for many projects - is it possible to install and Dual Boot Apache and IIS?

There seems to be a renewed interested in Dual Booting as of late

Posted by SEARCH Engine WEB at 07:21 GMT on 20 July 2006

@SEARCH Engine WEB - I guess you mean running side by side (dual boot means having the option at start up to select an operating system).

Yes, this is possible. You have to configure either Apache or IIS to use a different port to listen to if they use the same IP address. For example I have Apache using port 80 and IIS using port 8080 on my development machine.

Posted by John Bokma at 20:32 GMT on 30 July 2006

Thanks, the tutorial really helped me installing apache 2.2

Posted by Giambi at 13:09 GMT on 11 August 2006

Hi, John. I am from Malaysia and found your tutorial on configuring Apache HTTP web server. I am using version 2.2. Previously, when i configured it according to the manual from Apache, i cant even view http://localhost/cgi-bin/printenv.pl , but after i added the ScriptInterpreterSource registry in it. It coulld run. But file with extension .cgi will be downloaded. How can i fix this?

I have added ExecCGI in the root Options directive and AddHandler cgi-script .cgi .pl plus ScriptInterpreterSource registry in cgi-bin directory. Thx

Posted by raymondtan at 01:47 GMT on 17 August 2006

@Sana, Richard - my bad, my original article contained a mistake (fixed now):

<VirtualHost *>

should have been:

<VirtualHost *:80>
Posted by John Bokma at 02:29 GMT on 31 August 2006

hi... i have apache and php installed (latest versions of each). everything works fine locally.

however, when i try to browse some sites online, they will not load. the page simply trys to load and gives no time out error. It seems to be mainly sites that use some form of cgi.

this has only started since i installed and setup apache and php on my machine to use as a localhost. Any ideas on whats' happening?

the hosts file in /drivers just has the 127.0.0.1 localhost url in it.

thanks for any help you may provide!

Posted by jeffro at 22:09 GMT on 1 September 2006

I figured out that Nick's method

127.0.0.1 localhost
127.0.0.2 lc.example.com
...

works. I had however also have to make a virtual host section for the localhost

<VirtualHost *:80>

    ServerName localhost
    DocumentRoot "C:/my/document-root/"


    ErrorLog logs/localhost.error.log
</VirtualHost>

In addition, in the httpd.conf there is a restriction on which clients (identified by IP-address) might access the document root. I had to widen it:

<Directory "C:/my/document-root">
    #...
    Allow from 127.0.0
    #...
</Directory>

replace C:/my/document-root with your own document root.

Hopes this helps someone.

Posted by website-ontwikkeling at 19:36 GMT on 29 September 2006

John,

Thanks for posting this great tutorial.

I installed httpd-2.2.3-win32-x86-ssl/php5/mysql at xp release2

the default localhost message is "It works!". When I try to access www.mysite1.com I get 403 error, even if there is a index.html there.

<VirtualHost *:80>
    ServerName www.mysite1.com
    DocumentRoot "C:/mysite1.com/web"
    CustomLog logs/mysite1.com.access.log combined
    ErrorLog logs/mysite1.com.error.log
</VirtualHost>

I logged in as admin user. your example is for installing apache_2.2.3-win32-x86-no_ssl. is there anything I missed for httpd-2.2.3-win32-x86-ssl

Thanks again

Posted by Howard at 04:38 GMT on 11 October 2006

Brilliant! This information on the Windows hosts file and virtual hosts was a godsend! If you ever need someone to have your babies, look me up.

Seriously, though, thank you. Cheers!

Posted by Josh at 03:48 GMT on 8 November 2006

BIG THANKS!

I'm trying to migrate from fooling with IIS and ASP, to fooling with Apache, PHP, MySQL, - and Drupal. This has really helped me set up a development environment

Posted by Herb at 19:28 GMT on 17 November 2006

Hi,

I installed apache as per ur notes but monitor apache server is not starting n its not showing any services to start in services.msc please reply me in this regards. will be waiting

Posted by muzu at 10:32 GMT on 7 December 2006

Hi john,

i installed apache server 2.2.3 installation got completed succesfully and my monitor apache server started successfuly but when i go to start\programm\apache HTTP server\control apache server\start its giving a error (os 10048) please help me in this regards thanks

Posted by muzammil at 11:35 GMT on 7 December 2006

Hi! I am starting out, but there is a newer version of Apache available and I want to use the newer one, but am reluctant to because your tutorial is on an older one...I don't want to start out blind because your tutorial is very detailed...

Posted by Jane at 09:37 GMT on 17 December 2006

Hi! I read your Installing and configurig Apache on Windows Xp (I am using the same version as the one in the tutorial) but I am stuck when it comes to editing the HOSTS file! It will not let me save...when I try to save, via the 'save as' and the normal 'save', it keeps giving me this warning:

Cannot create the C:\WINDOWS\system32\drivers\etc\hosts file" "Make sure that the path and filename are correct."

I checked the HOSTS file's property and such and it is not 'read-only'. Also, when I try to overwrite it or delete it or move it, it says that the file is in use by another person or process...I've tried everything!

Posted by roat at 13:01 GMT on 17 December 2006

OK. I've installed apache2 for my personal web page.

All I want is that visitors are able to see my html pages only.

What can I do?

When I try to access my domain name, the first thing that comes out is the contents of my folder.

I do not want the whole folder to show, just the main html file that I have placed there. Does anybody have an idea how to change this issue? I am running "Apache 2.0.59".

Posted by Jim at 15:55 GMT on 8 January 2007

Hi Jim,

Are you sure that you have an index.html in your folder? When you access a folder using Apache it attempts to use some files first. If none can be found the contents of the folder is shown, or depending on your configuration, an error is returned to the browser.

If you don't have an index.html file in your folder, try to add it and see if everything is working ok.

Posted by John Bokma at 01:50 GMT on 16 January 2007

hello, i read all and also configured accordingly.in virtual host setting for documentroot in "c://program files/apache group/apache 2/htdoc" it worked fine for my server but placing another html at "C;/program files /apache group/apache 2/include" or any else directory it didnt work... plz kindly guide me

Posted by nageen at 16:53 GMT on 26 January 2007

Thanks John,

I had this up and running in less than 10 minutes thanks to your exquisite tutorial. Great work!

Posted by Ron at 11:02 GMT on 31 January 2007

Just to echo the thanks of many others and the congratulations on providing such a clear explanation suitable even for server-novices like myself.

I feel many times more in control than I did a half-hour ago!

Posted by Dan at 12:34 GMT on 31 January 2007

Hi.. John your tutorial is really great. And most importantly, the first apache tutorial that is well explained among the ones I went through..

Posted by Amjath at 16:17 GMT on 2 February 2007

hey there i tried to install apache with ur instructions and stuff... it get installed, but there are some problems

1- i installed, uninstalled, and installed this stuff many times as i was not able to view the test apache server page ( the one we get to see after typing "http://localhost/" , do i get to reinstall windows for this ? or the uninstall though control add and remove programs is well enuff.

2- i saw that blocking and unblock windows pop up first time when i was installing the apache. now when i install it, it doesnt come.

3- the error that it gives when i write the localhost url in the browser is that connection times out. when i remove the proxies and stuff then it says the page cannot be displayed.

i added the test url in bypass proxy option.

nothing is working. plzzzzzzzzzz help

i am using apache 2.0.59

Posted by Bushra at 09:58 GMT on 13 February 2007

I too would like to add my thanks to this excellent tutorial. It's been a huge timesaver for me.

My only problem is getting CGI scripts to work. I noticed at the bottom of this tutorial that you planned to add one for setting up and using CGI. Any idea if/when you're going to do that, or any quick tips you could give me to get started?

Thanks

Posted by Fern at 15:51 GMT on 13 February 2007

Hello John

Is this going to work Ok with XP Home Edition, just completed a Frontpage course and shown how to load IIS...however XP HE does not support this

Am I doing the right thing?

Many thanks for you help

Posted by Lou at 13:41 GMT on 26 February 2007

@Lou - you might try to install Apache as described in the article.

Posted by John Bokma at 00:23 GMT on 6 March 2007

Thanks John

Great easy to understand tutorial.

I can't wait for you to have one on setting up PHP with Apache, because I have followed other tutorials to the nth degree and it just doesn't happen.

Posted by Lollylegs - Australia at 06:29 GMT on 14 March 2007

In regards to the gentleman (70) who understood your tutorial, I'm 59 and have been a programmer for 35 years, and yours is the first apache tutorial I've fully understood.

Thanks heaps.

Posted by tomk at 08:57 GMT on 3 April 2007

too good i could understand many things.....

thank you very much...

Posted by jeevan at 14:17 GMT on 3 April 2007

Thank you for this Tutorial i was searching about it in search engine finaly i found it here. awesom work !

Posted by Hayssam at 00:57 GMT on 3 May 2007

hi John,

I followed your instructions for installing Apache on Windows XP and created the following virtual hosts:

# default: localhost

    ServerAdmin webmaster@dummy-host2.localhost
    ServerName localhost
    DocumentRoot "C:/Program Files/ApacheWebServer/Apache2.2/htdocs"
    ErrorLog "logs/localhost.error.log"
    CustomLog "logs/localhost.access.log" combined

# gamaingstandards.com

    ServerAdmin webmaster@dummy-host2.localhost
    ServerName lh.gamingstandards.com
    DocumentRoot "C:/Documents and Settings/Rob/My Documents/websites/gamingstandards.com"
    ErrorLog "logs/lh.gamingstandards.com.error.log"
    CustomLog "logs/lh.gamingstandards.com.access.log" combined

localhost works but, when I attempted to go to lh.gamingstandards.com, I get the following error message:

"You are not authorized to view this page"

Any idea how to fix this? I'm the administrator and only user on this machine.

thanks, Rob

Posted by Rob at 05:56 GMT on 31 October 2007

Hi Rob,

Are you sure you have an index.html in the gamingstandards.com folder?

Posted by John Bokma at 16:48 GMT on 31 October 2007

After reading through the many comments and solutions, I tried to install apache 2.2.4 to my existing php5.2.1. For 2 hours, a test php file appeared as a request to download.

After having a cup of coffee and restarting the browser, apache 2.2.4 and php 5.2.1 now works fine. I don't know how it will behave tomorrow.

It's no wonder that some people have been mysteriously blessed with additional zeroes by their bank's computers for no particular reason. So for some of you who are facing this problem, just take a beer of something and perhaps the computer might be more cooperative.

And thanks to John for a helpful tutorial.

Posted by Jet at 16:48 GMT on 6 November 2007

John,

Thank you so much for this site. It has been extremely helpful in debugging a cgi-bin issue related to Apache under Windows.

Posted by Richard at 15:18 GMT on 3 January 2008

Very clear. I followed your Apache and PHP and it simply worked. Kudos, kudos. Rare that someone writes so clearly and with good and helpful picks.

I followed your directory structure -- more or less -- and everything was fine until I added a new one. Apache can't seem to find any new virtuals. Stop/Start, of course. Anything I'm missing?

Posted by Oligonicella at 23:43 GMT on 18 January 2008

Sorry, should have told you -- Apache 2, PHP 5.

Posted by Oligonicella at 23:46 GMT on 18 January 2008

i have configure three virtual hosts. and put a index.html file in their document root.

bur when i was trying to open other virtual sites it always Its Works!

Posted by pankaj at 07:37 GMT on 30 January 2008

hi john, iam pankaj again i am pasting here my virtual server config file in reference to my que.

# Use name-based virtual hosting.

NameVirtualHost *:80


    
    ServerName lc.mysite1.com
    DocumentRoot "C:/www1/web "
    
    CustomLog logs/lc.mysite1.access.log combined
    ErrorLog logs/mysite2.error.log
    





    
    ServerName lc.mysite2.com
    DocumentRoot "C:/www2/web "
    
    CustomLog logs/lc.mysite2.com.access.log combined
    ErrorLog logs/lc.mysite2.com.error.log
    



    
    ServerName lc.mysite33.com
    DocumentRoot "C:/www3/web "
    
    CustomLog logs/lc.mysite33.com.access.log combined
    ErrorLog logs/lc.mysite33.com.error.log
    
Posted by pankaj at 07:52 GMT on 30 January 2008

hi pankaj,

Are you sure the configuration file is read? You can test this by making a mistake in the virtual host file, for example just type something like asdfgsasda after NameVirtualHost. If you stop and then start Apache and the latter fails, you are at least sure that the file is read.

Posted by John Bokma at 03:58 GMT on 1 February 2008

It was Skype which blocked the Socket. After stopping Skype I was able to start Apache! Thanks for your help!

Posted by ukraus at 20:35 GMT on 11 February 2008

Thanks for this tutorial John. I have been programming 25 years but only recently started using Apache/PHP and even some JSP and servlets. I had been using htdocs as my development and testing folder which was getting messy with 6 sites to maintain. I now have 7 virtual hosts, I made an extra one for using as a sandbox.

Posted by Tom at 23:24 GMT on 11 March 2008

Hi! I have problem with Perl and Apache 2. I tried to set up a socket using Perl. But the problem is that when I browser to connect.cgi (I programmed for socket), I can not browser to any other file .cgi (Server only stand on the website that I setup for socket)I do not know why? Can anyone help me?

Posted by Rose at 15:44 GMT on 30 April 2008

Post a comment

Note that your comment doesn't show up immediately. I review each comment before I add it to this site.

Internet adresses will be converted automatically. You can use the following notation to specify anchor text for a link: [url=http://example.com/]example text[/url]. HTML will be ignored.