apache 限制某些目录不能用php有很多中方法,可以设置php.ini和apache的配置信息都可以,下面简单介绍如下: 

php.ini中如下代码段 

引用文字:
——————————————————————————–
 
safe_mode = On 
; By default, Safe Mode does a UID compare check when  
; opening files. If you want to relax this to a GID compare,  
; then turn on safe_mode_gid.  
safe_mode_gid = Off  

; When safe_mode is on, UID/GID checks are bypassed when  
; including files from this directory and its subdirectories.  
; (directory must also be in include_path or full path must  
; be used when including)  
safe_mode_include_dir =  

; When safe_mode is on, only executables located in the safe_mode_exec_dir  
; will be allowed to be executed via the exec family of functions.  
safe_mode_exec_dir =  

; open_basedir, if set, limits all file operations to the defined directory  
; and below. This directive makes most sense if used in a per-directory  
; or per-virtualhost web server configuration file.  
;  
open_basedir =
——————————————————————————–

open_basedir 用来指定只在某一个目录中执行PHP 

如果不需要开放PHP权限的目录,在PHP的 Apache-specific Functions 章节中有如下介绍: 

 The behaviour of the Apache PHP module is affected by settings in php.ini. Configuration settings from php.ini may be overridden by php_flag settings in the server configuration file or local .htaccess files. 

示例为: 
php_flag engine off 

engine boolean 

    This directive is really only useful in the Apache module version of PHP. It is used by sites that would like to turn PHP parsing on and off on a per -directory or per-virtual server basis. By putting engine off in the appropriate places in the httpd.conf file,  PHP can be enabled or disabled.  

因此,只需在不需要PHP权限的目录或者虚拟主机设置段(目录为<Directory>,虚拟主机为<VirualHost>中加上 
php_flag engine off即可。 
即修改http.conf中的虚拟主机配置段,在特定目录<Directory>,或者说整个主机<VirualHost>段中加上php_flag engine off即可。 

以上方法,第二种比较简单。