Recently I got the source code of a simple PHP website. Obviously I’m not a PHP developer. However, I’m curious on how to launch the website on my MacBook. In searching, I found a simple way to launch a PHP website on macOS using its in-built PHP server. This may not be a solution for someone to develop and debug PHP websites. But, it will help you to check basic PHP websites and web pages.
Tools Used
- PHP 7
- macOS Big Sur
Start the PHP server
First, start the inbuilt PHP server by following these steps:
- In the finder, go to the folder with the php website code.
- Right click the folder. From the popup menu, select the option New Terminal at Folder to launch the terminal window for the folder.
- In the terminal window run the command php -S localhost:9000.
- The server starts listening to http://localhost:9000. Just leave the terminal window without disturbing it. Once you close the terminal, the server will stop running.
Launch the PHP website
Now, go to any browser and run the address http://localhost:9000/. If the folder has an index.php file, then it will load the webpage. Else, you have to add the webpage name to the url like http://localhost:9000/something.php.
Shutting down the PHP server
Go back to the terminal window and press Ctrl + C buttons to shut down the PHP server. Then you can quit the terminal.
Hope this article will help you to quickly run or launch a PHP website on macOS.
Reference
- More about using PHP on macOS at php.net.