Home  >  Article  >  Backend Development  >  php exec cannot be executed

php exec cannot be executed

王林
王林Original
2019-10-19 15:36:527683browse
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!

Statement:
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