Create a custom php script in root directory

First of all create a file Create a custom php script in root directory with .phpfile extension in root directory. For example:test.php

Then paste following code in created file and save it:

<?php

use Magento\Framework\App\Bootstrap;
require 'app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
echo 'Hello, This is a test script.';

If the pub folder is root directory, use this code:

expoundsofttechsolution Create a custom php script in root directory
<?php

use Magento\Framework\App\Bootstrap;
require '../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
echo 'Hello, This is a test script.';

And run this script file with this type of URL on your browser: Create a custom php script in root directory

https://your-domain.com/test.php