Reputation: 1
shell_exec is not running on linux terminal
try to run below commands
[root@localhost conf]# shell_exec
-bash: shell_exec: command not found
[root@localhost conf]# shell_exec("pwd")
-bash: syntax error near unexpected token `"pwd"'
[root@localhost conf]#
Upvotes: 0
Views: 115
Reputation: 81
You're trying to execute PHP directly on the command line without using the PHP packaging, so the bash shell is attempting to execute it and doesn't recognize the PHP function.
You need to run shell_exec()
in a PHP file or use the appropriate PHP CLI syntax. For example, you can pass -r
to the php
command, which allows you to run code.
myusername:~$ php -r 'echo shell_exec("pwd");'
/home/myusername
myusername:~$
Or you can use the built-in REPL.
myusername:~$ php -a
Interactive shell
php > echo shell_exec('pwd');
/home/myusername
php >
Also note the use of echo
here since the successful result will return a string that we want to see.
Upvotes: 1