Running PHP Server on Local Machine
With the advent of PHP 5.4, developers have access to a built-in web server for conveniently testing PHP files locally. The following steps guide you through the process:
Execute the following command:
php -S 127.0.0.1:8000
This command starts the PHP server on your local machine, listening on port 8000.
To enhance the functionality of your local server, consider implementing a simple router. Here's an example:
// router.php if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) { return false; // serve the requested resource as-is. } else { require_once('resolver.php'); }
After saving the router file, run the following command:
php -S 127.0.0.1:8000 router.php
This enhanced server configuration allows for more flexible routing and resource handling.
References:
The above is the detailed content of How to Run a PHP Server Locally Using the Built-in Web Server?. For more information, please follow other related articles on the PHP Chinese website!