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, ...
🌐
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.
🌐
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 ...
🌐
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 - In addition, it allows you to move between directories. 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 ...
🌐
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.
Find elsewhere
🌐
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%
🌐
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.
🌐
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.
🌐
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 ...
🌐
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
🌐
Reddit
reddit.com › r/php › php web server?
r/PHP on Reddit: PHP Web server?
December 21, 2023 -

Reading the documentation is confusing me a little.

I have experience writing a Nodejs web server with Express and EJS for routing and templating. I’ve made a couple websites and its pretty easy to spin up a node server with my specific routes.

I’ve also been interested in Go for writing a server backend.

The PHP docs say i need to use a Server like Apache or Nginx.

Can i write a Go server and use PHP? Can I write a server with PHP? Is PHP the templating language then?

Is Apache like Node and PHP is like Express and EJS?

Can someone share some insight im missing? Or point me in the right direction to make a PHP web server?

Thanks in advance

Edit: Thank you all for your advice and sharing your knowledge. I have a better grasp of what is going on now. Much appreciated

🌐
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:
🌐
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....