symfony 3.4“驱动程序中发生异常:SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo失败:名称或服务未知”

时间:2019-03-27 11:21:56

标签: php symfony amazon-ec2 amazon-rds

您好,我正在尝试在AWS EC2和RDS中部署我的项目。我们使用Symfony 3.4 Framework开发了应用程序,我在localhost中的代码运行正常,没有任何问题。

在AWS中托管后无法正常工作。显示此错误

 "message": "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known",

邮递员错误消息:

{
    "error": {
        "code": 500,
        "message": "Internal Server Error",
        "exception": [
            {
                "message": "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known",
                "class": "Doctrine\\DBAL\\Exception\\ConnectionException",
                "trace": [
                    {
                        "namespace": "",
                        "short_class": "",
                        "class": "",
                        "type": "",
                        "function": "",
                        "file": "/var/www/html/ApartmentManagementScms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php",
                        "line": 93,
                        "args": []
                    },

                ]
            },


        ]
    }
}

AWS中的Apache版本:

Server version: Apache/2.4.18 (Ubuntu)
Server built:   2018-06-07T19:43:03

操作系统版本:

    Distributor ID: Ubuntu
    Description:    Ubuntu 16.04.5 LTS
    Release:    16.04
    Codename:   xenial

2 个答案:

答案 0 :(得分:1)

仔细检查您在DSN中指定的主机地址。该错误仅表示无法解析您为mysql主机指定的名称。

答案 1 :(得分:0)

在.env文件中检查数据库配置

DATABASE_URL = mysql://您的数据库用户名:您的数据库密码@ 127.0.0.1:3306 /您的数据库名称