Can't access my local apache server from other computers
bradster
Status: New User - Welcome
Joined: 20 Mar 2004
Posts: 4
Reply Quote
I have had an apache installation running for a while on my local network, I use it for web development. I have been able to reach my server from other test machines only off and on, this is getting annoying. Can anyone give me advice on how to solve this?

I am running windows 2000, with apache 2. Apache runs great on my local machine. I have set the hosts files to accept local connections to my files.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
there's a few things that might be causing that, I'll run them down, let me know if one of them fixed it.

1. Your hosts file might be too long. Open up the hosts file, in winnt/system32/drivers/etc/hosts

Open it in a decent text editor, not notepad, that has trouble with file names with no extensions.

you will have something like
127.0.0.1 site1 site2 site3

and so on. I've found that you can't have too many items per line, maybe 10 max, then start a new line, with
127.0.0.1 site 11 site12
and so on.

If that's not a problem, check to see if it's a firewall problem, the newer zonealarms for example have strict settings that will block other machines from accessing apache, it blocks all outgoing traffic if set on high security, that's found in zonealarm/security tab.

that's often the source of these kinds of problems.

I assume that you have the httpd.conf listening ports set correctly since you said it was working then stopped.

Once you have your local machine up and running as a server, all you have to do is add the following to other machines on the network:

192.168.0.3 site1 site2

and of course you've already changed your hosts file on the local server have this:

127.0.01 site1 site2

This tells the machines to use this first when you type in site1 or site2 into the address bar of the browser, the whole web used to run off manually configured hosts files, obviously it got complicated when more and more sites got added, but all computeres still have the capacity to do this, machines always check their hosts files first for any url you request. I make my sites have very short abbreviations for my local server sites, less typing, makes no difference what you call it in hosts or virtual hosts, as long as it's consistent.

Let me know if this solved the problem.
Back to top
bradster
Status: New User - Welcome
Joined: 20 Mar 2004
Posts: 4
Reply Quote
jeffd, thanks, it was the Zonealarm high security setting, I don't remember setting that at high, but I did update my zonealarm recently, maybe that's the new default setting? I don't know, anyway, I set it back to medium security and I can now reach my server on my network fine, thanks for the advice.

Oh, I changed my hosts files just in case there were too many entries, like you suggested, though that didn't seem to make too much difference with this problem, but it doesn' hurt. I actually didn't know you could have multiple lines of 127.0.0.1 entries, I thought it all had to be on one line, no linebreak, but now I see that all I am doing is telling my pc to look in 127.0.0.1 for the addresses that follow it before doing a dns search, so there can be as many lines as I want.

thanks again
Back to top
MatthewHSE
Status: Contributor
Joined: 20 Jul 2004
Posts: 122
Location: Central Illinois, typically glued to a computer screen
Reply Quote
So how do you set up different "sites" on your own machine for the hosts file to point to? Also, once that's set up, how do you go about allowing other machines on the LAN to connect to your sites?
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hi MatthewHSE, there are a few steps you need to do first:

Set the ports listening on httpd.conf. Your local server must have a static IP set of course:
:: Code ::
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
Listen 127.0.0.1:80
Listen 192.168.0.3:80 [change to your server ip address]
#Listen 80


You'll need to tell the server to run php on the pages, you can do this individually for each virtual hosting account you create, since all my sites use php, I set it in the configuration file:
:: Code ::
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
AddType application/x-tar .tgz
AddType image/x-icon .ico
AddType application/x-httpd-php .php .html .htm


Make sure your virtual hosts configuration is set correctly in your httpd.conf file is set correctly:
:: Code ::

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *

##LOCALHOST##
<VirtualHost *>
   ServerName localhost
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/program files/apache group/apache2/htdocs"
</VirtualHost>

## site 1  ##
<VirtualHost *>
   ServerName site1
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/websites/site1"
   <Directory "c:/websites/site1">
      AllowOverride None
   </Directory>
   php_value include_path ".;c:/websites/site1/includes"
   DirectoryIndex index.php index.html index.htm
</VirtualHost>

## site 2  ##
<VirtualHost *>
   ServerName site2
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/websites/site2"
   <Directory "c:/websites/site2">
      AllowOverride None
   </Directory>
   php_value include_path ".;c:/websites/site2/includes"
   DirectoryIndex index.php index.html index.htm
</VirtualHost>


There are other ways to set this up, this is the way I use, it works perfectly.

AllowOverride None

tells apache not to use the .htaccess file.

Usually you'll be using an htaccess file to do the server configurations on shared hosting accounts, but it's easier to just set those up for the shared hosting and use httpd.conf for your local server, that way you don't have to change the paths each time.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hi MatthewHSE, there are a few steps you need to do first:

Set the ports listening on httpd.conf. Your local server must have a static IP set of course:
:: Code ::
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
Listen 127.0.0.1:80
Listen 192.168.0.3:80 [change to your server ip address]
#Listen 80


You'll need to tell the server to run php on the pages, you can do this individually for each virtual hosting account you create, since all my sites use php, I set it in the configuration file:
:: Code ::
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
AddType application/x-tar .tgz
AddType image/x-icon .ico
AddType application/x-httpd-php .php .html .htm


Make sure your virtual hosts configuration is set correctly in your httpd.conf file:
:: Code ::

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *

##LOCALHOST##
<VirtualHost *>
   ServerName localhost
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/program files/apache group/apache2/htdocs"
</VirtualHost>

## site 1  ##
<VirtualHost *>
   ServerName site1
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/websites/site1"
   <Directory "c:/websites/site1">
      AllowOverride None
   </Directory>
   php_value include_path ".;c:/websites/site1/includes"
   DirectoryIndex index.php index.html index.htm
</VirtualHost>

## site 2  ##
<VirtualHost *>
   ServerName site2
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/websites/site2"
   <Directory "c:/websites/site2">
      AllowOverride None
   </Directory>
   php_value include_path ".;c:/websites/site2/includes"
   DirectoryIndex index.php index.html index.htm
</VirtualHost>


There are other ways to set this up, this is the way I use, it works perfectly. Note that on windows, the include_path uses:
.;
On Unix/Linux that would be:
.:

AllowOverride None

tells apache not to use the .htaccess file.

Usually you'll be using an htaccess file to do the server configurations on shared hosting accounts, but it's easier to just set those up for the shared hosting and use httpd.conf for your local server, that way you don't have to change the paths each time.

Once this part is up and running, you can set up the rest of the hosts files on the other machines on the network, same thing, except instead of using:
127.0.0.1 site1 site2

you'll use
192.168.0.3
[replace with local server ip address]
giving you
192.168.0.3 site1 site2

This tells the machine where to look for the address: site1 or site2
Rather than making a request to a dns server, it just uses the ip you gave it. This is how the web used to work a long time ago, before dns servers, and it's still a useful tool.
Back to top
erikZ
Status: Contributor
Joined: 30 May 2004
Posts: 148
Reply Quote
Remember that you need to restart Apache to make any change to the httpd.conf file active.

I use the apache services monitor in windows, I don't know if XAMPP has that, it probably does, but I can't say for sure.

Personally, I prefer setting the stuff up piece by piece too, it's easier to know what is doing what in that case, but it's hard to argue with being up and running in a few minutes.

Apache.org has pretty good stuff on configuration, especially in their faq section and the HTTP server 2.0 documentation, although I have to admit it can be amazingly obscure sometimes, often it's easier to just ask on a forum than to try to decipher apache's way of explaining things :-)
Back to top
MatthewHSE
Status: Contributor
Joined: 20 Jul 2004
Posts: 122
Location: Central Illinois, typically glued to a computer screen
Reply Quote
Right, I restarted Apache after each change to httpd.conf, but each time I tried to set up a virtual host, the whole thing failed (as in I couldn't even access localhost anymore). I don't know what I'm doing wrong; I've gone all through the Apache documentation on virtual hosts but frankly can't make head nor tail out of it. I'll be giving it another try later when I have time. In the meantime, if you have any suggestions . . . you know I'm not adverse to advice! ;)
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4124
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
You've found the first problem with using these all in one packages, since you didn't set it up, it's hard to know what's wrong.

Best thing is to go back to the point it last worked, then see if the basic configuration is working.

that means, create a test page on localhost account, in the local host folder, see if you can run some php on it:

<?php echo 'hello world'; ?>

That will tell you the whole system is working.

then you have to see what the specific xampp configurations are in httpd.conf, which from what I can see are not the defaults of a clean apache 2 install.

this is not a bad thing, but it does mean some of what jeffd said above will not be applicable for your httpd.conf file I believe.

Once you have a localhost account up and running we can go back through the httpd.conf file and see what needs to be modified to make it support virtual hosts properly.

I'm assuming that you have done the following:

created directories for your websites.
created a hosts file that has the aliases for those sites.
have apache and mysql starting as services in Windows 2k
you are not using nod32 antivirus, which kills apache, unfortunately.
you have turned off any software firewall during testing to make sure that's not the problem.

If the answer is no to any of the above you'll need to get that done.

If the answer is yes, we can try to figure out just what it is that xampp httpd.conf needs to get running as a virtual hosts server.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours