03 Local PHP Home

03 Local PHP Home

Terminal Command Method

Stackoverflow is a wonderful place to get information regarding nearly any programming langauge and certain scenarios that may or may not be easy to find through their documentation. The first method to get PHP running locally without having an active server (or not wanting to upload straight to the server) is to run a command through the terminal. Clicking on the article title above will bring you to stackoverflow.com where the command required is already presented, as well as a brief explanation as to what to do after. This only works with MacOS, however.

XAMPP Method

A second method is to install XAMPP, a development environment that works great with PHP, as well as other server-side scripting languages. With this, you can open up the command prompt and connect to the directory with your PHP files that are being worked on. Next, run the simple command "php -S localhost:8000" and head to localhost:8000 in your browser and you will be connected to your page. Keep that page up to maintain a live status of the page and just refresh the browser when any updates are made.

Command Line

While also using the command line, this method is different from the first. This method allows the user to run PHP code through the command line. However, this method is not for all PHP usage, being limited to certain tasks that don't require connection to a server. With this method, just go through the command prompt and find where 'php.exe' is located, and when you locate it, run "path/php.exe filename.php" and the code will execute. For further details regarding the specifics, visit the link above to read more about this method.

To Summarize

Running PHP Locally is great for when the developer doesn't have access to a running server, or when they simply want to test certain scripts and their functions without damaging their active server (if they have one). Of course, when testing locally it can limit the functions of PHP, especially with the third method, but it's a great way to test some new code and get some practice.