PHP service equivalent

Is there any way so that the only accessible file is the main index.php ?

I mean one equivalent to

php -s localhost: index.php

Try

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteRule !^(public/|index\.php) [NC,F]