Home  >  Article  >  Backend Development  >  When executing PHP under Linux, the external shell script system returns 126

When executing PHP under Linux, the external shell script system returns 126

WBOY
WBOYOriginal
2016-12-01 00:56:422017browse

<code><?php
$command = '/var/www/html/fzip.out  /var/www/html/test  /var/www/html/test.fzip';
//$command = 'ls /var/www/html';
system($command,$return);
exec($command,$out);
//echo $command;
print_r($return);
echo '<br>=================<br>';
print_r($out);?></code>

The first $command is your own shell script, the purpose is to compress the folder of the second parameter to the path of the third file. Tell us about the current situation.
1 php.ini is not in safe mode, so you can call ls and other commands normally.
2 When the system executes this command, it returns 126, and the second parameter of exec is empty.
3 The html directory of the generated file has been given 777 permissions, and the compressed test directory also has 777 permissions
4 You can execute this command directly using the command line

What configuration is required to execute such a custom script? ?

Reply content:

<code><?php
$command = '/var/www/html/fzip.out  /var/www/html/test  /var/www/html/test.fzip';
//$command = 'ls /var/www/html';
system($command,$return);
exec($command,$out);
//echo $command;
print_r($return);
echo '<br>=================<br>';
print_r($out);?></code>

The first $command is your own shell script, the purpose is to compress the folder of the second parameter to the path of the third file. Tell us about the current situation.
1 php.ini is not in safe mode, so you can call ls and other commands normally.
2 When the system executes this command, it returns 126, and the second parameter of exec is empty.
3 The html directory of the generated file has been given 777 permissions, and the compressed test directory also has 777 permissions
4 You can execute this command directly using the command line

What configuration is required to execute such a custom script? ?

Finally, I found that execution was blocked by selinux. I will leave a result for your reference. The performance is that in php-cli mode, the script can be executed normally, and execution on the web page returns 126. Adding sudo returns 1

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