views:

138

answers:

7

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

+2  A: 

You can run a PHP script from anywhere using the command line:

php yourscript.php
thetaiko
I would like to be able to run the PHP file by right clicking it -> Open with Firefox. Is that possible ?
Misha Moroshko
@Misha - That probably won't work, even if the PHP is in the htdocs directory. The file must be run and served by the webserver, not interpreted by the browser.
thetaiko
A: 

Newer versions of php come with php-cli: a command line interface. So to run php code, you just need to type:

 php some_code.php
Satanicpuppy
A: 

Yes. You don't say if you want to run it from the web server, or from the command line, but you can use include past the web root.

chris12892
A: 

Or you can change paths in apache config to another dir

GOsha
A: 

You can either run it from the command line,

or you can create a "wrapper" script within your htdocs that "includes" the file from outside of the htdocs directory

Mark Baker
+1  A: 

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.

Ehsan
+1  A: 

you cannot open it with firefox.
Because firefox has nothing to do win PHP.
So, you need to request this URL from a web-server

Create a windows shortcut with http://127.0.0.1/file.php

or whatever way you prefer to click web links

Col. Shrapnel
@Misha Moroshko: Go to the web page in Firefox and then drag the "fav icon" (the icon to the left of the url) to your desktop. Now, when you double-click it, it will open the url in your browser. This will require you to have your web server running, of course.
webbiedave