Executing php exec system shell_exec has no results? Done in one article!

藏色散人
Release: 2023-04-11 08:48:02
forward
7041 people have browsed it

This article will introduce to you the problem that php exec system shell_exec cannot be executed. The main content is to explain the method of executing php exec() system() shell_exec() without results and the result is NULLD. I hope it will be helpful to friends in need~

Executing php exec system shell_exec has no results? Done in one article!

php exec() system() shell_exec() cannot be executed, there is no result, the result is NULLD, solution

The code index.php on the server:

<?php    
$cmd = &#39;php -v&#39;;    
exec($cmd, $arr);    
echo &#39;<pre class="brush:php;toolbar:false">'    
var_dump($arr);
Copy after login

After the browser is accessed, the printed result is: NULL

It means that the server has not turned on PHP and used exec(); [Recommended learning: PHP video Tutorial

Solution:

1. Add a function to view the currently running user:

<?php    
var_dump(get_current_user());    
$cmd = &#39;php -v&#39;;    
exec($cmd, $arr);    
echo &#39;<pre class="brush:php;toolbar:false">'    
var_dump($arr);
Copy after login

Display: root

2. Go to the server to modify file permissions:

$ chmod 777 index.php
Copy after login

View the user and permissions of index.php:

$ ll
Copy after login

Result:

-rwxrwxrwx 1 root root    1595 Sep 20 10:18 index.php
Copy after login

3. Check php.ini to see if these functions are disabled:

$ cd /usr/local/php/etc
$ vim php.ini
Copy after login

##Find disable_functions =


Remove exec, system, and exec_shell and use whichever one you use;

4. Restart the php service. This step is very important:

$ /etc/init.d/php-fpm restart
Copy after login
Then test, the browser accesses the server and the result is:

Most of it is because php.ini disables the exec function and the execution permission of the file.

The above is the detailed content of Executing php exec system shell_exec has no results? Done in one article!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!