Any idea why I can execute the command from the command line, but not from PHP exec ()

OK,

I did a few creative searches, and I kinda hit the road block.

I am trying to use the linux "sox" program. I am trying to call this from my PHP script. script DOES work if I use the command line. However, when I use PHP exec, it does not work.

Example:

sox file1.mp3 file2.mp3 tempfile.mp3 -V3 

("V3" indicates verbose output)

When executed on the command line as "User X" or as root, I can create a new file. However, when I execute a command like:

 <?php exec('sox file1.mp3 file2.mp3 tempfile.mp3 -V3', $output); foreach($output as $line){ print $line; } 

It does not generate a new file. In addition, the array that should return the results of the command is empty.

I made simple text with

 exec(ls,$output); 

and I get the contents of the root directory.

I used the PHP get_current_user() command, and it returned the owner of the directory, which is the root of the website.

However, when I use the linux whoami , I find that it is viewing the current user as "apache". Should I grant apache permissions to use the program?

I will continue to search the Internet and conduct trial and error to find out what I am doing wrong. Any help is appreciated.

Explanation

  • I'm not in safe mode (I checked phpinfo () page ")
+4
source share
3 answers

This is usually a path issue. The application you are trying to call is probably not in the search path for the web server user account. I only call applications from PHP using the full path. I store this path in the configuration files, so it works on any system in which it is used.

+3
source

I am sure that php works as the user launching your apache, and this is most often nobody (a user without permissions to create directories). Try creating your exit somewhere where everyone is allowed to write and verify that the apache user is working under.

+2
source

Check if PHP is currently running in safe_mode

0
source

Source: https://habr.com/ru/post/1334839/


All Articles