0

我遇到了 symfony2 的问题,我不太确定是什么导致了这个问题,我正在使用 FOSUserBundle 来处理登录和注册。我将我的代码移到了新服务器上,除了登录页面之外一切正常。我在登录页面上遇到了错误。

SQLSTATE[08006] [7] 无法连接到服务器:权限被拒绝服务器是否在主机“”上运行并接受端口 5432 上的 TCP/IP 连接?

我正在使用 postgres,我可以 PSQL 到服务器,所以我知道这不是权限问题。此外,由于它是一个新服务器,我用一个测试文件测试了我的 PDO 连接并且它工作正常。

关于问题可能是什么的任何想法?

测试文件。

<?php
    try {
    $dbh = new PDO('pgsql:host=host;dbname=dbname', 'user', 'password');
    echo 'Connected to database';
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

有人对这个问题有什么想法吗?

堆栈跟踪

Stack Trace

    in /var/www/html/portal/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php at line 36  -
        {
            public function __construct($dsn, $user = null, $password = null, array $options = null)
            {
                parent::__construct($dsn, $user, $password, $options);
                $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine\DBAL\Driver\PDOStatement', array()));
                $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            }
    at PDO ->__construct ('pgsql:host=testdb04.cctus.com port=5432 dbname=contourportal ', 'contour_owner', 'owner', array())
    in /var/www/html/portal/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php at line 36  +
    at PDOConnection ->__construct ('pgsql:host=value port=5432 dbname=value ', value', '', array())
    in /var/www/html/portal/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php at line 26  +
    at Driver ->connect (array('dbname' => 'value', 'host' => 'value', 'port' => '5432', 'user' => 'contour_owner', 'password' => 'valuer', 'charset' => 'UTF8', 'driver' => 'pdo_pgsql', 'driverOptions' => array()), 'contour_owner', 'owner', array())
    in /var/www/html/portal/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php at line 350  +
    at Connection ->connect ()
    in /var/www/html/portal/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php at line 627  +
    at Connection ->executeQuery ('SELECT t0.username AS username1, t0.username_canonical AS username_canonical2, t0.email AS email3, t0.email_canonical AS email_canonical4, t0.enabled AS enabled5, t0.salt AS salt6, t0.password AS password7, t0.last_login AS last_login8, t0.locked AS locked9, t0.expired AS expired10, t0.expires_at AS expires_at11, t0.confirmation_token AS confirmation_token12, t0.password_requested_at AS password_requested_at13, t0.roles AS roles14, t0.credentials_expired AS credentials_expired15, t0.credentials_expire_at AS credentials_expire_at16, t0.id AS id17, t0.billing_entity_id AS billing_entity_id18 FROM contour_portal_users t0 WHERE t0.username_canonical = ?', array('admin'), array('string'))
    in /var/www/html/portal/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 844  +
    at BasicEntityPersister ->loadAll (array('usernameCanonical' => 'admin'), null, null, null)
    in /var/www/html/portal/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php at line 157  +
    at EntityRepository ->findBy (array('usernameCanonical' => 'admin'))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php at line 106  +
    at UniqueEntityValidator ->validate (object(User), object(UniqueEntity))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 276  +
    at ExecutionContext ->executeConstraintValidators (object(User), array(object(UniqueEntity), object(UniqueEntity)))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 241  +
    at ExecutionContext ->validateValue (object(User), array(object(UniqueEntity), object(UniqueEntity)))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 110  +
    at ValidationVisitor ->visit (object(ClassMetadata), object(User), 'Registration', 'data')
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 107  +
    at ClassMetadata ->accept (object(ValidationVisitor), object(User), 'Registration', 'data')
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162  +
    at ValidationVisitor ->validate (object(User), 'Registration', 'data', true, false)
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 227  +
    at ExecutionContext ->validate (object(User), 'data', 'Registration', true)
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php at line 60  +
    at FormValidator ->validate (object(Form), object(Form))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 276  +
    at ExecutionContext ->executeConstraintValidators (object(Form), array(object(Form)))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 241  +
    at ExecutionContext ->validateValue (object(Form), array(object(Form)))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 110  +
    at ValidationVisitor ->visit (object(ClassMetadata), object(Form), 'Default', '')
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 107  +
    at ClassMetadata ->accept (object(ValidationVisitor), object(Form), 'Default', '')
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162  +
    at ValidationVisitor ->validate (object(Form), 'Default', '', false, false)
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator.php at line 90  +
    at Validator ->validate (object(Form))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php at line 55  +
    at ValidationListener ->validateForm (object(FormEvent))
    at call_user_func (array(object(ValidationListener), 'validateForm'), object(FormEvent))
    in kernel.root_dir/cache/dev/classes.php at line 1664  +
    at EventDispatcher ->doDispatch (array(array(object(ValidationListener), 'validateForm')), 'form.post_bind', object(FormEvent))
    in kernel.root_dir/cache/dev/classes.php at line 1597  +
    at EventDispatcher ->dispatch ('form.post_bind', object(FormEvent))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php at line 42  +
    at ImmutableEventDispatcher ->dispatch ('form.post_bind', object(FormEvent))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 624  +
    at Form ->submit (object(Request))
    in /var/www/html/portal/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 638  +
    at Form ->bind (object(Request))
    in /var/www/html/portal/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Controller/RegistrationController.php at line 52  +
    at RegistrationController ->registerAction (object(Request))
    at call_user_func_array (array(object(RegistrationController), 'registerAction'), array(object(Request)))
    in kernel.root_dir/bootstrap.php.cache at line 2774  +
    at HttpKernel ->handleRaw (object(Request), '1')
    in kernel.root_dir/bootstrap.php.cache at line 2748  +
    at HttpKernel ->handle (object(Request), '1', true)
    in kernel.root_dir/bootstrap.php.cache at line 2878  +
    at ContainerAwareHttpKernel ->handle (object(Request), '1', true)
    in kernel.root_dir/bootstrap.php.cache at line 2179  +
    at Kernel ->handle (object(Request))
    in /var/www/html/portal/web/app_dev.php at line 29  +
4

2 回答 2

1

出于某种原因,我的问题是一个 centos 问题,SELinux 阻止了我的请求。当我禁用它时,它开始工作。

于 2013-08-01T14:58:37.877 回答
0

您可以通过以下方式取消阻止与数据库的连接:

setsebool -P httpd_can_network_connect 1

禁用 SELinux 不是一个好主意。

于 2014-05-03T12:39:44.147 回答