Failed user login on production server using Symfo

2019-02-16 15:22发布

I'am using Symfony for a project and I have been trying to get the login to work on production server with no success for the past 2 days. I keep getting the error

Authentication request could not be processed due to a system problem.

I have followed the guide here (http://symfony.com/doc/current/cookbook/security/entity_provider.html) to setup loading users from database.

My security.yml file:

security:
encoders:
    Symfony\Component\Security\Core\User\User: plaintext
    Acceptme\UserBundle\Entity\User: plaintext
role_hierarchy:
    ROLE_SUPER_ADMIN:   [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

providers:
    in_memory:
        memory:
            users:
                patricia:
                    password: patricia
                    roles: 'ROLE_ADMIN'
    users:
        name: user_provider
        entity: { class: AcceptmeUserBundle:User, property: username }

firewalls:
    user_area:
        pattern: ^/
        anonymous: ~
        provider: user_provider
        form_login:
            login_path: login_route
            check_path: _login_check
            default_target_path: homepage
    dev:
        pattern: ^/(_(profiler|wdt|error)|css|images|js)/
        security: false

    default:
                anonymous: ~
                http_basic: ~

access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }

My SecurityController.php:

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Security\Core\SecurityContext;

class SecurityController extends Controller
{
/**
 * @Route("/login", name="login_route")
 * @Template("security/login.html.twig")
 */
public function loginAction(Request $request)
{
    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
    } else {
        $error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
    }

    return array(
        'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
        'error'         => $error,
    );
}

/**
 * @Route("/login_check", name="_login_check")
 */
public function securityCheckAction()
{
    // this controller will not be executed,
    // as the route is handled by the Security system
}
}

I have tried uploading the project on 2 different web hosts (FatCow & GoDaddy) and the problem remains. Locally i am using PHP 5.4.19 (FatCow uses 5.3.2 and GoDaddy uses 5.4.37). Keep in mind that when working on localhost with XAMPP everything works fine!

I've confirmed that PDO is enabled in both cases. I've confirmed that the database username, password and host are correct in the parameters.yml file. Error logs on both local and remote servers show nothing.

I have followed all directions from this previous post Deploying Symfony2 app getting fosuserbundle errors and still no success.

I appreciate all the help in advance.

8条回答
Animai°情兽
2楼-- · 2019-02-16 15:52

UPDATE: Issue solved. The issue was that a table in the entity php file was named with upper case letters while the database table was named with lower case. +1 to ClémentBERTILLON for pointing in the right direction, namely prod.log

查看更多
闹够了就滚
3楼-- · 2019-02-16 15:56

It looks like that the error:

Authentication request could not be processed due to a system problem.

is too generic and does not tell anything about where the problem is (there is an issue opened about this matter here).

I solved my issue by checking the logs and see what happened (in var/logs/dev.log), hoping this helps someone.

In my specific case, there was a wrong parameter in parameters.yml about database connection. But, again, the error is too generic and does not necessarily imply that the problem is related with database connection.

查看更多
放我归山
4楼-- · 2019-02-16 15:59

Currently there is a bug in Symfony and on production IF during authentication system error occurs (missing table, missing column or any other exception) - it's logged as INFO instead of ERROR and with default error logging options it's not logged at all.

https://github.com/symfony/symfony/pull/28462

I think there are two options right now - temporary log everything (including INFO) on production until you find the real error.

Second option: use this patch or debug directly on production.

查看更多
Viruses.
5楼-- · 2019-02-16 15:59

In my case the issue was fixed by correcting a typo in connection details in the .env file.

查看更多
We Are One
6楼-- · 2019-02-16 16:04

Another possible cause could be MySQL Server. In my case I forgot to start MAMP / MySQL Server and Symfony resulted with this message.

查看更多
对你真心纯属浪费
7楼-- · 2019-02-16 16:12

This solution is correct for me: https://stackoverflow.com/a/39782535/2400373

But If you do not have access to the terminal, you can enter the server and delete the folders that are inside var/cache.

Another solution if you have access to the console is to type

#rm -rf var/cache/*

or

$sudo rm -rf var/cache/*

this solution works on symfony 3

查看更多
登录 后发表回答