Chapter 3 of 5

Install MariaDB and phpMyAdmin on Debian 13 for Laravel

verified on 2 September 2026 · 4 min

Quick answer

sudo apt install mariadb-server, then sudo mariadb-secure-installation (the old mysql_secure_installation is gone). Create a utf8mb4 database and a dedicated user limited to that database, never the administrator account. On the Laravel side, DB_CONNECTION=mysql is the right value for MariaDB too.

Laravel needs a database. On Debian, MariaDB is the default choice: it is the package the distribution ships, and it works with the MySQL driver Laravel already uses. phpMyAdmin comes afterwards, if you want a web interface to inspect your tables.

This chapter is part of installing Laravel on a Debian server, in the Web development track. The steps were run on Debian 13 “trixie” with MariaDB 11.8.6 and Laravel 13.30.1, on 2 September 2026.

Install MariaDB

bash
sudo apt update
sudo apt install -y mariadb-server
sudo systemctl enable --now mariadb
mariadb --version
code
mariadb from 11.8.6-MariaDB, client 15.2 for debian-linux-gnu

The administrator account is reachable from the root shell of the machine, with no password. That does not make the installation safe: it means the security rests entirely on who can get onto the server.

Secure the installation

Debian 13 ships the tool under its MariaDB name. The old mysql_secure_installation is gone:

bash
sudo mariadb-secure-installation

The script asks a series of questions. Answer them like this:

Question Answer Why
Switch to unix_socket authentication yes the administrator authenticates through their system account, not through a stored password
Change the root password up to you pointless once unix_socket is enabled
Remove anonymous users yes they allow a connection with no credentials
Disallow root login remotely yes administration happens over SSH, not on port 3306
Remove test database yes a database anyone can write to
Reload privilege tables yes applies the changes straight away

Create the database and the application user

Never run the application under the administrator account. Create a dedicated database and a dedicated account:

bash
sudo mariadb
sql
CREATE DATABASE laravel
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'un_mot_de_passe_long';

GRANT ALL PRIVILEGES ON laravel.* TO 'laravel'@'localhost';

FLUSH PRIVILEGES;

Two details are worth a second look. The utf8mb4 character set is not decoration: it is the only one that stores the whole of Unicode, emoji included. And the privilege is restricted to laravel.*, not *.*: if the application is ever compromised, the other databases stay out of reach.

Check the result:

sql
SHOW GRANTS FOR 'laravel'@'localhost';
code
GRANT USAGE ON *.* TO `laravel`@`localhost` IDENTIFIED BY PASSWORD '*1F48A8…'
GRANT ALL PRIVILEGES ON `laravel`.* TO `laravel`@`localhost`

Wire Laravel up

.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=un_mot_de_passe_long

DB_CONNECTION=mysql is the right value for MariaDB too: Laravel goes through the same PDO driver. Clear the configuration cache, then run the migrations:

bash
php artisan config:clear
php artisan migrate --force
code
  INFO  Running migrations.

  0001_01_01_000000_create_users_table ......................... 136.15ms DONE
  0001_01_01_000001_create_cache_table .......................... 65.58ms DONE
  0001_01_01_000002_create_jobs_table .......................... 117.52ms DONE

Migrations that go through are proof that the connection, the privileges and the character set are all correct.

If the connection fails

A “could not find driver” error does not come from MariaDB but from PHP: php-mysql is missing. Check with php -r 'echo implode(", ", PDO::getAvailableDrivers());', as covered in the chapter on PHP and its extensions, and make sure mysql shows up. The php-mysqli package is not enough, since Laravel goes through PDO.

phpMyAdmin, and whether you need it

phpMyAdmin is back in Debian 13, in version 5.2.2:

bash
sudo apt install -y phpmyadmin

The installer offers to configure the web server, Apache in the most common case, and creates its own configuration database. On an Apache install the interface is then served under /phpmyadmin.

An admin interface exposed to the internet is a target

The /phpmyadmin address is scanned around the clock. If you install it on a public server, restrict access by IP address or HTTP authentication, or do not expose it at all: an SSH tunnel lets you reach it from your own machine without opening it to the world.

bash
# SSH tunnel: phpMyAdmin stays on the server's loopback interface
ssh -L 8080:127.0.0.1:80 deploy@exemple.com
# then http://127.0.0.1:8080/phpmyadmin from your browser

For day-to-day work the command line is enough, and it sidesteps the question entirely:

bash
sudo mariadb laravel -e "SHOW TABLES;"
php artisan db:show
php artisan db:table users
php artisan tinker

php artisan db:show lists the tables, their size and their row count without leaving the terminal. That is usually all you need.

Back the database up

A database without a backup is not a production database. The bare minimum:

bash
sudo mariadb-dump --single-transaction laravel | gzip > /var/sauvegardes/laravel-$(date +%F).sql.gz

--single-transaction avoids locking InnoDB tables during the export, so the service keeps running while the backup is taken. Put that line in a scheduled job, and check from time to time that a restore really works: a backup you have never restored is a hypothesis, not a guarantee.

Common errors

mysql_secure_installation is gone On Debian 13 the tool is called mariadb-secure-installation.
Granting ALL PRIVILEGES on *.* A compromised application then reaches every database on the server. Restrict it to laravel.*.
Using utf8 instead of utf8mb4 utf8 does not cover the whole of Unicode: emoji and a few other characters fail on insert.
“could not find driver” error The problem is PHP, not MariaDB: php-mysql is missing. php-mysqli is not enough, since Laravel goes through PDO.
phpMyAdmin exposed to the internet The /phpmyadmin address is scanned around the clock. Restrict access or go through an SSH tunnel.
A backup that has never been restored A backup you have never replayed is a hypothesis. Test the restore.
Newsletter

New tests, tutorials and projects, by e-mail.

Reproducible tests, versioned code, dated results. Never any spam.