Apache on Mac OS X

Discussion in 'Mac Programming' started by jammer08, Jul 23, 2006.

  1. macrumors member

    Joined:
    May 26, 2006
    #1
    Hello, I am trying to host a website on a Macbook. I will be using the Macbook as a dedicated server for my company. I have started personal web sharing in system preferences, and have added the pages to the "Sites" folder... The issue is, when I try to access the website from a computer other than the host, it says I do not have permission to view the page -- how to I go about fixing this? Any help would be greatly appreciated.

    Thanks-
    Justin
     
  2. macrumors 6502a

    panoz7

    Joined:
    Nov 21, 2005
    Location:
    Raleigh, NC
    #2
    You need to have the files in the webserver folder. Its found in library/webserver/documents. I think the sites folder is just for iWeb stuff... i've never used it so I'm not positive though.
     
  3. thread starter macrumors member

    Joined:
    May 26, 2006
    #3
    I will try that - Thank you! :)
     
  4. Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #4
    If you put something in the sites folder in your home directory, it's supposed to show up in http: // your IP address or DN or local hostname / ~ your user name

    It's not for iWeb -- it existed before iWeb did. But you have to have your firewall settings set up so that the requesting computer can see it. If I open my firewall on my iMac for instance, I can see the sites folder from my Axim or iBook, but I can't see it from the extranet, because there's another firewall on my router, right?
     
  5. macrumors 6502a

    panoz7

    Joined:
    Nov 21, 2005
    Location:
    Raleigh, NC
    #5
    Ok... just figured the ~name thing out. What's the point though? Its slightly more convenient to stick stuff in the sites folder, but other then that I see no advantage and its a real pain to have to type in the ~USERNAME thing, especially if you have a strange username.

    The firewall has never given me trouble on the internal network. I've never had to turn it off. Maybe the sites folder is different and is safe-gaurded more?
     
  6. macrumors 68000

    Joined:
    Feb 23, 2006
    #6
    you can configure Apache to change the default directory to your ~ Sites folder
     
  7. Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #7
    If you turn Apache on via OS X (i.e. in System Preferences) it automatically opens the associated port on the Firewall. If you have the OS X firewall up, Port 80 absolutely must be open for a webserver to work. No exceptions, really.... You either have to let OS X do it or do it yourself.

    As far as the ~username... the idea is like any other managed Unix system -- different users can have different web pages. It isn't always called sites, but having a folder within the user folder is the standard way of doing things in Unix.... This way a user does not need to play with root level files. To which they ought not have write access to begin with. Which is the way it should be. ;)

    If you have a domain name, you can always map it onto ~yourusername just as easily as the root.

    But in the end, both folders belong to Apache, and there is only one Apache instance. There's nothing special about either folder... just make sure permissions and accessibility are all set up properly.
     
  8. thread starter macrumors member

    Joined:
    May 26, 2006
    #8
    more confused

    now i am really confused -- i have my htm files in the webserver folder. i have the port (80) open, and when i go to my ip address i get the apache page... when i go to my ip/~user i get a message saying i dont have privelege to view this page... the firewall on the macbook is off and the port on my router's firewall is open :confused: :confused: :confused:
     
  9. thread starter macrumors member

    Joined:
    May 26, 2006
    #9
    BTW-- i have my domain pointed to my ip address. either way i access it (via domain or ip address) i get a permissions error.
     
  10. macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #10
    Do not despair :)

    There are two possible causes for this:

    1.- Permissions have changed on sites folder.

    To fix this, select the Sites folder, Get info (either from the File menu, cmd-I or right click-> get info) and then make sure that everyone has read access on the tab Ownership & Permissions. Make sure Others have Read Only access or you'll be in for some big security risk for your site!


    2.- You do not have an index.html file and Apache is not configured to list folder contents.

    Solution: Put up an index.html page inside your Sites folder, and see if you can access it. If you can, just make sure you rename your homepage! Way easier than fiddling with /etc/httpd/httpd.conf file if you are not used to it.


    Good luck!
     
  11. thread starter macrumors member

    Joined:
    May 26, 2006
    #11

    I have checked folder permissions, and yes, everyone has read rights. I actually had moved my pages to the WebServer folder. I do have an index.html file in the WebServer folder.. still saying no permissions.
     
  12. macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #12
    Justin,

    either the folder /Library/WebServer/Documents doesn't have read permissions, OR (and i think this might be it) your index.html file doesn't have the right permissions set. check that index.html does have read access to everyone.

    By the way, this is not a firewall issue. The message is the standard one from Apache.
     
  13. thread starter macrumors member

    Joined:
    May 26, 2006
    #13

    You were correct!! -- the index file did not have read permissions for others. THANK YOU very much! :)
     
  14. macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #14
    No problem ;)

    By the way, you might want to check permissions on your images folder/files as they present the same issue :D
     
  15. thread starter macrumors member

    Joined:
    May 26, 2006
    #15
    should i leave all of the apache pages in the WebServer folder? also, what is the difference between the Sites folder, and the WebServer folder?
     
  16. macrumors 68000

    Joined:
    Feb 23, 2006
    #16
    Don't forget to turn your firewall back on.
     
  17. thread starter macrumors member

    Joined:
    May 26, 2006
    #17
    Thanks! :D
     
  18. thread starter macrumors member

    Joined:
    May 26, 2006
    #18
    I did, thank you. :)
     
  19. macrumors 68000

    Joined:
    Feb 23, 2006
    #19
    If you want the Apache webserver to serve up a different directory, use terminal

    cd /etc/httpd
    cp httpd.conf httpd.conf.bak (back up the original file)
    nano httpd.conf

    Inside that configuration file under section 2:

    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    #
    </change/this/to/whatever/you/want>

    And a few lines below that:

    #
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "/change/this/to/what/you/changed/above">
     
  20. thread starter macrumors member

    Joined:
    May 26, 2006
    #20
    Do you recommend doing that instead of deleting all of the apache pages in the default directory?
     
  21. macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #21
    There is no benefit on doing that. If you really want to save all your info, just copy all the files and save it somewhere on your HD.
    Unless you have a particular reason to do so, just keep the standard web folder schema.

    The difference between the Webserver and the sites folder is, in short, that the webserver folder is your computer's web site. The sites folders are independet for each user of the machine (hence the ~username after the ip address).

    If you want to maintain your site on your sites folder (so you dont need root permissions for every single update), just put this code on your index.html on your webserver folder:

    <script>
    location.href="~username";
    </script>

    There are tons of alternative ways of doing this (using headers, remapping at http.conf) but I feel this is the easiest way while you get your site admin experience.
     
  22. thread starter macrumors member

    Joined:
    May 26, 2006
    #22
    This machine will be dedicated to hosting just this one website, so i just assume leave it in the WebServer folder -- shouldn't be too hard to keep track of.

    Again, thank you for your help.
     
  23. macrumors newbie

    Wince99

    Joined:
    Oct 31, 2005
    Location:
    Montreal
    #23
    Why did you choose a laptop as a dedicated web server? Wouldn't it be less expensive to put a mac mini on the task?

    :rolleyes:
     
  24. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #24
    I'm glad I wasn't the only thinking this....
     
  25. macrumors 68000

    Joined:
    Feb 23, 2006
    #25
    I wasn't going to say anything.
     

Share This Page