T
T
topuserman2020-07-28 14:30:17
PHP
topuserman, 2020-07-28 14:30:17

How does a webserver and php work?

I have been working as a web developer for a long time, and to be honest, I have never delved into the work of a web server, and there were no such tasks.

Now I want to close the gap in my knowledge, I'll figure out how a web server works, what layers it consists of, and what chain of interaction.

I have always used the classic web server scheme: apache+nginx.
And all I know is

  1. nginx plays the role of the first layer, and immediately gives all the static itself.
  2. the remaining requests are given to the next layer - apache
  3. apache itself interacts through a certain interface (as far as I understand, called SAPI) with the php core.


Do I understand correctly that SAPI is a way for a system (nginx or apache) to interact with php ?

How does the schema work when pure nginx is used? there some kind of sapi is used?

I would be grateful if someone would schematically describe and tell the connections between these components, and their areas of responsibility.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Dmitriev, 2020-07-28
@SignFinder

Apache has a mod_php module that handles the code.
nginx\lighttpd does not have a module and they need a separate service\server to which they will pass the code via TCP or unix socket.
For php it is php-fpm

F
FanatPHP, 2020-07-28
@FanatPHP

Once again: two web servers is an obvious crutch, caused only by the curvature of the user's hands, but by no means a technical necessity.
The web server, of course, only needs one.
The classic scheme in 2020 is one web server and PHP connected via FastCGI PHP.
It can be either Nginx+PHP-FPM
or Apache MPM Event+PHP-FPM. If you install Apache in modern distributions, then this option is installed by default.
In the end, it all comes down to the mammoth-old CGI protocol: the web server redirects the request to the handler (in this case, PHP), the handler returns the HTTP headers and (optionally) the response body, the web server gives them to the client.
In its simplest form, a separate web server is not required, see built-in server in PHP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question