[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Simple and secure blogging software for nginx



On Fri, Mar 11, 2022 at 12:48:28PM -0400, Chris Mitchell wrote:
> I believe Apache and nginx both have fairly robust support for popular
> server-side languages like PHP, so many toolkits will work happily on
> top of either one.

nginx can be told to contact php-fpm in order to run PHP scripts.
Here's a basic outline of what you want:

1) Install nginx.  Set up your virtual hosts ("sites"), so that each
   one is working, at least to the point of delivering an index.html
   page out of the correct site's directory.

2) Install php-fpm.

3) In the virtual host that wants to allow PHP scripts, add a stanza like
   this one:

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;
    }

   The exact path of the unix domain socket will depend on which version
   of Debian (and therefore php-fpm) you're using.

4) Reload nginx, and test it.

This is quite different from the Apache philosophy of "oh, we will
provide a special apache-php module, and you need to configure Apache
to use this module".  nginx uses a more strict separation.  The web
server runs as one user, and the php-fpm daemon runs as a different
user, and they communicate over a unix domain socket.

That will matter if your PHP scripts need to write to files.  You'll
need to make sure the files have appropriate ownership/permissions for
php-fpm to write to them, and *possibly* for nginx to read them, if
they're intended to be served directly.  (If they're not intended to
be served, then don't store them under the document_root, and nginx
won't be able to find them.)


Reply to: