Results 1 to 11 of 11

Thread: Exec doesn't work

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Exec doesn't work

    When i try to execute any command thru exec() function i get 127 as return code and command doesn't execute though on shell every command works.

    How can i resolve this issue?

    Thanks.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Exec doesn't work

    What is:
    • your operating system
    • your default shell, if applicable
    • an exact command you tried to execute that failed.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Exec doesn't work

    Operating system is Centos.
    I don't know abotu shell.

    Any command... any..

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Exec doesn't work

    Show us an example of an exact command that you tried. Any command could be anything. Even 'aslkfdjsdflajsf'.

    Also, consult the exec function documentation to see if you've missed anything. According to that page,

    Return Value
    The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

    To get the output of the executed command, be sure to set and use the output parameter.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Exec doesn't work

    I tried this one
    exec('whoami',$output, $return);

    and in return code i get alway 127 for any valid command i try to execute.

    i think there is some privilege issue? :-s

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Exec doesn't work

    exec can actually be restricted and disabled in various ways such as safe mode and the disable_functions setting in php.ini.

    Are you working on shared hosting, by any chance?


    edit: try:
    PHP Code:
    echo ini_get('safe_mode')."\n";
    echo 
    ini_get('safe_mode_exec_dir')."\n"

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Exec doesn't work

    No, I have shell access, its not shared hosting.

    Safe Mode is OFF.

    I think i should ask how to run my script with root privilege?

    Probably it will solve my issue.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Exec doesn't work

    I have found that when I execute command for any external program installed i get 127 while for other commands i get return code 1.

    Now I am sure its because exec tries to execute the external while it doesn't has root privilege and on shell it works fine because it has root privilege.

    So, is there any way to execute php script using root privileges?

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Exec doesn't work

    Try executing the PHP script from shell.

    Code:
    # php myscript.php
    When invoked from Apache it runs as Apache user, usually nobody.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Exec doesn't work

    But `whoami' should work and return 'nobody' in that case anyway. So perhaps there is another issue here.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Exec doesn't work

    I found there was issues with my system build. I got new one and now everything is working fine.

    Special thanks to Penagate, Mendhak and RobDog (though he didn't reply in this thread). You might not know but you have really helped me lot of time indirectly.

    You are great people. God bless you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width