6

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() ..?

Mob
  • 10,958
  • 6
  • 41
  • 58
Selva
  • 87
  • 1
  • 1
  • 5
  • is safe mode enabled? `shell_exec` is disabled in safe mode – Juan Oct 28 '12 at 19:10
  • Even if you manage to get it working on your WAMP server, how are you going to move it to your live server afterwards? How do you figure the function is disabled on your WAMP server? What did you try? What happened when you tried it? – lanzz Oct 28 '12 at 21:17
  • @Mob I've just noticed now that you're actually hijacking someone else's question, so my question regarding the live server is probably not relevant. – lanzz Oct 28 '12 at 21:32
  • Actually, for me there's no moving to any live server. I just want it running on my windows box. – Mob Oct 29 '12 at 06:15
  • Is `shell_exec` even available on Windows? – Cobra_Fast Nov 02 '12 at 11:36
  • Are you asking us to hack that server for you? Because going against server policy's is generally not a good idea. Though, if properly configured, this shouldn't be an issue. – Ariaan Nov 02 '12 at 23:32

10 Answers10

8

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:

  1. stop all services from Wamp-Server and close the programm

  2. Open .../wamp/bin/apache/Apache2../bin/php.ini

  3. copy php.ini to desktop and open it

  4. set safe_mode_exec_dir (line after = is empty, so IT IS ON!!!) set it off!

  5. save

  6. copy back to dir (maybe you need admin rights)

  7. start wamp-server

  8. enjoy exec() and co.

Sturmi
  • 101
  • 2
  • 8
  • `set safe_mode_exec_dir (line after = is empty, so IT IS ON!!!) set it off!` ... i did not understand this ....my php.ini has `safe_mode_exec_dir = ` it is empty , do I need to type ON there? – Hitesh Dec 04 '14 at 12:38
  • how can i turn it off? – masoud vali Mar 03 '16 at 05:09
  • 1
    `safe_mode_exec_dir = off` is the answer, if it is not available in the php.ini just add a line, it works!!!! – Bira Mar 12 '16 at 02:55
3

I was having the same problem and tried a lot of solutions out there. What worked out for me was running XAMPP as Admin.

leplandelaville
  • 186
  • 1
  • 9
1

Open your php.ini file used by wamp, find the disable_functions part, change it and restart the server.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
xdazz
  • 158,678
  • 38
  • 247
  • 274
  • 1
    Thanks for your replay..I already checked in php.ini file. the disable-functions is empty. No functions are disabled.. – Selva Oct 06 '12 at 08:59
  • Sorry guys..Its all my problem..I was tried shell_exec() function 'ls -hal'. But its not working. Recently I just tried some other basic commands like 'cal' , 'date' ..Its working..Then I realized wamp is just giving us linux environment only. So we cant expect full linux command utilization. Actually I tried execute one 'c' file. Finally I found solution. First we need to compile that 'c' file then only we can execute...This what I used.. Thanks for all..!! – Selva Nov 09 '12 at 09:59
0

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.

oxygen
  • 5,891
  • 6
  • 37
  • 69
0

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()

Community
  • 1
  • 1
Estefano Salazar
  • 419
  • 4
  • 15
0

have you tried backticks? (in case safemode is OFF)

`ls -hal`

Windows equivalent would be

`dir \AH`
Ariaan
  • 1,105
  • 1
  • 9
  • 13
  • @WebnetMobile.com Well, that's uncalled for. I did mention it. So RTFA to you, and the other comments on the question. On that note Mob did mention safemode is **OFF** – Ariaan Nov 02 '12 at 23:24
0

Try using a WAMP server stack, which is clearly for development, like WPN-XM or XAMPP. Without any security limitations for the developer. So you won't run into trouble, when executing system(), shell_exec(), passthrough().

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
0

I think we can use these steps

  1. Open wamp\bin\apache\apache2.4.9\bin(doesn't matter apache version)
  2. Open php.ini file in editor
  3. Search for "disable_functions".
  4. Remove exec and shell_exec from disable function
  5. Restart all services.

Enjoy!!!

0
<?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.

-2

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

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Jimmy M
  • 1,627
  • 3
  • 14
  • 18
  • I don't think he has access to those configurations, else he would be able to enable it himself anyway. – Ariaan Nov 02 '12 at 23:40