Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Finding my localhost folder.

I seem to be in an unending battle with PHP.

If I open Safari and enter:

+ http://localhost/+

it shows me:

"+It works!+"

which (if my memory serves me correctly) was a page that I created when I went through the battle with getting PHP configured before (about a year ago).

How do I find this file and so determine where my actual ' localhost' folder is, so that I can begin (again) trying to develop a webpage using PHP? Or (in other words) how do I find the location of the file that says +"It works!+"? If I go to the Finder and ask it to find "It works!" it spews hout HUNDREDS of files, none of which look like the one that I am looking for.

iMac 24 inch, 2.8 GHz, Mac OS X (10.6.6), 4 Gb RAM

Posted on Jan 15, 2011 8:25 AM

Reply
17 replies

Aug 1, 2017 9:44 AM in response to noondaywitch

noondaywitch wrote:


You can create a website in any folder you like. I have around six different sites in different locations. As long as you're happy with your filing system the only thing that matters is that the page files have the correct extensions (.htm or .html, .PHP, .CSS, JS, etc.) and they all link to Index.html (or.PHP etc).

Location on your computer is irrelevant.

To check the site in a browser, just drag and drop the index file onto the browser icon in the Dock.

Message was edited by: noondaywitch

I can't drop the index.php file in the browser icon in the Dock. How do you do?

Jan 15, 2011 8:38 AM in response to pforkes

pforkes wrote:
OK, sow I am REALLY confused!
In /Library/WebServer/Documents there are the following files:

.DS Store
PowerByMacOSX.gif
PowerByMacOSXLarge.gif
index.html.en
index.php
phpmyadmin
test.php
wordpress

NONE of these files contain the text "+It works!+"


Really?

Pele:~ jdaniel$ cat /Library/WebServer/Documents/index.html.en
<html><body>

It works!

</body></html>Pele:~ jdaniel$

Jan 15, 2011 8:42 AM in response to Barney-15E

You are right. That files DOES have the text, as you say.

So, does this mean that I have to put ALL my html & php files, etc. into this folder if I want to be able to create a website? I do not recall having to do this before.

Other websites that I created are in pforkes/Sites.

Can I 'reconfigure' OS X to that I can create new websites in pforkes/Sites?

Jan 15, 2011 8:44 AM in response to pforkes

pforkes wrote:
You are right. That files DOES have the text, as you say.

So, does this mean that I have to put ALL my html & php files, etc. into this folder if I want to be able to create a website? I do not recall having to do this before.

Other websites that I created are in pforkes/Sites.

Can I 'reconfigure' OS X to that I can create new websites in pforkes/Sites?


You have to put your site(s) files in the location you set up as the document root in your Apache web server config files. What you are seeing is the default location for a newly installed system.

Jan 15, 2011 8:55 AM in response to pforkes

You can create a website in any folder you like. I have around six different sites in different locations. As long as you're happy with your filing system the only thing that matters is that the page files have the correct extensions (.htm or .html, .PHP, .CSS, JS, etc.) and they all link to Index.html (or.PHP etc).

Location on your computer is irrelevant.

To check the site in a browser, just drag and drop the index file onto the browser icon in the Dock.

Message was edited by: noondaywitch

Mar 2, 2011 11:30 AM in response to noondaywitch

Ok, so I'm as confused as Pforkes. I have activated php and apache in my mac. So I get the page "it works" when i enter http://localhost. However, I cant get a simple php file to run. I have it saved in localhost/~ rialaado/Sites/serverTest.php but when i enter this into the browser url it doesnt work. Can you help? What is wrong with this address?
Thanks

Message was edited by: Rialaado

Nov 17, 2013 6:44 PM in response to pforkes

I highly advise that you make a backup of any system files before modifying them.


This will explain how to setup and activate localhost on your Mac, and how to change the default directory.

If your localhost is not currently setup or active follow these steps:

  • From Finder, select Go -> Go To Folder -> /etc/apache2/users
  • Look for a file named username.conf (where username is your username)
  • If such a file does not exist, create it and open it, if it does exist, open it.
  • Copy and paste the following into the username.conf file, replace username with your username.

<Directory "/Users/username/Sites/">

Options Indexes MultiViews

AllowOverride All

Order allow,deny

Allow from all

</Directory>

  • Save and close that file. You will be prompted to enter your administrative password because you are modifying a system level file.
  • Move up one directory so you are in /etc/apache2/
  • Look for and open a file named httpd.conf
  • Open a search prompt and enter the query: php
  • You should then be looking at a line that reads as follows or similarly (may be slight variations based on the PHP version)

LoadModule php5_module libexec/apache2/libphp5.so

  • Remove the # from the beginning of this line
  • Save and close the file and provide your administrative credentials.

Open Terminal and enter and run the following command to restart Apache and you are all set.

sudo apachectl restart

To modify the root directory that is displayed when you browse to http://localhost follow these directions

  • Similarly to above, open the httpd.conf file.
  • Open a search and query: DocumentRoot
  • You should then see a line that reads as follows

DocumentRoot "/Library/WebServer/Documents"

Modify this line to the directory path you would like to use as your root localhost directory. Be sure to type out the full directory path. For example I created new folders in my root user folder for 'Published Projects' and 'Projects' so I adjusted mine to read like so:

DocumentRoot "/Users/davidcondrey/Projects/

If for example I wanted the 'Target' folder in the 'Sites' folder that sits on my 'Desktop' it would look like this:

DocumentRoot "/Users/davidcondrey/Desktop/Sites/Target/

Restart Apache one more time with the terminal command:

sudo apachectl restart


And now your done. So now when I go to http://localhost I see the index.html or index.php file in the root directory of my Projects folder.

Finding my localhost folder.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.