WordPress 404 Error when vieiwing php file direct

Solution:

For security, WordPress wont let you go to that file directly. Your best bet is to give it a template name, assign a page to it then navigate to that page.

<?php
    /* Template name: Your template */
    code
?>

That should run the code you need and you can restrict access to public if you need to in the page settings.