简体   繁体   中英

PHP shell_exec with parameters is not working

I have a problem with the shell_exec option in my server. I am running CentOS 5.7 with CPanel and PHP installed on it.

In our coding we are passing parameters to a php file using shell_exec. Our sample code is like below. We are calling this from a phpfile (background process)

vi test.php

<?php
shell_exec("php -f /home/nikesh/public_html/createtestfile.php 666 >/dev/null &");
?>

where 666 is the parameter which is passing to the php file..

This is working fine in our test server and in live server its not working.

Also when I am executing this using linux terminal it working fine and output is generating.

ie : php -f test.php - is working fine.

But while I try to run this same file throught the browser its not working..

http://example.com/test.php

There is no error messges in my log files and the permission which i set is correct.

Please let me know If anybody faced the same problem before. please help me to fix this issue.

Thanks,

Nikesh


I have given the full permission for the folder and its not working. Safe mode is disabled in our server.

The basic Shell_exec functions are working in my server. But when we are giving parameters to the the php file its not working through the browser. But from the Linux terminal its working and generating the output.

Its not related to the folder permissions, the folder is having the write permission. But some how its not working through the browser. Please let me know if anything need to enable for this..? or need to change any server/php settings ?

Your webserver's php.ini likely has safe mode enabled or this function in the disabled_functions ini setting.

run

<?php
phpinfo();
?>

From a page through your webserver to inspect these variables (assuming that's not disabled)

give 777 permission to your public_html folder with chmod -R 777

try like that

<?php
shell_exec("php -f /home/nikesh/public_html/createtestfile.php 666 >/dev/null 2>&1");
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM