-
Notifications
You must be signed in to change notification settings - Fork 9
Developer tools: Using PHP on Mac OS X 9, 10, and above
PHP is a command that is pre-installed with Mac OS X 9 (Mavericks, Mac OS 10.9, etc.) that can be run through the Terminal application. It allows you to run PHP locally on your computer without having to setup any servers, or downloading any extra software.
First, open up the Terminal app. It is located at /Applications/Utilities/Terminal and has an icon of the text >_ in white.
Next, a window should pop up with the text your-mac's-name:~ your-user-name, replacing your-mac's-name with your Mac's name, and your-user-name with your username (for example, Joe).
After the text appears, you should be able to type in the terminal (don't actually type anything and press enter, you might accidentally do something you didn't want to). Type cd with the space at the end, then the location of your local web site or PHP testing area. Your command should look something like cd ~/Documents/PHP/Testing/.
Tip: Using "~" will specify your home directory, so cd ~/foo will actually bring you to /Users/your-user-name/foo.
Finally, type the command php -S localhost:8000 (new in Mavericks) and press enter to start up PHP. To close it, hold down control and press the C key.
After you've started up PHP, the text Listening on http://localhost:8000 should appear. That means it's working and you can open up the link by going to http://localhost:8000! If there isn't any index.extension (with extension being php, html, or other) then it'll probably show the text Not found - this just means it can't find the index and you'll have to give it an actual file location, such as localhost/about.php.
When I type the PHP command and press enter, it just says -bash: php: command not found. Chances are this is because you're using an older version of Mac OS X. To find out the version of your Mac, click on the apple icon in the top left corner of the menubar and click "About This Mac". It should say the version of your Mac, which is probably 10.8 or lower. Note that Yosemite, the most recent version of Mac OS X, has the php command installed because it is version 10.10.
Typing php and pressing enter doesn't give me anything. Chances are you forgot the extra text at the end, -S localhost:8000. The command should be php -S localhost:8000.
I have an index file in my directory but it gives me Not Found when I open localhost. First, make sure that you've started PHP in the right folder - when you ran php it outputted some text along the lines of Document root is /Users/your-user-name/Documents/PHP/Testing. Make sure that this is the folder that index.php is in. If not, press control-C to close PHP and then cd to the right folder and restart PHP. Finally, if that doesn't work, rather than going to localhost/, go to localhost/index.extension with extension being the extension of your index.
If you need further help, contact us using the methods listed at the OpenSprites website.
OpenSprites http://opensprites.org Live Site (Some features may not work) http://osdev.opensprites.org/ Scratch Forum Thread https://scratch.mit.edu/discuss/topic/85320/ (unread)