Score:0

How does Php-fpm access filesystem, or does it?

cn flag

Background: My server has become too old to upgrade. Some software will only work on PHP 5.6 and is incompatible with newer versions of PHP. New server hosting packages do not support PHP 5.6 as it was deprecated a while ago.

I am moving the application to a new server that supports docker and I intent to wrap up PHP 5.6 and all its deps into a docker image. I will then reconfigure Apache 2.4 to use fcgi/php-fpm to talk to the containerised php for the domains that need PHP 5.6. My containerised version of PHP-FPM can talk to the platform's MySQL and Mongo.

I've been reading through the PHP-FPM documentation and it is unclear how the files get from Apache to PHP-FPM or does PHP-FPM read the files from the filesystem.

Is PHP-FPM a pure network application i.e. I can put it on any machine on the network and it will translate PHP files and return output with no access to the filing system? In the new set up, PHP will be running in its own container and has its own filesystem. Do I need to care about this?

Can someone help me understand the relationship between PHP-FPM, Apache, source files and the filing system.

Score:1
in flag

Simplified:

Apache httpd maps the incoming request to a location on the web servers file system (i.e. after parsing the DocumentRoot and any/all applicable Alias , Location , mod_rewrite and other expansions).

When that request maps to a PHP file, Apache httpd passes the filesystem location of that file to PHP-FPM for processing and returns the output PHP-FPM generates to the site visitor.

So when your Apache config for example looks like:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/www.example.com

    DirectoryIndex  index.html index.php

    Alias "/my-app" "/var/www/apps/my-app/release-2.3"
 
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost/"
    </FilesMatch>

</VirtualHost>

The directory /var/www/apps/my-app/release-2.3 does not have a index.html, but contains an index.php and possibly other data for your web application.

Thus a request for http:///www.exaple.com/my-app will map to a PHP file on the file system, to /var/www/apps/my-app/release-2.3/index.php

That location is passed to PHP-FPM.
The equivalent of "please parse /var/www/apps/my-app/release-2.3/index.php for me"


Apache does not send to contents of /var/www/apps/my-app/release-2.3/index.php to PHP-FPM. That has several reasons: but one is that only rarely a PHP application consists of only the contents of a single PHP file. Typically other parts of the application code get loaded with include and/or require PHP directives and the PHP interpreter, PHP-FPM will need to load those files as well.


When you run PHP-FPM in a docker container, you will need to make sure that your PHP sources are available and get mapped to the same file-system location as where the PHP sources reside on the web server.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.