1

Note: I am not going to lie, I know pretty much nothing about apache, servers, local host, etc so please pardon my ignorance - if there is a comprehensive or a great review out there for these things, please point me in their direction. I did try and read some online tutorials such as this one, but this all seems to be more than I need.

Context

I have some learned and then made some minimal PHP code that I want to test locally. However, that appears to mean that I need to use a server. Apparently LocalHost can serve that purpose. So I have made a directory ~/Sites which stores different directories each housing a small website (each with subdirectories such as assets, css, js, etc and the actually html pages).

Question

How do I set-up whatever I need to set-up so that I can specify the root of one of this small websites (e.g. ~/Sites/a_website/index.html) as the local host so I can see if my PHP code works?

Community
  • 1
  • 1
SumNeuron
  • 4,850
  • 5
  • 39
  • 107

1 Answers1

2

Go ahead and download XAMPP, which is probably the most popular local environment for development.

Once it's installed, open the XAMPP Control Panel, and click "Manage Servers": enter image description here

Start the Apache Web Server. Your computer is now running as a 'localhost environment'.

If you go to your browser and type localhost, you should be greeted by a orange "Welcome to XAMPP" page.

In Finder, navigate to Applications > XAMPP > xamppfiles > htdocs, which is where you "create your sites". For example: inside the htdocs directory, I would make a folder called test which inside would be my relevant HTML, CSS, PHP etc - if I now went in my browser to localhost/test, I would see that site just like I would if it was hosted online.


Feel free to ask any further questions.

Zac Webb
  • 653
  • 6
  • 22
  • Hey Zac, this is a good answer and very straightforward. Just one issue... When I click `Start` the Apache Web Server does not start.... Restart All, Stop All and Start All has no affect on the icon indicator either – SumNeuron Feb 25 '17 at 12:48
  • Strange, never had that happen before @SumNeuron - after some research I think it is because there is already an Apache server running on MacOS: try entering `sudo apachectl stop` into Terminal to stop the process and then try starting the server again through the XAMPP Control Panel. If that doesn't work, upload your XAMPP log found in `Applications > XAMPP > Logs > Error_Log` to pastebin.com and post it here so I can have a look. Cheers – Zac Webb Feb 25 '17 at 12:57
  • So the apachectl stop worked... but local host says "It Works" in black font rather than an orange "Welcome to XAMPP" page... – SumNeuron Feb 25 '17 at 13:03
  • Also the directory `xamppfiles` does not exist under either User or System level Applications (`~/Applications/` or `/Applications/`) Thoughts? – SumNeuron Feb 25 '17 at 13:06
  • In regards to `xamppfiles`, I made an error in my original post - the path is `Applications/XAMPP/xamppfiles/htdocs/` - whoops! – Zac Webb Feb 25 '17 at 13:08
  • Not quite sure about the "It Works" page, try clearing your browser cache and reload `localhost`. Make sure you started the Apache server in the XAMPP Control Panel as well. – Zac Webb Feb 25 '17 at 13:10
  • Ok, it is there under system's applications. Clearing the browser cache and restarting the Apache Web Server from XAMPP did not solve the problem... – SumNeuron Feb 25 '17 at 13:16
  • Ok, so if I type `http://localhost` I get "It Works!" but if I then click refresh I get XAMPP... – SumNeuron Feb 25 '17 at 13:18
  • 1
    Hmm - I guess try creating a folder in `htdocs` with a test `index.html` in it to see if it works. – Zac Webb Feb 25 '17 at 13:20
  • follow up question, is there a way to get local host to pull from `~/Sites` rather than the XAMPP obscure - to me - path? – SumNeuron Feb 25 '17 at 13:20
  • I think this should do the trick: http://stackoverflow.com/questions/8060533/how-to-change-xampp-htdocs-directory-in-osx – Zac Webb Feb 25 '17 at 13:22
  • One last question - I hope - if I want to simulate uploading a file, does it just go to the directory on my local machine? – SumNeuron Feb 25 '17 at 13:28
  • Hahaha no worries. Yes it will do, if you have a site that includes a file upload function, it will upload info that directory – Zac Webb Feb 25 '17 at 13:33