How can a public directory be set up for PHP files in order to ensure accessibility?

To set up a public directory for PHP files, you can use an .htaccess file to ensure that only specific files are accessible while restricting access to others. This can be achieved by using the "Options -Indexes" directive to disable directory listing and the "DirectoryIndex index.php" directive to specify the default file to load. Additionally, you can use the "RewriteEngine On" directive to enable URL rewriting for cleaner URLs.

Options -Indexes
DirectoryIndex index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]