How to Run a PHP Server on Your Local Machine
Setting up a PHP server on your local machine allows you to test PHP files before uploading them to a web host.
Solution:
With PHP 5.4 and later, you can use the built-in web server:
php -S 127.0.0.1:8000
Visit http://127.0.0.1:8000 in your browser to verify that your server is running.
Additional Router:
To create a more robust router, use the following code:
// 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'); }
Then, run the command:
php -S 127.0.0.1:8000 router.php
References:
The above is the detailed content of How do I run a PHP server locally?. For more information, please follow other related articles on the PHP Chinese website!