Is there a built-in server in php?

Asked

Viewed 81 times

2

Sometimes we want to run a simple PHP script to perform tests, but we don’t want to spend time installing wamp, xampp or even installing the apache2 followed by PHP.

Is there any way to run the script in PHP, with some simple server, without the need to install any of the above mentioned application.

  • I didn’t understand -1 followed by +1. KKK

  • 1

    Also did not understand, I gave +1 not to be negative. And as it was already answered there is yes.

  • A chat friend did not know this. I thought it pertinent to post it here so that other people know that in PHP there is a server.

1 answer

5

Yes, there is a way.

From the version 5.4 PHP offers, in its own language, a built-in server.

Just run the following code on the command line:

php -S localhost:9000

This will cause PHP to create a small server to run its scripts. The root of your application will be considered the folder in which the command was executed.

If you want to specify the folder where you will run the script, just use the option -t

Behold:

php -S localhost:9000 -t /var/www/stackoverlow

See more about this at PHP Manual - Built-in Web Server

Browser other questions tagged

You are not signed in. Login or sign up in order to post.