Repository

Looks good to me!

User Tools

Site Tools


topic:backend:php:how

How it works?

PHP is a server-side language. When .php files are requested by the user, say https://pyuxiang.com/index.php, any PHP scripts within the file are processed before rendering as HTML. Redirection of such requests to the PHP processor are handled by the webserver.

Example

In Nginx, on top of retrieving the resource, default configurations additionally redirect the resource to the PHP processor for handling.

server {
    listen [::]:80;
    server_name pyuxiang.com;
    location ~ \.php {
        include "cgi.conf"; # TODO
        "something something php7.0-fpm.sock;
    }   
}   

For the request https://pyuxiang.com/index.php, the index.php file is processed, which may look like this:

<!doctype html>
<html>
<head></head>
<body>
  <?php
    echo "Welcome to the website!<br>";
    if (count($_FILES["file"]["name"]) > 0) {
      echo "I see some files in your request...";
    }
  ?>
</html>

which in turns eventually renders to:

<!doctype html>
<html>
<head></head>
<body>
  <p>Welcome to the website!<br/></p>
</html>

Typical modern setups rely on CGI backends, e.g. Python Django, to replicate the same behaviour.

TODO

Add recommended PHP resources.

How to setup?

For nginx specific configuration, see the nginx page.

topic/backend/php/how.txt · Last modified: 24 months ago ( 2 May 2023) by 127.0.0.1