How can I run a php without a web server?

前端 未结 5 671
孤城傲影
孤城傲影 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:52

    See https://github.com/php-pm/php-pm.

    Works fine with symphony.

    But I'm fighting with it, trying run a slim app

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-30 01:04

    PHP is a normal sripting language similar to bash or python or perl. So a script with shebang works, at least on linux.

    Example PHP file:

    #!/usr/bin/env php
    
    <?php
    
    echo("Hello World!\n")
    
    ?>
    

    How to run it:

    $ chmod 755 hello.php  # do this only once
    $ ./hello.php
    
    0 讨论(0)
  • 2020-11-30 01:04

    You can use these kind of programs to emulate an apache web server and run PHP on your computer:

    http://www.wampserver.com/en/

    http://www.apachefriends.org/en/xampp.html

    0 讨论(0)
  • 2020-11-30 01:13

    For windows system you should be able to run php by following below steps:

    1. Download php version you want to use and put it in c:\php.
    2. append ;c:\php to your system path using cmd or gui.
    3. call $ php -S localhost:8000 command in a folder which you want to serve the pages from.
    0 讨论(0)
提交回复
热议问题