Prepare Platform

This is working on an nginx setup service via php-fpm.

  1. Folders and files setup.
  2. Custom php-fpm pool file, and nginx configuration must agree on socket file or IP address.
  3. May try using setfacl - The sites/mysite/tmp folder tree needs rwx for the user "http" on archlinux (or cachyos), which is the user/group for nginx. On Debian the nginx user/group is "www-data". May also have to do some special with root home folder, such as allowing groups to have execute.
  4. Test the supporting PHP environment and framework setup.

I never manage all the mysterious configuration steps at first go. Usually the configuration does not work initially and some searching and checking is needed.

Essentials for a simple mysite.

A google query "linux setup nginx and permissions to execute website from home folder directory" includes some of these non-obvious steps.

Some adjust of access permissions on that file tree, and

# new directory for site
mkdir -p ~/www/mysite

# Need execute permissions to the root of home directory:
chmod o+x /home/myuser
# or even
chmod 711 /home/myuser

# Change the group of the website folder to "http"
sudo chown -R myuser:http /home/myuser/www/mysite
chmod 755 /home/myuser/www/mysite

# Directories get 755, files get 644
find /home/myuser/www/mysite -type d -exec chmod 755 {} \;
find /home/myuser/www/mysite -type f -exec chmod 644 {} \;
  1. In the php-fpm.d configuration directory.
cp www.conf mysite.conf

[mysite]/
user=myuser
group=mygroup

listen = /run/php-fpm/mysite.sock

Using netbeans, test that the Wcc namespace is accessible. Run as a script, as mysite/index.php, at first, rather than as brower fetch.

The setlocale and the autoload need to be successful, and the RouteMatch URL is given directly, and the script run from netbeans, before trying from nginx.

<?php
namespace Wcc;

$locale = setlocale(LC_ALL, "en_AU.UTF-8");
if (!$locale) {
    echo "Bad Locale";
    die;
}
$services = require_once("../wc/php/Wcc/autoload.php");

$config = new Config();
$config->locale = $locale;
$services->set('config', $config);

$rset = new RouteSet();

$rset->addRoute(new Route(Route::GET_I, "/brew/{count}",
    function(int $count) {
        return "$count bottles of beer on the wall.";
        }));

$rm = new RouteMatch("/brew/2", Route::GET_I, Route::AJAX_NONE);

if ($rm->findRoute($rset) && ($rm->prepare_call()))
{
   $result = $rm->call();
   if (is_string($result))
   {
       echo $result;
   }
};

This simple script behaves the same way each time because it has no inputs. The pretend input is the constructor call to the new RouteMatch object. The RouteSet object potentially holds not just one matchable route, but here the only Route object added has the location part of the URI containing the matched parameter ":count". The matchable parameter could have also been expressed in the string as "{count}".

The RouteMatch object has a few basic methods to carry out the "target" instructions, which here is a PHP Closure object which will be called with an array of arguments, in this case the value "[ 'count' => '2' ]" Automatic PHP type conversion allows the closure function to receive it as an integer value.

None of the websites I have ever made make use of a closure like this. The objects and methods called here do all get used, but within a much larger abstract framework. Complexities skipped over here include user sessions and authentication, input analysis, and dynamic web pages and forms creation.

Route objects analysed and stored by RouteSet are divided into fixed URL strings, easy for array string lookup, and ones that vary pattern because of regular expression usage, and need to be checked for a match one at a time. All can make use of additional URL query parameters.

Handle command line arguments

To make use of varying input, simple command line script argument handling will be added, as if arguments from a http request. At startup each PHP binary running the script sets up global arrays with parameters taken from its execution environment. Constantluy accessing these directly seems to be not recommended, because they are a 'global state', although it is typical in code examples.

The class "Wcc\RequestGlobals" makes a writeable copies of the major PHP global arrays. This can be then used as a basis for checking and modifying the script environment. Each global array of interest can be setup as a "Wcc\Hmap" object.