I know there exists some libraries, openPgp or gnupg, to encrypt and decrypt files in PHP, but it is a requirement of the company that the script works with bash script and runs from PHP like shell_exec("./myscriptencrypt")
#The example script:
#!/bin/bash
echo "$USER"
sudo gpg --output /Applications/MAMP/htdocs/outfiles/file.xls.gpg --encrypt --recipient myemail@myemail.com.mx /Applications/MAMP/htdocs/uploads/file_to_process.xls
When I run from terminal, this work very good, but when I run from PHP command gpg do not work and it doesn't create a file in folders, the folder have permissions: all users can RWX ->
chmod -R 777 /Applications/MAMP/htdocs/outfiles/
chmod -R 777 /Applications/MAMP/htdocs/uploads/
echo "$USER"
print -> my current user name: usuario
Extra: I run on MacOS in local environment, but it will live in Ubuntu server.