I currently have a file sharing network set up between my mac and pc.
Now, I have a localhost server running on the mac, and I obviously just browse to http://localhost to test my pages when working on the mac and was wondering how I could browse to the pages (localhost on the mac) from the PC (across the network)… is this possible? If so, what do I need to do?
I’m assuming this is OS X. (I don’t know OS X but it’s based on FreeBSD so this command should work.)
If you have router such as Linksys and are using DHCP, an IP other than 127.0.0.1(localhost) is already set. Open a command line prompt window (Terminal Window, I believe) and type ifconfig.
Should get something like this (Note: edited output):
eth0 Link encap:Ethernet HWaddr 00:80:AD:72:E8:9A
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
Hi…thanks for the reply… but I actually use that IP address to connect to my mac (for file sharing) over the network, so I am not sure how I could connect to the localhost server?
Presuming the server is not firewalled nor restricted to localhost for some other reason, you just need to enter the IP address of the mac to view it within your local network. Ie, if the IP was 10.10.1.5, then you would just browse to http://10.10.1.5/ from the other computer.
Hi… yeah, I already have the mac connected across the network, and have used its ip address to establish the connection (192.168.0.5).
On the mac, I have all my files (for Apache localhost) in a folder, and have set up a doc root in httpd.conf, so, when on the mac, I open up http://localhost, and it shows me the site that I am testing locally.
If I was to browse to those files (.php) across the network from the pc, and tried to open one of them, then it would open them with dreamweaver, or my pc’s default app.
So, basically, I wanted to be able to open up the site to test it from the pc , without always having to upload my modified files to my sites remote server for testing.
No. You are connecting to a file share using \\192.168.0.5\ShareName. What you need to do is open a http connection. The best way to do this is to explicitly state “Hey, windows, this is a http connection!” by typing http://192.168.0.5/WhateverRootRelativeUrl.php in your windows browser.
Unless the mac is not properly configured to accept http connections from outside of localhost, that is. In which case, you will need to tweak the apache setup to listen on other addresses.
Hi…
OK, I tested browsing to the directory on my mac (from the pc).
I had a file “index.php” in that directory. When I browsed to that folder (from the pc, in a browser), I was shown the directory itself (files and folders) but, I created a file, “index.html” and saved it to that directory and when I browsed to it again, I was able to see index.html rendered correctly.
So, I can only assume that I will need to tweak Apache (as you mentioned).
I added my pc’s ip address to the following lines in Apache’s HTTPD.conf:
# 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 12.34.56.78:80
Listen 80
#my pc's ipaddress
Listen 192.168.0.6
Is that correct? or do I also need to add the sharename to the end of that? As I did not get any improved results.
I am using the MAMP package, and not OSX’s built in Apache…
There is no share here–I still think you are browsing incorrectly. Do not open windows explorer and go glicking on My Network Places. Do open a web browser and type in the IP address. You need to hit the machine over port 80, rather than whatever SMB is running on.
The reason the html file works is that it does not need server side processing, whereas the php stuff does not work is that you are still browsing to a network share, not hitting the web server.
Regarding the configuration, I am not really an apache guy, but it would help if Apache was listening on the same IP address the mac is using–which you indicated was 192.168.0.5 above and the config has it as .6.
but it would help if Apache was listening on the same IP address the mac is using–which you indicated was 192.168.0.5 above and the config has it as .6.
OK, from what I understood, I needed to configure apache to listen to the PC (ip address 192.168.0.6)… My bad, I will try that when I get home…
As for the browsing issue, I was definitely using the browser, and had entered the address
The file view I got was not the usual Windows Explorer view, it was my servers directory view, with linked files etc… ie: what you would normally see if you went to a website with no index file for example…
No, this is not where you should go. Your webpages should be in Macintosh HD/Library/WebServer/Documents. By default is only here that PHP pages will be parsed.
When you enter http://192.168.0.5 (just that and nothing else, don’t bother with file paths for the moment) in your web browser, you will either see an apache page, index.html, or the parsed index.php.
I have several folders in my Documents folder for various web projects I am working on. For ex., I have a folder called aom which contains the files for a web project and I use http://192.168.0.5/aom/ to run the index.php file in that folder.
You see, when you go to http://localhost on your Mac the browser gets the pages from the websever location (Macintosh HD/Library/WebServer/Documents). So, when you put http://192.168.0.5 in your PC browser the webserver will automatically serve the same default page from the same location (Macintosh HD/Library/WebServer/Documents) to the browser.
Right. The problem is now sorted!
Thanks everone for your help. @Rob_D: As you pointed out, I simply need to browse to that address - http://192.168.0.5 - and the browser loads whichever page I have set as my document root in httpd.conf