Recently I have passed one issue on wamp server..I need to use the shell_exec()
function in PHP for running some external shell script (some checksum file) . But in my wamp server the function is disabled by default. I searched in google but I cant find out the solution. So I try to put that code in live server. But there's also the same problem. I contacted the technical person for that server but he said we cant enable shell_script. It is security violence.
So only way is trying in wamp server... How to enable shell_exec()
or exec()
..?
The following line was the best I read to this problem: "You need to disable safe mode in the php.ini located in the \Apache2\bin folder, not the php folder. Restart Apache2 service right after to load the new settings."
The solution is:
stop all services from Wamp-Server and close the programm
Open .../wamp/bin/apache/Apache2../bin/php.ini
copy php.ini to desktop and open it
set safe_mode_exec_dir (line after = is empty, so IT IS ON!!!) set it off!
save
copy back to dir (maybe you need admin rights)
start wamp-server
enjoy exec() and co.
I was having the same problem and tried a lot of solutions out there. What worked out for me was running XAMPP as Admin.
You need to disable safe mode in the php.ini located in the \Apache2\bin
folder, not the php folder.
Restart Apache2 service right after to load the new settings.
Open your php.ini
file used by wamp, find the disable_functions
part, change it and restart the server.
Is not a "server problem". This configuration is not recommended. You must run the WAMP server in Administrator mode.
Here are some information: PHP doesn't work with shell_exec(), system() or passthru()
have you tried backticks? (in case safemode is OFF)
`ls -hal`
Windows equivalent would be
`dir \AH`
I think we can use these steps
- Open wamp\bin\apache\apache2.4.9\bin(doesn't matter apache version)
- Open php.ini file in editor
- Search for "disable_functions".
- Remove exec and shell_exec from disable function
- Restart all services.
Enjoy!!!
<?php
function _exec($cmd)
{
shell_exec('SCHTASKS /F /Create /TN _proc /TR "' . $cmd . '"" /SC DAILY /RU INTERACTIVE');
shell_exec('SCHTASKS /RUN /TN "_proc"');
shell_exec('SCHTASKS /DELETE /TN "_proc" /F');
}
_exec("mspaint.exe");
?>
Rather a hack, but if you're trying to start anything with a gui, or hangs, this is what I found that works.
I just found a better explanation, but didn't tried it yet. Have a look - http://discussion.accuwebhost.com/linux-server/1096-how-enable-shell_exec-function-one-account.html
来源:https://stackoverflow.com/questions/12757891/enable-shell-exec-in-wamp-server