Table of Contents
回复内容:
Home Backend Development PHP Tutorial linux - 用php的exec()删除目录文件提示权限不够

linux - 用php的exec()删除目录文件提示权限不够

Jun 06, 2016 pm 08:29 PM
exec linux php Permissions

我在用浏览器访问服务器上的php文件,然后用exec()删除某目录文件,提示权限不够,经过一顿搜索之后,我已根据很多文章的描述进行下面的权限设置,请问还有什么漏了设置的地方导致权限还是不够?

代码test.php:
$a = exec("rm /var/test/test.txt 2>&1",$result,$status);
print_r($result);
关于权限的服务器设置:
1、apache的httpd.conf中的user和group现在是apache。

linux - 用php的exec()删除目录文件提示权限不够

2、利用visudo给了apache和root一样的权限,并把Defaults requiretty注释了。

linux - 用php的exec()删除目录文件提示权限不够

linux - 用php的exec()删除目录文件提示权限不够

3、将/var/test文件夹的权限给足,用户和用户组设为apache

linux - 用php的exec()删除目录文件提示权限不够

4、test.txt的权限和用户、用户组也设置了

linux - 用php的exec()删除目录文件提示权限不够

访问192.168.1.xxx/test.php还是不能删掉,还是提示这个:

linux - 用php的exec()删除目录文件提示权限不够

回复内容:

我在用浏览器访问服务器上的php文件,然后用exec()删除某目录文件,提示权限不够,经过一顿搜索之后,我已根据很多文章的描述进行下面的权限设置,请问还有什么漏了设置的地方导致权限还是不够?

代码test.php:
$a = exec("rm /var/test/test.txt 2>&1",$result,$status);
print_r($result);
关于权限的服务器设置:
1、apache的httpd.conf中的user和group现在是apache。

linux - 用php的exec()删除目录文件提示权限不够

2、利用visudo给了apache和root一样的权限,并把Defaults requiretty注释了。

linux - 用php的exec()删除目录文件提示权限不够

linux - 用php的exec()删除目录文件提示权限不够

3、将/var/test文件夹的权限给足,用户和用户组设为apache

linux - 用php的exec()删除目录文件提示权限不够

4、test.txt的权限和用户、用户组也设置了

linux - 用php的exec()删除目录文件提示权限不够

访问192.168.1.xxx/test.php还是不能删掉,还是提示这个:

linux - 用php的exec()删除目录文件提示权限不够

通过

<code><?php echo shell_exec('whoami');
</code></code>
Copy after login

你就可以知道为何你没有权限删除了啊
另外, 在PHP中直接创建一个文件, 看看他是什么权限,也能看到你的php的执行用户和用户组

根据上面的权限配置,应该是能删除的呀。
LZ要不试试重启下apache服务器,然后再执行代码。

注意到php.ini里提供有一个open_basedir配置,也就是只有在open_basedir里的目录,PHP才能进行操作,所以如果你开启了open_basedir限制,那你就应该把/var/test这个目录加到open_basedir里,重启Apache:

<code>open_basedir="/tmp/:/var/www/html/:/var/test/"
</code>
Copy after login

Linux上目录用冒号(:)分隔,Windows上用分号(;)分隔.

很奇怪,你把apache加入了visudo里,为什么sudo -u apache 还是不能删除文件?也就是说sudo并没有成功赋给apache这个用户了

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

PHP and the Web: Exploring its Long-Term Impact PHP and the Web: Exploring its Long-Term Impact Apr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

See all articles