问题
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?
回答1:
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":
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.
来源:https://stackoverflow.com/questions/42455270/setting-up-localhost-server-for-macos-sierra-to-use-php-and-apache