LearningLocker / learninglocker

Learning Locker - The Open Source Learning Record Store. Started in 2014.
https://learningpool.com/solutions/learning-record-store-learning-locker/learning-locker-community-overview/
GNU General Public License v3.0
553 stars 274 forks source link

Migration causing 500 error #891

Closed lagost closed 7 years ago

lagost commented 7 years ago

PHP 5.6.22 Windows 2012 r2 mongodb version 3.2 mongophp extension version 1.5.4

When I perform: php artisan migrate, I receive 500 error: Failed to connect to : local host: 27017: Authentication failed ...with username...

After performing a few tests, I believe it has something to do with the password. If I exclude the password from the config/local/database file, I receive the registration page. However the migration step still shows 500 Errror: MongoDB::_construct(): invalid name.

I have been researching a way to fix this but am out of luck. All the options I found do not work. When I use a no password option to bypass the migration step, the registration page redirects me to a 404 error page. So I must be missing something.

Any help would be so graciously helpful and appreciated.

Thanks, Laura

ryasmi commented 7 years ago

Hi Laura, thanks for reporting your issue. Do you think you could provide some steps to reproduce the problem for a blank database and new installation of Learning Locker? If you can do that I can try to reproduce your problem and help resolve it.

ht2 commented 7 years ago

Just one thing I've noticed there, your PHP extension is an older version. I'd recommend upgrading to 1.6.* (I can't remember the most recent patch number).

-- James MullaneyTECHNICAL DIRECTOR

Office: +44 (0) 1865 873 862

Skype: james.ht2

Email: james@ht2labs.com https://ht2labs.com

The R&D Company For Learning and Performance

HT2 Limited | Company Reg No. 04052815 | Registered Office: Hillside, Albion Street, Chipping Norton, Oxfordshire OX7 5BH, UK.

lagost commented 7 years ago

Hi James,

I'll give that a shot and see if the updated extension makes a difference.

thanks, Laura

On Fri, Jan 20, 2017 at 4:53 PM James Mullaney notifications@github.com wrote:

Just one thing I've noticed there, your PHP extension is an older version.

I'd recommend upgrading to 1.6.* (I can't remember the most recent patch

number).

--

James MullaneyTECHNICAL DIRECTOR

Office: +44 (0) 1865 873 862

Skype: james.ht2

Email: james@ht2labs.com

https://ht2labs.com

The R&D Company For Learning and Performance

HT2 Limited | Company Reg No. 04052815 | Registered Office: Hillside,

Albion Street, Chipping Norton, Oxfordshire OX7 5BH, UK.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LearningLocker/learninglocker/issues/891#issuecomment-274189757, or mute the thread https://github.com/notifications/unsubscribe-auth/ANjD46MJrpD8Tybv9ERKFLxQkTRq0IA2ks5rUSzSgaJpZM4Lpw6v .

lagost commented 7 years ago

I have upgraded the mongodb extension to 1.6. I am still receiving a 500 error at migration step with a different message regarding SASL authentication failure. I am attaching my mongodb exention details and the error I am receiving.

To answer ryansmith94, I followed the steps as defined on the learning locker installation page.

  1. PHP 5.6 was already installed on the server .
  2. MongoDB was already installed on the server as we are using it for another program as well. All I did was create a new database called LRS.
  3. I installed the latest mongdb extension. 1.6
  4. I re-ran the install command lines: php -r "readfile('https://getcomposer.org/installer');" | php php composer.phar install --no-interaction --no-dev
  5. Created the config database file under local. (see config file below) My password has special characters, uppercase characters and numbers.
  6. Ran php artisan migrate. And this is where I get stuck.

Config file:

<?php

return [
  'fetch' => PDO::FETCH_CLASS,
  'default' => 'mongodb',
  'connections' => [
        'mongodb' => [
        'driver'   => 'mongodb',
        'host'     => 'localhost',
        'port'     => 27017,
        'username' => 'myusername',
        'password' => 'mypassword',
        'database' => 'LRS'
    ]
  ]
];

error mongodb

ht2 commented 7 years ago

OK, well good to know your extension is up to date now - that will certainly prevent any other issues moving forward.

Regarding your current issue, the error you posted points to an authentication problem: Failed to connect to : local host: 27017: Authentication failed

It would be useful to see the full stack trace of the error (feel free to paste it in from the logs) but if the driver is giving an authentication error then it is highly likely your Mongo user is not correctly configured to read/write to the database you have set in your config. You can read more about managing your users and their respective roles that allow them to access and amend the database via the Mongo documentation: https://docs.mongodb.com/v3.2/tutorial/manage-users-and-roles/

ht2 commented 7 years ago

To add to that, critically, you should ensure that the user you have created to access your database is set with at least the readWrite role - either at the database level or across the whole Mongo instance.

Assuming you have already created the user and given them a password, this could be achieved via:

use LRS
db.grantRolesToUser(
    "youruserhere",
    [
      { role: "readWrite", db: "LRS" }
    ]
)
lagost commented 7 years ago

I removed the user and re-added the user, just to ensure I did a readWrite. I use RoboMongo and am providing the screen shot of the user role info. I am still receiving the same error.

dbuserinfo

lagost commented 7 years ago

Strange, I just accessed my MongoDB via the shell and it seems that my user doesn't exist, even though Robomongo shows the user. I will recreate the user via the shell with readWrite access and see if that makes the difference. I will keep you posted.

lagost commented 7 years ago

I re-created the LRS, then added a user with read/write role. I must have missed a step somehow because it's now providing an error that the Collection cannot be empty.

So to recap what I need to do:

  1. Create the LRS DB
  2. Add a user to LRS.

What collection should I be creating?

ryasmi commented 7 years ago

You shouldn't need to create any collections yourself. Can you please provide a screenshot of the error?

lagost commented 7 years ago

Okay, I removed the DB and restarted and these are the exact steps I took within the Mongo shell:

  1. use LRS
  2. db.createUser(
    {
     user: "myusernamehere",
     pwd: "XXXXX",
     roles: [ "readWrite", "dbAdmin" ]
    }
    )
  3. php artisan migrate
  4. collection missing error

mongoerror

lagost commented 7 years ago

Also, if it helps, I have a connection called AdaptDB in MongoDB and here is my config file:

<?php

return [
  'fetch' => PDO::FETCH_CLASS,
  'default' => 'mongodb',
  'connections' => [
    'mongodb' => [
        'driver'   => 'mongodb',
        'host'     => 'localhost',
        'port'     => 27017,
        'username' => 'myusername',
        'password' => 'mypassword',
        'database' => 'LRS'
    ]
  ]
];
ryasmi commented 7 years ago

Hi @lagost, I don't think this will solve the issue, but it may help to be running php artisan migrate --env=local (although I'm pretty sure we always use local anyway).

As @ht2 said, we really need the full stack trace from the logs (in app/storage/logs).

lagost commented 7 years ago

Hi @ryansmith94, I am sending you the log file. I had decided to launch the learninglocker/public site to see if it would load and it did. I was able to even register my super user, however the links on the dashboard don't work. I imagine because it's not migrated with the DB.

Here is the log file. laravel-2017-01-21.txt

lagost commented 7 years ago

Also, forgot to mention that the php artisan migrate --env=local, also yielded the same error.

ryasmi commented 7 years ago

Thanks @lagost. Yeah that is most likely the issue there. Thanks for trying the --env=local.

Here are the unique errors I found in the log.

Collection name cannot be empty

[2017-01-21 21:44:22] local.ERROR: exception 'MongoException' with message 'Collection name cannot be empty' in C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php:78
Stack trace:
#0 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php(78): MongoDB->selectCollection('')
#1 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Schema\Blueprint.php(40): Jenssegers\Mongodb\Connection->getCollection(NULL)
#2 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Schema\Builder.php(112): Jenssegers\Mongodb\Schema\Blueprint->__construct(Object(Jenssegers\Mongodb\Connection), NULL)
#3 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Schema\Builder.php(81): Jenssegers\Mongodb\Schema\Builder->createBlueprint(NULL)
#4 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Migrations\DatabaseMigrationRepository.php(125): Jenssegers\Mongodb\Schema\Builder->create(NULL, Object(Closure))
#5 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\InstallCommand.php(52): Illuminate\Database\Migrations\DatabaseMigrationRepository->createRepository()
#6 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(112): Illuminate\Database\Console\Migrations\InstallCommand->fire()
#7 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(253): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(128): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php(102): Illuminate\Console\Command->call('migrate:install', Array)
#11 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php(61): Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase()
#12 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(112): Illuminate\Database\Console\Migrations\MigrateCommand->fire()
#13 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(253): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(889): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 C:\tedi\learninglocker\artisan(59): Symfony\Component\Console\Application->run()
#19 {main} [] []

There are no commands defined in the "make" namespace.

[2017-01-21 21:30:32] local.ERROR: exception 'InvalidArgumentException' with message 'There are no commands defined in the "make" namespace.' in C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php:516
Stack trace:
#0 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(550): Symfony\Component\Console\Application->findNamespace('make')
#1 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(190): Symfony\Component\Console\Application->find('make:migration')
#2 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 C:\tedi\learninglocker\artisan(59): Symfony\Component\Console\Application->run()
#4 {main} [] []

Symfony\Component\HttpKernel\Exception\NotFoundHttpException

[2017-01-21 21:23:09] local.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:148
Stack trace:
#0 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1054): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#1 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1022): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1001): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#3 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#4 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#5 C:\tedi\learninglocker\vendor\itsgoingd\clockwork\Clockwork\Support\Laravel\ClockworkLegacyMiddleware.php(20): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#6 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72): Clockwork\Support\Laravel\ClockworkLegacyMiddleware->handle(Object(Illuminate\Http\Request), 1, true)
#7 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#8 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#9 C:\tedi\learninglocker\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#10 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#11 C:\tedi\learninglocker\public\index.php(49): Illuminate\Foundation\Application->run()
#12 {main} [] []

Failed to connect to: localhost:27017: SASL Authentication failed on database 'LRS': Authentication failed.

[2017-01-21 21:16:21] local.ERROR: exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: SASL Authentication failed on database 'LRS': Authentication failed.' in C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php:133
Stack trace:
#0 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php(133): MongoClient->__construct('mongodb://local...', Array)
#1 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\Connection.php(40): Jenssegers\Mongodb\Connection->createConnection('mongodb://local...', Array, Array)
#2 C:\tedi\learninglocker\vendor\jenssegers\mongodb\src\Jenssegers\Mongodb\MongodbServiceProvider.php(32): Jenssegers\Mongodb\Connection->__construct(Array)
#3 [internal function]: Jenssegers\Mongodb\MongodbServiceProvider->Jenssegers\Mongodb\{closure}(Array, 'mongodb')
#4 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(163): call_user_func(Object(Closure), Array, 'mongodb')
#5 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(64): Illuminate\Database\DatabaseManager->makeConnection('mongodb')
#6 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Migrations\DatabaseMigrationRepository.php(167): Illuminate\Database\DatabaseManager->connection(NULL)
#7 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Migrations\DatabaseMigrationRepository.php(135): Illuminate\Database\Migrations\DatabaseMigrationRepository->getConnection()
#8 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php(371): Illuminate\Database\Migrations\DatabaseMigrationRepository->repositoryExists()
#9 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php(98): Illuminate\Database\Migrations\Migrator->repositoryExists()
#10 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php(61): Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase()
#11 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(112): Illuminate\Database\Console\Migrations\MigrateCommand->fire()
#12 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(253): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 C:\tedi\learninglocker\vendor\laravel\framework\src\Illuminate\Console\Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(889): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 C:\tedi\learninglocker\vendor\symfony\console\Symfony\Component\Console\Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 C:\tedi\learninglocker\artisan(59): Symfony\Component\Console\Application->run()
#18 {main} [] []
ryasmi commented 7 years ago

Am I right in saying that the first time you run the migrations you get the connection error and the second time you get the collection name error?

ryasmi commented 7 years ago

I've just noticed that the authentication fails for the database called 'admin', but you're config says 'LRS' in the same comment.

lagost commented 7 years ago

Yes, when I first ran the migration the connection error was the issue. I realized that it wasn't reading my local file but the app/database file instead. After I updated that file, the connection worked and I then got the collection error. Yes the db is LRS. Did you want me to drop the LRS and Admin and re-create the DB LRS and user?

lagost commented 7 years ago

here is the snapshot of the DB, if it helps.

mongodb

ryasmi commented 7 years ago

Ok. I would probably try to get it working without a username and password first.

lagost commented 7 years ago

Sorry, I don't quite understand.

ryasmi commented 7 years ago

I would try to remove any authentication to Mongo, setup LL to connect to Mongo without a username and password (like in the default LL config app/database.php), make sure that connects correctly, then try adding the authentication back if that works.

lagost commented 7 years ago

Oh, I see. Okay, I will give that a try and keep you posted.

lagost commented 7 years ago

Okay, the migration worked. That was great advice! What should I do now though. Try to add the credentials, or login to LL. BTW - I wanted to thank you so very much for all your help so far!! You have been super patient and helpful. Thank you!!!

ryasmi commented 7 years ago

Awesome. Thanks 😄 At this point, knowing that you can connect to Mongo now, I would try to setup a user on the database, and then add the username and password to the config. For now, edit the app/database.php file, once you get that working, try to use the app/local/database.php file.

You're very welcome Laura. Thank you for your gratitude and patience 😺

lagost commented 7 years ago

Okay, created the user in the DB, and updated the app/database.php file. Re-ran the migration, and all good!! Now, when I try to register the user on submit I get a 404 error page. error

ryasmi commented 7 years ago

Closing this due to inactivity, it will be reopened if it becomes active again.