How do I change the shell for php's exec()

后端 未结 4 1714
名媛妹妹
名媛妹妹 2021-01-11 15:20

I want to use php\'s exec() function on an ubuntu server. The problem is, I alway get an error, that the command is not found. For example using

exec(\"echo         


        
4条回答
  •  误落风尘
    2021-01-11 15:34

    I think PHP calls /bin/sh internally (or cmd.exe on Windows) regardless of which function you use.

    Running ls -l /proc/$$/exe | sed 's%.*/%%' in your terminal in a Linux system should tell you what shell you're using, which is bash in my Ubuntu terminal by default. If you run the following in Ubuntu:

    you will get ["dash"] as the result, regardless of which function you use. If you change /bin/sh to point to bash rather than dash, the result from PHP changes to bash, but I don't recommend doing that obviously.

    So long story short it's probably not possible to change this without modifying your entire server's default shell or compiling PHP from source.

    If you want to solve the mystery further, it's probably related to ext/standard/proc_open.c and ext/standard/exec.c (all these functions are in there, system, passthru, etc.) in the PHP source, but to be honest it beats me.

提交回复
热议问题