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

。_饼干妹妹 提交于 2019-12-10 15:19:40

问题


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


回答1:


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.




回答2:


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

php yourscript.php



回答3:


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



回答4:


Or you can change paths in apache config to another dir




回答5:


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




回答6:


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.




回答7:


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




回答8:


I had always wondered about it the same manner, say you have a folder in a drive either than the apache/htdocs folder in drive C, and you would like to develop directly in this folder. But think about it this way, would you put your folders else where and expect it to be running on the web? Now Way. Why would you do that?




回答9:


Goto conf folder and open httpd file change DocumentRoot "C:/your/path" and Directory "C:/your/path" This should work

if it says forbidden access go to this link

Error message "Forbidden You don't have permission to access / on this server"



来源:https://stackoverflow.com/questions/2975027/how-to-run-a-php-file-on-my-computer-that-is-outside-the-htdocs-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!