78

I just started developing PHP projects on my mac (using PDT) and was wondering where localhost is located? How does Mac OS X serve websites, I haven't changed any settings during the installation of PDT.

Tassisto
  • 9,877
  • 28
  • 100
  • 157

10 Answers10

181

There are actually two place where mac os x serves websites by default:

  1. /Library/WebServer/Documents --> http://localhost
  2. ~/Sites --> http://localhost/~user/
Tassisto
  • 9,877
  • 28
  • 100
  • 157
Chris Muench
  • 17,444
  • 70
  • 209
  • 362
  • I don't know how I did this, but I have both of these folders and 2nd one is the working one, but the httpd.conf file is under /etc/apache2 and ServerRoot there shows the first folder. How can I find the httpd.conf file the server is using? – tekin beyaz May 13 '20 at 16:35
  • I have edited httpd.conf under /etc/apache2 and changed DocumentRoot and Directory to same folder /Users/{username}/Sites and everything is "It Works!" now :) I am not deleting these comments, hoping this may help someone. :) – tekin beyaz May 13 '20 at 18:53
21

For posterity

I never use PHP so I completely forgot where apache was installed on my mac as it was running on port 8080 mocking me, installed in a non-standard path. After giving up on the internet, I tried this...

httpd -t -D DUMP_INCLUDES

Because httpd was running it produced the httpd.config path and then the clouds parted and the sun shown brightly on my face. Victory! as within it lies the path to localhost.

ServerRoot "/your/path"

Mac OS 12 root*

/usr/local/var/www

*credit @cong-lb

King Friday
  • 25,132
  • 12
  • 90
  • 84
  • 2
    ServerRoot actually specifies the webserver's executable directory. One should actually look for "DocumentRoot" wherein you can find the path for the files that are being served by the Apache Server. – Sachin Khosla Apr 02 '18 at 16:43
  • 1
    @SachinKhosla would be good to provide a script that would locate DocumentRoot. Maybe grep 'DocumentRoot' / -rli ? – King Friday Dec 23 '18 at 02:09
  • In macos 12, the path has changed. It worked for me. My path is /usr/local/var/www – Cong LB Sep 09 '22 at 02:09
17

The default Apache root folder (localhost/) is /Library/WebServer/Documents

Also, make sure you have the PHP5 module loaded in /etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so
McKayla
  • 6,879
  • 5
  • 36
  • 48
8

If you use apachectl to start or stop, then you can find it with this command

apachectl -t -D DUMP_RUN_CFG
Olusola Omosola
  • 847
  • 9
  • 9
4

Actually in newer Osx os's, this is stored in /Library/WebServer/Documents/

The .en file is just an html file, but it needs special permissions to change, so I just made a folder for my stuff and then accessed it by user.local/Folder/file.html

3

There's no such thing as a "localhost" folder; the word "localhost" is an alias for your local computer. The document root for your apache server, by default, is "Sites" in your home directory.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • That's not the root folder. Root is `http://localhost/`. The folder you're refering to is located at `http://localhost/~User/`. – McKayla Mar 19 '11 at 21:41
  • 2
    +1 for the "localhost" hate, even though ~/Sites is only half the answer. – Charles Mar 19 '11 at 22:06
3

I realized you need to start service first.

  1. Start apache service sudo apachectl start

  2. Test in browser by hitting localhost You should get "It works" message in the browser

  3. Serve your files inside /Library/WebServer/Documents folder. Make directories if necessary.

Important: Notice in step 3 that it is /Library and not ~/Library

Tested in MacOS 11.2.3 Big Sur

bikram
  • 7,127
  • 2
  • 51
  • 63
0

Macintosh HD/Library/WebServer/Documents

Macintosh HD is the name of your HD

If you can't find it: Open Finder > click "Go" at the very top > Computer > Your HD should be there. You can drag and drop the HD to favorites on the left.

-2

open the 'Finder' in Mac and Command+Shift+G and type in the path:/usr/local/zend/apache2/htdocs. path will open then create/paste your web page/application then check it on the browser.

Rajesh M
  • 79
  • 1
  • 13
-11

Applications -> XAMPP -> htdocs This is the place where you should put your files for the website you're building.

Dragi
  • 1