Home php教程 php手册 PHP 配置open_basedir 让各虚拟站点独立运行

PHP 配置open_basedir 让各虚拟站点独立运行

Jun 13, 2016 pm 12:20 PM
iis open php independent site virtual run Configuration

当时觉得这跟IIS相比,实在太差了,因为在IIS里,可以在安全性里设置一个站点甚至一个目录访问时使用的匿名账号,只要各个站点使用的账号不一样,站点间的安全就不会互相影响。这几天才发现,原来当时的想法是错的,在Apache下,也可以配置PHP来实现各站点间的相互独立运行,虽然不能详细控制以某个用户运行某个站点,但至少不会再出现整个服务器被拿下的局面。

通过配置PHP的open_basedir即可以实现该控制,这个配置在IIS下也有用,但这里只讲Apache下的配置。

open_basedir可将用户访问文件的活动范围限制在指定的区域,通常是其家目录的路径,也
可用符号"."来代表当前目录。open_basedir也可以同时设置多个目录, 在Windows中用分号分隔目录,在任何其它系统中用
冒号分隔目录。当其作用于Apache模块时,父目录中的open_basedir路径自动被继承。以下以Linux系统下的配置为例

方法一:在php.ini里配置
open_basedir = .:/tmp/

方法二:在Apache配置的VirtualHost里设置
php_admin_value open_basedir .:/tmp/

方法三:在Apache配置的Direcotry里设置
php_admin_value open_basedir .:/tmp/

关于三个配置方法的解释:
a、方法二的优先级高于方法一,也就是说方法二会覆盖方法一;方法三的优先级高于方法二,也就是说方法三会覆盖方法二;
b、配置目录里加了“/tmp/”是因为php默认的临时文件(如上传的文件、session等)会放在该目录,所以一般需要添加该目录,否则部分功能将无法使用;
c、配置目录里加了“.”是指运行php文件的当前目录,这样做可以避免每个站点一个一个设置;
d、如果站点还使用了站点目录外的文件,需要单独在对应VirtualHost设置该目录;

设置完成后,记得找个PHP网马(如:phpspy)来玩一玩,测试一下有没有问题,不出意外,权限应该是控制得相当好的。
大家还有什么PHP安全配置的经验,欢迎分享交流。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Top 10 virtual currency trading platforms in the 2025 cryptocurrency circle Top 10 virtual currency trading platforms in the 2025 cryptocurrency circle Mar 12, 2025 pm 05:27 PM

Top 10 virtual currency trading platforms in the 2025 cryptocurrency circle: 1. OKX, known for its high liquidity, low fees and abundant products; 2. Binance, one of the world's largest exchanges, with a huge user base; 3. Gate.io, a veteran exchange, safe and stable; 4. Kraken, focusing on professional traders, safe and compliant; 5. Huobi Global, a world-renowned, strong technical strength; 6. Coinbase, a leading exchange in the United States, easy to use compliance; 7. KuCoin, rich trading pairs, low fees.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

How to open xml format How to open xml format Apr 02, 2025 pm 09:00 PM

Use most text editors to open XML files; if you need a more intuitive tree display, you can use an XML editor, such as Oxygen XML Editor or XMLSpy; if you process XML data in a program, you need to use a programming language (such as Python) and XML libraries (such as xml.etree.ElementTree) to parse.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

Explain strict types (declare(strict_types=1);) in PHP. Explain strict types (declare(strict_types=1);) in PHP. Apr 07, 2025 am 12:05 AM

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values ​​to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.

See all articles