I am trying to create content by a script running outside Drupal. I know this is possible, and probably done better, using REST. But the script below is so simple to set up and works very fast that I'd like to try and get it to work in D10->, like it did in D7.  

This code (from the final entry in this post), works to retrieve user and node data, running, for testing purposes, inside the Drupal root folder...

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();

//run script as user id 1 to avoid any permission problems
$user_id = 1; 
$user = \Drupal\user\Entity\User::load($user_id);
print("<pre>".print_r($entity,true)."</pre>");

$em = Drupal::service('entity_type.manager');
$user = $em->getStorage('user')->load(1);
$node = $em->getStorage('node')->load(1);
echo $user->id(), ' ', $user->label(), "\n";
echo $node->id(), ' ', $node->label(), "\n";

However when I add code to create a node, I get an error:

$nodex = $em->getStorage('node')->create([
   'type'  => 'page',
   'title' => 'This is the Title',
   'body'  => 'Some text in the body.',
]);
$nodex->save();

Server error: 
[Sat Nov 22 12:29:52.469644 2025] [authz_core:error] [pid 60160:tid 60260] [client 162.158.238.118:0] AH01630: client denied by server configuration: /var/www/vhosts/example.com/httpdocs/.git

Searching on the error message gives clues like:
If you are using Apache 2.4, you have to check allow and deny rules. This seems to lead into server configuration issues which seems strange as data retrieval works. 

In a D7 site this code creates an entity:

require_once 'core/includes/database.inc';  // no such file in D10
require_once 'core/includes/schema.inc';    // no such file in D10
$em = $kernel->getContainer()->get('entity_type.manager');
$entity = $em->getStorage('node')->create(array(
    'type'        => 'article',
    'title'       => 'Druplicon test',    
 ));    
$entity->save();

What puzzles me is that so much works without error. I can access Drupal database data without issue. The problem is I can't write to which suggests that some include statements may be missing, corresponding to the D7 require_once lines above.

Can anyone help with the code to replace the error lines in the above script which will create a node?  Thanks.