简体   繁体   中英

How do I run a PHP enabled server from the command line?

I originally started developing PHP via WAMP/MAMP stacks. These work, but there are a lot of painful caveats to deal with.

More recently, I've begun working with other software stacks, like rails, that can run the server from arbitrary directories with a minimum of configuration, muss, or fuss. Just a simple rails -s or python -m SimpleHTTPServer 8000 . (OK, the second one might not be simple).

Unfortunately, the rails one is for running a rails server. The python one sets up a very simple HTTP server. Neither one is appropriate for running PHP code.

Are there any alternatives out there to run a PHP based server from an arbitrary directory -- in this case, the development directory of the app I want to work on? I'd strongly prefer Mac OSX, but if there's a windows version available as well, I'd love to hear about it.

As of 5.4, PHP includes a built-in web server that can be used for development.

For example:

php -S localhost:8000 index.php

Documentation: Built-in web server

But keep in mind:

This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM