First Setup of SQL Database

OK. I’ve given up on trying to run Invoice Ninja in a Docker Container on my QNAP NAS. No one here seems to have any clue about how to make this work (sorry @hillel - I appreciate your support and efforts so please don’t take this statement wrong).

So I ended up installing the Invoice Ninja app from the MyQNAP.org repo. So now I have a working webpage! Hooray! But now I am stuck…

I need to create the MySQL database. So I am not sure what to enter here nor do I know where to enter the code shown:

-- Commands to create a MySQL database and user
CREATE SCHEMA `db-ninja-01` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'ninja'@'localhost' IDENTIFIED BY 'ninja';
GRANT ALL PRIVILEGES ON `db-ninja-01`.* TO 'ninja'@'localhost';
FLUSH PRIVILEGES;

Do I run that in the shell of the NAS? I just tried that and got errors. This looks like SQL code to me but not sure where I run that…

Here’s a screenshot of what I am seeing…

So I went back to the default localhost and tried again. This time it looks like I get a connection but no database…

So where do I run the SQL code…

Hi,

I don’t have much experience with QNAP, but here’s what AI suggests in case it’s helpful:

That is a common point of confusion when setting up self-hosted apps. The reason you saw errors is that the code you have is SQL, which is a language specific to database servers. You cannot run it directly in the NAS shell (the command line where you see the NAS name and a cursor) because the shell speaks Linux commands, not database commands.

To make this work, you need to “log in” to your database server first. Here are the two best ways to do this on a QNAP NAS.

Method 1: Using phpMyAdmin (The Easiest Way)

Most QNAP users prefer this because it provides a visual interface for the database.

  1. Install phpMyAdmin: Open the App Center on your QNAP and install the phpMyAdmin app.
  2. Log In: Open phpMyAdmin. The default username is usually root. The password is often admin, your NAS admin password, or whatever you set when you enabled the MariaDB/MySQL server in the Control Panel.
  3. Run the Code: * Once logged in, look for the SQL tab at the top of the screen.
    • Paste your entire block of code into the text box.
    • Click the Go button at the bottom right.

Method 2: Using the Command Line (SSH)

If you prefer using the shell, you just need to enter the “MySQL Monitor” mode first.

  1. Connect via SSH: Open your terminal or PuTTY and log into your NAS.
  2. Enter the Database Monitor: Type the following command and press Enter:
    mysql -u root -p
    (Note: If you have MariaDB 10 installed, you might need to use the specific path: /usr/local/mariadb/bin/mysql -u root -p).
  3. Enter Password: Type your database root password when prompted. You should now see a prompt that looks like mysql> or MariaDB [(none)]>.
  4. Paste the Code: Now you can paste your SQL commands. Make sure to include the semicolons at the end of each line.
  5. Exit: Once it says “Query OK,” type exit to leave the database monitor.

Important Tips for QNAP

  • Enable the Server: Before doing any of this, ensure the database server is actually turned on. Go to Control Panel > Applications > MariaDB (or MySQL Service) and make sure Enable MariaDB Server is checked.
  • MariaDB 10 vs. 5: Modern versions of Invoice Ninja usually require MariaDB 10. If you have both installed on your QNAP, MariaDB 10 often runs on port 3307 instead of the standard 3306.
  • The “localhost” detail: The code you have creates a user that can only connect from “localhost.” Since you are using a repo app (not Docker), this should work perfectly as the app and the database are running on the same “local” system.

Once those commands run successfully, you can go back to the Invoice Ninja setup page and enter db-ninja-01 as the database name, ninja as the user, and ninja as the password.

So thank you - I am closer and was able to create the database in phpMyAdmin, but I am still getting an error in InvoiceNinja that there is no such file…

But the database is there in MariaDB. Now I can’t set MariaDB as the driver - so I don’t know if that’s an issue but MariaDB and MySQL are compatible…

As suggested above, I am running MariaDB 10. And I’m using port 3307.

I tried creating db-ninja-01 as was originally there - didn’t work. I tried creating another database, dbninja. Still doesn’t work.

Getting this to run should not be this hard!

Since I can only put in one image per post, here’s a picture from phpMyAdmin

Can you please share the exact error you’re seeing?

Have you tried running:
sudo -u www-data php ./artisan migrate:fresh --seed

Run it from where ever the artisan command is…eg /var/www/html/ninja

It rebuilds the database. I think you have to have the database there beforehand.

Just a suggestion.

As shown in the picture above:

It says there’s no such file but there is…

I am getting this error:

sudo -u www-data php ./artisan migrate:fresh --seed
sudo: unknown user www-data
sudo: error initializing audit plugin sudoers_audit

I am also seeing this in the InvoiceNinja logs:

[Tue Mar 31 18:38:49.638802 2026] [example_hooks:notice] [pid 10629:tid 10629] x_monitor()
[Tue Mar 31 18:38:56.899601 2026] [example_hooks:notice] [pid 10723:tid 10863] x_create_connection()
[Tue Mar 31 18:38:56.903429 2026] [example_hooks:notice] [pid 10723:tid 10863] x_create_request()
[Tue Mar 31 18:38:56.903610 2026] [authz_core:debug] [pid 10723:tid 10863] mod_authz_core.c(815): [client 192.168.0.106:56399] AH01626: authorization result of Require all granted: granted, referer: http://192.168.0.3:28463/setup
[Tue Mar 31 18:38:56.903627 2026] [authz_core:debug] [pid 10723:tid 10863] mod_authz_core.c(815): [client 192.168.0.106:56399] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.0.3:28463/setup
[Tue Mar 31 18:38:56.903667 2026] [charset_lite:debug] [pid 10723:tid 10863] mod_charset_lite.c(216): [client 192.168.0.106:56399] AH01448: incomplete configuration: src unspecified, dst unspecified, referer: http://192.168.0.3:28463/setup
[Tue Mar 31 18:38:56.903694 2026] [example_hooks:notice] [pid 10723:tid 10863] x_create_request()
[Tue Mar 31 18:38:56.903721 2026] [authz_core:debug] [pid 10723:tid 10863] mod_authz_core.c(815): [client 192.168.0.106:56399] AH01626: authorization result of Require all granted: granted, referer: http://192.168.0.3:28463/setup
[Tue Mar 31 18:38:56.903732 2026] [authz_core:debug] [pid 10723:tid 10863] mod_authz_core.c(815): [client 192.168.0.106:56399] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.0.3:28463/setup
[Tue Mar 31 18:38:56.903762 2026] [charset_lite:debug] [pid 10723:tid 10863] mod_charset_lite.c(216): [client 192.168.0.106:56399] AH01448: incomplete configuration: src unspecified, dst unspecified, referer: http://192.168.0.3:28463/setup

Also, I found the .env file for the app. Maybe because the settings are different in .env from what I am being presented with?

[jono@NA9D-NAS-3 www]$ cat .env
APP_NAME="Invoice Ninja"
APP_ENV=production
APP_KEY=base64:xxxxxxxxxxxxxx
APP_DEBUG=false

APP_URL=http://localhost
REACT_URL=http://localhost:3001

DB_CONNECTION=mysql
MULTI_DB_ENABLED=false

DB_HOST=localhost
DB_DATABASE=ninja
DB_USERNAME=ninja
DB_PASSWORD=ninja
DB_PORT=3306

DEMO_MODE=false

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

MAIL_MAILER=smtp
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

POSTMARK_API_TOKEN=
REQUIRE_HTTPS=false

GOOGLE_MAPS_API_KEY=
ERROR_EMAIL=
TRUSTED_PROXIES=
SCOUT_DRIVER=null 

NINJA_ENVIRONMENT=selfhost

#options - snappdf / phantom / hosted_ninja
PDF_GENERATOR=hosted_ninja

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

UPDATE_SECRET=secret

DELETE_PDF_DAYS=60
DELETE_BACKUP_DAYS=60

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

GOOGLE_PLAY_PACKAGE_NAME=
APPSTORE_PASSWORD=

MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
MICROSOFT_REDIRECT_URI=

APPLE_CLIENT_ID=
APPLE_CLIENT_SECRET=
APPLE_REDIRECT_URI=

NORDIGEN_SECRET_ID=
NORDIGEN_SECRET_KEY=

GOCARDLESS_CLIENT_ID=
GOCARDLESS_CLIENT_SECRET=

OPENEXCHANGE_APP_ID=

OK - SUCCESS! I received some instructions from QNAP that allowed me to connect to the database not via localhost but via the IP address of the NAS. I set up the MariaDB server to allow external connections for the ninja user. Now it works and I can connect to the database.

Glad to hear it, thanks for the update!

Yeah, I’m not connecting via localhost so hope that is not too much of a problem.