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
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
Install and run XAMPP:
Updated link for download https://www.apachefriends.org/download.html
Videos
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