V5 unable to connect to database

Hi all,

I’m unable to get a database connection working with mariaDB on v5.
Opening the site gives a “Target class [db] does not exist.” with a reference to a check for the accounts table, however as the issue remains the same when entering a wrong DB password on purpose, it probably just can’t connect.

Config file below. Note: DB is running on a non-standard port, but switch it to 3306 makes no difference.
Any ideas?

Thanks in advance!

Timmmy

APP_NAME="Invoice Ninja"
APP_ENV=production
APP_KEY=base64:xxxx
APP_DEBUG=true

APP_URL=http://xxxxx

DB_CONNECTION=db-ninja-01
MULTI_DB_ENABLED=false

DB_HOST1=127.0.0.1:3307
DB_DATABASE1=ninja
DB_USERNAME1=ninja
DB_PASSWORD1=xxxx

#DB_HOST2=127.0.0.1:3307
DB_DATABASE2=ninja2
DB_USERNAME2=ninja
DB_PASSWORD2=xxx

DEMO_MODE=false

BROADCAST_DRIVER=log
LOG_CHANNEL=stack
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_HOST=localhost
MAIL_USERNAME=Tim@no-reply.com
MAIL_FROM_NAME=Tim@no-reply.com
MAIL_FROM_ADDRESS=Tim@no-reply.com
MAIL_PASSWORD=Tim@no-reply.com

POSTMARK_API_TOKEN=
REQUIRE_HTTPS=false

GOOGLE_MAPS_API_KEY=
ERROR_EMAIL=
TRUSTED_PROXIES=

NINJA_ENVIRONMENT=selfhost

PHANTOMJS_PDF_GENERATION=false
PHANTOMJS_KEY='a-demo-key-with-low-quota-per-ip-address'
PHANTOMJS_SECRET=secret

COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
SENTRY_LARAVEL_DSN=xxx

Hi,

Have you run php artisan optimize after changing the file?

Hi @hillel,

Thx, now I’m indeed able to connect (with an old db backup loaded).
For a clean database, how can I create the structure? I’ve tried the setup wizard, but no luck…

For anyone also struggling on Synology to run php artisan optimize (it defaults to an earlier version): new versions are located in ex. /volumeXX/@appstore/PHP7.4/usr/local/bin/php74.
You can run this with the full path to the executable without having to modify the default version.

Thanks in advance,

Tim

Are you seeing a specific error?

Hi @hillel,

No, setup wizard completes fine but just returns to the start of the wizard after ending.
DB structure is not created.

Root url returns just a 500 without further detail, even with debug on :confused:

Are there any errors in the web server error logs or the application logs in storage/logs/

On finishing the setup wizard, this is in the laravel log:
[2021-04-23 13:45:04] production.INFO: The command "mysql --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --database="${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"" failed.

Exit Code: 127(Command not found)

Working directory: /volume2/web/InvoiceNinja/ninja5/public

Output:
================


Error Output:
================
sh: mysql: command not found

On calling the main page (but probably just a consequence of the previous step failing)
"[2021-04-23 13:42:15] production.INFO: account table not found"

Nothing in Apache or PHP error logs it seems.

I suggest checking mysql is installed

@hillel Thanks!

There seems to be an issue there indeed. It is installed but permissions and PATH are not set as you would expect. Although, being on a NAS it will probably not be easy to fix.

Is mysql only needed during initial set-up or also with upgrades etc…

I assume mysql is always needed by the app

@timmy I had the same problem but was able to fix it.
The problem is that InvoiceNinja calls ‘mysql’ and because we installed MariaDB packages, that command cannot be found in the current path.
The solution is to add the path or what I did: create a symbolic link.
You can create a symbolic link to mysql in /usr/local/bin, e.g.:
sudo ln -s /volume1/@appstore/MariaDB10/usr/local/mariadb10/bin/mysql /usr/local/bin/mysql

Thanks for sharing your solution!

cc @david @ben

Thanks for sharing this with us. However, this seems to be an edge case, since we didn’t have many reports for this not working. That said, I don’t think it’s worth putting this into docs.

However, what we could do is, having a dedication section in docs with many helpful links, which includes links to this thread.

@hillel @david thoughts?

My preference would be to compile these sorts of tips into the docs directly, maybe in the troubleshooting section. This makes it easier to search, using links makes things harder to find.

Note: for this particular problem the better solution may be to add MariaDB as an option, I imagine many users will want to use it.