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
I painfully experienced behaviour that I can't seem to find documented here so I wanted to save everyone from repeating my mistake by giving the following heads up: When starting php -S on a mac (in my case macOS Sierra) to host a local server, ...
🌐
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 find the exact file you’re looking for, type in cd your-directory · To start the PHP server on your computer, type in the php -S localhost:8000 command in the command prompt.
🌐
Aaron Saray
aaronsaray.com › 2023 › run-php-local-server-like-live-server
Run PHP Local Server Like live-server | Aaron Saray
November 19, 2023 - Sweet - now you have a locally running web server with PHP at localhost on port 8000 when you run php-server. ... Eagle-eyed readers may have seen that there was a space after the alias declaration. This allows additional parameters to be passed to the command after the alias.
🌐
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 ...
🌐
Packagist
packagist.org › packages › php-kit › php-server
php-kit/php-server - Packagist.org
If it's a name, the directory will be searched for starting at the current directory and going upwards. Alternatively, you may specify the full path. [default: Sites] -f, --foreground Don't run the server as a background process. -x, --executable The path to the PHP interpreter. [default: searched on $PATH] COMMAND stop - Stops the web server.
🌐
GitHub
github.com › wp-cli › server-command
GitHub - wp-cli/server-command: Launches PHP's built-in web server for a specific WordPress installation. · GitHub
Uses php -S to launch a web server serving the WordPress webroot. http://php.net/manual/en/features.commandline.webserver.php
Starred by 68 users
Forked by 19 users
Languages   PHP 81.3% | Gherkin 18.7%
🌐
Grav
learn.getgrav.org › 17 › webservers-hosting › php-built-in-web-server
Php-built-in-web-server | Grav Documentation
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 start the server.
Find elsewhere
🌐
SitePoint
sitepoint.com › blog › php › maintaining your server with command line php
Maintaining your Server with Command Line PHP — SitePoint
November 13, 2024 - In this article we’ll look at the advantages of using PHP CLI. I’ll show you how to test PHP’s Command Line Interface / Interpreter (CLI) on your server, and then we’ll look at some of the options available for PHP CLI including the interactive shell and how to create executable scripts.
🌐
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 - If you want, you can put this command in a .bat file on Windows or .sh file on Linux and copy it to where you want and execute the file to start the server in that folder.
🌐
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
🌐
W3Schools
w3schools.com › php › php_superglobals_server.asp
PHP $_SERVER Superglobal
PHP superglobals are built-in variables that are always accessible in all scopes! Note: The entries in $_SERVER are created by the web server, so there is no guarantee that every entry is available across different servers or environments.
🌐
Rip Tutorial
riptutorial.com › running built-in web server
PHP Tutorial => Running built-in web server
It can be used to run application without need to install other http server like nginx or apache. Built-in server is designed only in controller environment for development and testing purposes. It can be run with command php -S : To test it ...
🌐
DreamHost
help.dreamhost.com › hc › en-us › articles › 214202238-Command-line-PHP-overview
Command line PHP overview – DreamHost Knowledge Base
To run the commands in this article, you must configure a Shell user and log into your server via SSH. The paths for the default DreamHost PHP-CLI installed binaries are as follows:
🌐
Symfony
symfony.com › home › documentation › setup › how to use php's built-in web server
How to Use PHP's built-in Web Server (Symfony 2.x Docs)
Running a Symfony application using PHP's built-in web server is as easy as executing the server:start command:
🌐
Natanfelles
natanfelles.github.io › blog › php-server
PHP Server - Natan Felles
November 26, 2017 - php = PHP_BINARY host = localhost ... post_max_size = 200M upload_max_filesize = 200M [server] ENVIRONMENT = development · You can use the command php-server new to create a new configuration file in the current directory....