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。
2、利用visudo给了apache和root一样的权限,并把Defaults requiretty注释了。
3、将/var/test文件夹的权限给足,用户和用户组设为apache
4、test.txt的权限和用户、用户组也设置了
访问192.168.1.xxx/test.php还是不能删掉,还是提示这个:
回复内容:
我在用浏览器访问服务器上的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。
2、利用visudo给了apache和root一样的权限,并把Defaults requiretty注释了。
3、将/var/test文件夹的权限给足,用户和用户组设为apache
4、test.txt的权限和用户、用户组也设置了
访问192.168.1.xxx/test.php还是不能删掉,还是提示这个:
通过
<code><?php echo shell_exec('whoami'); </code></code>
你就可以知道为何你没有权限删除了啊
另外, 在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>
Linux上目录用冒号(:)分隔,Windows上用分号(;)分隔.
很奇怪,你把apache加入了visudo里,为什么sudo -u apache 还是不能删除文件?也就是说sudo并没有成功赋给apache这个用户了

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

AI Hentai Generator
Generate AI Hentai for free.

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



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 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 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.

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)

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.

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.

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.

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).
