Answer the question
In order to leave comments, you need to log in
Why might the exec function not work?
I have a php script that should run an application, let's say java.class, the function in this case will look something like this exec("java -cp . java"), and that's how it works, only the problem is that it only works if if I run this script from the console, and when I run it as a page of the site in the browser, then the function does not work, what could be the problem?
In addition, I can say that when I run the script from the console, it runs as the system user and when it runs in the browser, the user is www-data.
Added safe_mode = Off safe_mode_exec_dir = "var/www/exec/" to php.ini file and removed this function from disable_functions.
Answer the question
In order to leave comments, you need to log in
try executing this command in the console as www-data
either you don't have enough rights, or there's a problem with the paths.
Because exec runs commands in the sh shell without exporting environment variables, including $PATH, that is, it simply does not know where the java binary is. Specify the full path to the binary in the command that you pass to exec(). For example, it will look like this for me:
$ which java
/usr/bin/java
exec("/usr/bin/java -cp .java")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question