Search code examples
phpapache2htdocs

How to run a PHP file on my computer that is outside the htdocs directory?


I just installed Apache and PHP on my computer to be able to run PHP files locally.

I can run a PHP file if it is located in Apache2.2\htdocs directory.

Is that possible to run PHP files outside this directory ?

I'm looking to a simple solution, because all I need is to write a small PHP code and try it locally.

I would like to be able to run the PHP file by right clicking it -> Open with Firefox


Solution

  • There is some ways to do it, but the simplest way is using 'include' or 'required' php command:

    <?
    include ('/somewhere/outside/of/your/htdocs/file.php');
    ?>
    

    Please note you may need to turn off 'open_basedir' php directive.