PHP 5.4 and later have a built-in web server these days.

You simply run the command from the terminal:

cd path/to/your/app
php -S 127.0.0.1:8000

Then in your browser go to http://127.0.0.1:8000 and boom, your system should be up and running. (There must be an index.php or index.html file for this to work.)

You could also add a simple Router

<?php
// 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');
}
?>

And then run the command

php -S 127.0.0.1:8000 router.php

References:

  • https://www.php.net/manual/en/features.commandline.webserver.php
  • https://www.php.net/manual/en/features.commandline.options.php
Answer from GardenRouteGold on Stack Overflow
🌐
PHP
php.net › manual › en › features.commandline.webserver.php
PHP: Built-in web server - Manual
If an index.php or index.html is found, it is returned and $_SERVER['PATH_INFO'] is set to the trailing part of the URI. Otherwise a 404 response code is returned. If a PHP file is given on the command line when the web server is started it is treated as a "router" script. The script is run at the ...
Discussions

How to run a PHP server on your pc! (Using PHP webserver) - Informal - InfinityFree Forum
Extract the .zip the site give you (in a folder like C:/php), now make a index.html or index.php and put the code you want in it. Running the server. Go to Command Prompt in the folder and run this cmd: “The-PATH-to-PHP.exe” -S localhost:8000 and boom your local server is online (only for you). More on forum.infinityfree.com
🌐 forum.infinityfree.com
0
December 7, 2025
Is There A "simple" way of running PHP soely through Visual Studio Code?
php has a testing server by default (not fit for production): php -S localhost:8000 router.php https://www.php.net/manual/en/features.commandline.webserver.php Other than that, to run php command line straight from VSCode use "Code Runner": https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner it works really well. if you want to get off of Xampp, try docker / docker compose. if you're having issues with your PHP binary, that's a problem on your system, not VSCode. More on reddit.com
🌐 r/vscode
3
2
April 1, 2024
Best/easiest/safest way to run php development server only on local network?
You're probably using the easiest way. Honestly it's only insecure in that php built in server isn't a full fledge webserver, so there'll be things it won't cache or block, but if you got folks in your local network, you have bigger problems. You could install apache 2 for Win, and use Event Schedule to run them in the background. Can't give step by step, but it's not terrible, got that running on my other machine. Other option is setting up a VirtualBox VM instance that shares your host IP, installing nginx or apache and PHP there, and getting the IP that VM is using and accessing your machine via that IP in your network. Both of these take some setup, though the VM route is probably the best long term route. Docker is another route, but honestly never set that up myself. Think they have recipes to quickly set up a PHP webserver, probably a ton of howtos. But, you're probably fine for now. More on reddit.com
🌐 r/webdev
5
1
June 28, 2023
PHP Web server?
PHP, natively, doesn't handle HTTP request directly. The standard/common setup is to run it behind a webserver, like Apache and nginx, with PHP-FPM. Basic workflow: HTTP request comes in and the webserver inspect it. If it's a static asset (like an image) it's served directly. If the requested URI is for a PHP file, handle the request to the PHP engine (an wait for a response). So no, there's no app.run(); in vanilla PHP. That said, there are alternative ways to run PHP. They mostly work as an application server, similar to what you're used to. But that isn't the default, native way. To answer you question: you very likely just need nginx + PHP-FPM. Just out of curiosity, FrankenPHP is a app server that uses Caddy under the hood, a web server written in Go (Caddy can be used standalone with PHP-PFM just like nginx). More on reddit.com
🌐 r/PHP
34
19
December 21, 2023
🌐
Aaron Saray
aaronsaray.com › 2023 › run-php-local-server-like-live-server
Run PHP Local Server Like live-server | Aaron Saray
November 19, 2023 - (The -z tells it to connect, but not attempt to send anything.). Finally, open is assigned to the last return value of previous command. Finally, once we’ve retrieved a port that works, we run two commands. First, a sleep 1 and then opening the URL. This is ran in the background. The sleep is because it takes a split second for the PHP server to start - and once it starts, it keeps this function and the script open.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-execute-php-code-using-command-line
How to Execute PHP Code using Command Line? - GeeksforGeeks
If you need to run a PHP script in the background (e.g., for long-running processes), append & to the command: ... This will run the script in the background and free up the terminal. PHP includes a built-in web server that you can use for testing purposes.
Published   July 12, 2025
🌐
PixemWeb
pixemweb.com › home › php › php cli – built in web server
PHP CLI - Built In Web Server - PixemWeb
August 4, 2020 - In your terminal application, you would use the below command which starts with php followed by the -S flag and then your host/ip and port number. ... Create a php file and name it either index.php if it’s going to be the root file, or give ...
🌐
Medium
medium.com › laravel-developers › start-a-php-server-in-any-folder-with-one-command-66fc85832b69
Start a PHP server in any folder with one command | by Varun Pujari | Laravel developers | Medium
February 15, 2019 - Sometimes, we might want to start a PHP server is a particular folder instead of moving the whole folder to public folder of local server. We can do this by run single command in command line
🌐
HostAdvice
hostadvice.com › blog › web-hosting › php › setup-a-php-server
How to Start a PHP Server: Everything You Need to Know
May 22, 2025 - To start the PHP server, use the command php -S localhost:8000 in the terminal · You can visit the site by using localhost:8000 as the URL across all browsers · You should test the PHP server by creating a simple PHP file and checking that ...
Find elsewhere
🌐
WordPress
make.wordpress.org › cli › handbook › how-to › how-to-start-webserver
How to start the webserver – WP-CLI - Make WordPress
July 1, 2025 - $ wp server PHP 7.2.24-0ubuntu0.18.04.4 Development Server started at Thu Jun 4 17:40:13 2020 Listening on http://localhost:8080 Document root is ../wpdemo.test Press Ctrl-C to quit. The command above starts the server using the default settings.
🌐
Grav
learn.getgrav.org › 17 › webservers-hosting › php-built-in-web-server
Php-built-in-web-server | Grav Documentation
The PHP command line (CLI SAPI) has a built-in Web server that is useful for quick Grav site testing or demos. It is not a full-featured Web server and should not be used on a public network. On the command line, navigate to the [GRAV_ROOT] folder. Run php -S localhost:8080 system/router.php to ...
🌐
Medium
sirolad.medium.com › six-easy-setup-for-local-php-development-beginners-cfbed13c851e
Six Easy Setups for Local PHP Development — Beginners | by Surajudeen Akande | Medium
October 31, 2019 - Similar to using ST3’s Build System, running PHP code within your Atom editor comes out of the box. Just run cmd + I or Ctrl + I. Starting PHP server within Atom editor is easy by using this plugin. With this, you can easily spin up your server ...
🌐
Envato Tuts+
code.tutsplus.com › home › php › php scripts
How to Run a PHP File - Code - Envato Tuts+
April 30, 2020 - The preferred way of running PHP files is within a web server like Apache, Nginx, or IIS—this allows you to run PHP scripts from your browser. That’s how all PHP websites work! The other way is to run PHP scripts on the command line, and it doesn't require you to set up a web server.
🌐
Quora
quora.com › How-do-I-use-a-PHP-server-on-a-local-host
How to use a PHP server on a local host - Quora
Answer (1 of 2): Mac - Open Terminal and navigate to your project folder - Run: --- php -S localhost:8000 --- - Open `http://localhost:8000` Windows (Standalone PHP) - Install PHP from PHP - Open Command Prompt in your project folder - Run: ...
🌐
Plesk
docs.plesk.com › en-US › obsidian › administrator-guide › web-hosting › php-management › running-php-scripts-from-the-command-line.76345
Running PHP Scripts from the Command Line | Plesk Obsidian documentation
You can run PHP scripts in the Command Line for a particular PHP version used in Plesk. In Plesk for Linux, the PHP binary (the php file) is located in the following path: ... Here <PHP version> should be replaced with a particular PHP version number. For example, if your domain uses PHP version 7.0, use the following command to run the my_script.php script:
🌐
InfinityFree
forum.infinityfree.com › informal
How to run a PHP server on your pc! (Using PHP webserver) - Informal - InfinityFree Forum
December 7, 2025 - Extract the .zip the site give you (in a folder like C:/php), now make a index.html or index.php and put the code you want in it. Running the server. Go to Command Prompt in the folder and run this cmd: “The-PATH-to-PHP.exe” -S localhost:8000 ...
🌐
Rip Tutorial
riptutorial.com › running built-in web server
PHP Tutorial => Running built-in web server
Built-in server is designed only in controller environment for development and testing purposes. ... Now yout should be able to see content in browser. To check this, navigate to http://localhost:8080 · Every access should result in log entry written to terminal ... Get monthly updates about new articles, cheatsheets, and tricks. ... This website stores cookies on your computer. We use cookies to enhance your experience on our website and deliver personalized content.
🌐
SunAnt Interactive
sunant.com › home › developer tips
Running PHP from Windows command line
November 13, 2020 - Note: Use semicolon to delimit between System Variables. 3. Open the CMD and enter PATH. Verify your PHP System Variable has been added.