How can I run a php without a web server?

前端 未结 5 679
孤城傲影
孤城傲影 2020-11-30 00:10

I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the ste

5条回答
  •  囚心锁ツ
    2020-11-30 00:57

    You should normally be able to run a php file (after a successful installation) just by running this command:

    $ /path/to/php myfile.php // unix way
    C:\php\php.exe myfile.php // windows way
    

    You can read more about running PHP in CLI mode here.


    It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:

    $ php -S localhost:8000
    

    You can read more about running a PHP in a Web Server mode here.

提交回复
热议问题