简体   繁体   English

SQLSTATE[HY000] [2002] 权限被拒绝

[英]SQLSTATE[HY000] [2002] Permission denied

我收到此错误不知道原因SQLSTATE[HY000] [2002] Permission denied ,这里是我尝试上传我的文件example.com

This happens because selinux avoids db connections from the httpd server to the remote db server.发生这种情况是因为 selinux 避免了从 httpd 服务器到远程数据库服务器的数据库连接。 To solve it you need to access your server through ssh or just open a console if you have pretencial access and do the following:要解决此问题,您需要通过 ssh 访问您的服务器,或者如果您具有假冒访问权限,则只需打开一个控制台并执行以下操作:

You must check in the SELinux if port 80 is managed in. You can check it by typing # semanage port -l | grep http_port_t如果端口 80 被管理,则必须在 SELinux 中检查。您可以通过键入# semanage port -l | grep http_port_t来检查它# semanage port -l | grep http_port_t # semanage port -l | grep http_port_t for a list and check: # semanage port -l | grep http_port_t获取列表并检查:

http_port_t tcp 443, 488, 8008, 8009, 8443, 9000

If you need to add the required port, just type:如果您需要添加所需的端口,只需键入:

# semanage port -a -t http_port_t -p tcp 80

Type the command to ckeck once again:再次输入命令来检查:

# semanage port -l | grep http_port_t

. .

http_port_t tcp 80, 443, 488, 8008, 8009, 8443, 9000

Then you should notify SELinux you want to allow network connections from the httpd server to the db remote server, setting the boolean variables that set it:然后你应该通知 SELinux 你想要允许从 httpd 服务器到 db 远程服务器的网络连接,设置设置它的布尔变量:

  1. Down the httpd service # service httpd stop关闭httpd # service httpd stop
  2. # setsebool httpd_can_network_connect 1
  3. # setsebool httpd_can_network_connect_db 1
  4. Up the httpd service # service httpd start up httpd service # service httpd start

Now your httpd service should be capable to get data from the db server.现在您的 httpd 服务应该能够从数据库服务器获取数据。

I hope that can be useful for the gang that searches solve errors like this.我希望这对搜索解决此类错误的团伙有用。

进入 .env 文件并将 DB_HOST=127.0.0.1 更改为 DB_HOST=localhost

May I am late to answer this question but what worked for me are the commands.我可能会迟到回答这个问题,但对我有用的是命令。 I ran into same issue and then I ran the following commands.我遇到了同样的问题,然后我运行了以下命令。

Provide permissions:提供权限:

chmod -R 777 . (though not recommended) (虽然不推荐)

Run setup upgrade command运行安装升级命令

php bin/magento setup:ugrade

and finally compile command最后编译命令

php bin magento setup:di:compile

也许你需要像这样关闭你的selinux

setenforce 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM