php exec cannot be executed

王林
Release: 2023-02-27 13:14:01
Original
7684 people have browsed it
Recommended manual:php complete self-study manual

php exec cannot be executed

##Permission problem:

When we execute Linux system commands directly on the server (taking ping as an example here), the execution permissions depend on the permissions of our logged-in user. If our logged-in user is root, when executing ping Use root to execute. But when we access the website, our user at this time is www. If we do not modify the execution permission of ping, it will not be executed successfully.

Recommended tutorial:

PHP video tutorial

Solution:

Modify the execution permissions of ping or corresponding commands.

Command path problem:

When we use exec to execute a command, no error is reported and no result is returned. The reason is that this command It is not in the directory where the environment variable is configured, that is, in the /etc/profile file. Taking ifconfig as an example, we can use whereis ifconfig to find out the specific path of this command.

Solution:

1. Copy the command to /usr/bin, which is the directory under the environment variable

2. Directly enter the command Full path completion exec('/usr/sbin',$output)

3. Add the target directory to the environment variable, for example, add /usr/sbin to the directory

Related articles Recommendation: 1.
Use exec to call system commands in PHP 2.
The difference between shell_exec() and exec() functions in PHP3 .
Solution to the problem that the exec() function in php fails to execute system commands
Related video recommendations:1.
Dugu Jiujian (4)_PHP video tutorial

The above is the detailed content of php exec cannot be executed. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template