gpg 加密失败:文件打开错误
我已经为此发疯了..
我在 CentOS 服务器上安装了 gnupg,并尝试加密上传的文件(通过 PHP 页面上传)。在服务器上通过命令行,它运行得很好。但是通过 php 脚本,它会失败并出现以下错误:
gpg: /path-to-my-file/my-file: encryption failed: file open error
用户 apache (我认为用于运行 exec 命令)在文件的目录中具有读/写权限。
文件上传正常(当我从代码中删除未加密文件的删除后我可以看到它)并且可以通过 php 站点正确删除。
我运行的命令如下 知道
/path-to-gpg/gpg --homedir=/path-to-my-home-gnupg/.gnupg -e -r therecipient@email the-unencrypted-file
如何解决这个问题吗? 谢谢
I have been going nuts with this..
I have gnupg installed on my CentOS server and I try to encrypt uploaded files (uploaded via a PHP page). On the server via the command line, it works perfectly. But via the php script, it fails with this error:
gpg: /path-to-my-file/my-file: encryption failed: file open error
The user apache (which I think is used to run the exec command) has read/write in the directory of the file.
The file is uploaded fine (I can see it afterward as I removed the deletion of the unencrypted file from my code) and can be deleted correctly via the php site.
the command I run is the following
/path-to-gpg/gpg --homedir=/path-to-my-home-gnupg/.gnupg -e -r therecipient@email the-unencrypted-file
Any idea how I could tackle this?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几件事需要检查:
system("ls " .escapeshellarg($file))
并检查结果 - 是否找不到文件?没有权限?这将帮助您调试。system("whoami")
以确保 PHP 按照您认为的方式运行。" 然后复制+粘贴命令并从 shell 运行它,以确保文件的路径是您期望的路径。
另外,我相信 CentOS 默认运行 SELinux…如果您安装了它,请检查日志(在
/var/log/
中)以查看 SELinux 是否阻止 Apache 执行 GPG。A few things to check:
system("ls " . escapeshellarg($file))
and check the result — is it file not found? Permission denied? That will help you debug.system("whoami")
to make sure PHP is running as who you think it is.echo "<pre>ls " . escapeshellarg($file) . "</pre>"
then copy+paste the command and run it from the shell to make sure that the path to the file is what you expected it to be.Also, I believe CentOS runs SELinux by default… If you've got it installed, check the logs (in
/var/log/
) to see if SELinux is preventing Apache from executing GPG.尝试在详细模式下使用实际的 apache 用户权限运行命令:
Try running the command with actual apache user privileges in verbose mode: