I am attempting to perform the following actions on a file located on a CentOS server via PHP:
- Copy the file from its original location to a working directory
- Encrypt the file within that directory
- Move the file from the working directory to its final destination on the same server
The encryption step is where I am having difficulty. I can log the command string, copy it, and use it in the CentOS CLI and the file is encrypted no problem. But using the same command string through PHP has not produced working results.
Example command strings are:
"gpg --encrypt --default-recipient bob filename.txt"
"/usr/bin/gpg --encrypt --default-recipient bob filename.txt"
I have tried both shell_exec($command) and exec($command, $output_array, $return_code) to execute the command string.
exec( ) seems to work at first glance. Logs show the $return_code is zero (0) and the length of the $output_array is also zero. However the file is not encrypted.
The following steps have been taken in an effort to resolve any permissions issue: 1. The owner and group of the "/home/apache" directory is set to "apache" 2. The owner and group of the "/home/apache/.gnupg" file is also set to "apache" 3. The permissions of the directory and file listed above are also set to 777 4. The permissions of the file that is to be encrypted are set to 777 before the encryption step
I am at my wit's end for resolving this issue. Does anybody have any input? Thanks in advance.