PHP 配置open_basedir 让各虚拟站点独立运行
当时觉得这跟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安全配置的经验,欢迎分享交流。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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,

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

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.

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.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.
