-2

I want to create a server for php codes to server ajax httprequest.

1.Web Server sends a POST HTTP request by the way of AJAX to this Server, and the php codes in this Server takes the request, and responds via Echo.

Do I need an apache server installed? or just php.

Thanks, techfang

techfang
  • 97
  • 7
  • 1
    PHP isn't a web server, it's a scripting language. Since you do need a web server, as you say, Apache is rather necessary, yes. (Caveat, asterisk: PHP ships with a ***development*** web server, and you can write a web server in PHP, but both are bad ideas in production.) (Asterisk 2: there are also other web servers than Apache.) – deceze Jul 07 '16 at 09:45
  • 2
    See http://serverfault.com/questions/629493/why-do-we-really-need-apache-php-if-php-can-run-as-web-server – iainn Jul 07 '16 at 09:47
  • See: http://stackoverflow.com/a/31287094/3392762 – Progrock Jul 07 '16 at 10:17
  • @decese Actually PHP has its own built-in webserver since 5.4. The command-line is `php -S binding_address:tcp_port -t document_root`. Example: `php -S localhost:8080 -t ~/public_html`. – RockTheShow Jul 07 '16 at 10:32
  • @Léo Did you read my *entire* comment? – deceze Jul 07 '16 at 11:30

1 Answers1

1

You mention that you're sending an HTTP (POST) request to a server. Which then runs the request through the PHP parser and executes it. Then you ask, do I need an HTTP server?

The answer seems obvious: yes, you do.

Does it need to be Apache? No, it does not need to be Apache; you can also use other HTTP servers such as for example Nginx or Node.

But in the end, to be able to handle an HTTP request, you need a HTTP server. Not just the parser that parses and executes the php script.

Tularis
  • 1,506
  • 1
  • 8
  • 17