Extensive Guide: Installing MariaDB with PhpMyAdmin on Ubuntu 24.04 LTS (With and Without Docker)

This guide will walk you through two methods to install MariaDB with PhpMyAdmin on Ubuntu: using Docker/Docker Compose and without Docker.

MariaDB is a popular open-source database, and PhpMyAdmin is a web-based tool that allows you to manage MySQL/MariaDB databases easily.

Method 1: Installing MariaDB and PhpMyAdmin Using Docker/Docker Compose

Step 1: Install Docker and Docker Compose

First, ensure Docker and Docker Compose are installed on your Ubuntu system.

Install Docker Compose:

sudo apt install docker-compose -y

Install Docker:

sudo apt update
sudo apt install docker.io -y

Step 2: Create a Directory for Your Setup

Create a directory for your Docker setup:

mkdir mariadb-phpmyadmin-docker
cd mariadb-phpmyadmin-docker

Step 3: Create a docker-compose.yml File

Create a docker-compose.yml file in the directory with the following content:

version: '3.7'

services:
  mariadb:
    image: mariadb:latest
    container_name: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: my_database
      MYSQL_USER: user
      MYSQL_PASSWORD: user_password
    ports:
      - "3306:3306"
    volumes:
      - ./mariadb_data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: phpmyadmin
    restart: always
    environment:
      PMA_HOST: mariadb
      MYSQL_ROOT_PASSWORD: root_password
    ports:
      - "8080:80"

Step 4: Configure Environment Variables

Replace root_password, my_database, user, and user_password with your desired values.

Step 5: Start the Docker Containers

Run the following command to build and start the containers:

docker-compose up -d

Step 6: Access PhpMyAdmin

Once the containers are running, access PhpMyAdmin by navigating to http://localhost:8080 in your web browser. Log in with the credentials you configured in the docker-compose.yml file.

Step 7: Manage Your Containers

Use the following commands to manage your Docker containers:

Rebuild and restart the containers:

docker-compose up --build -d

View logs:

docker-compose logs -f

Stop the containers:

docker-compose down

Method 2: Installing MariaDB and PhpMyAdmin Without Docker

Step 1: Update and Upgrade Your System

First, update your package list and upgrade your system:

sudo apt update
sudo apt upgrade -y

Step 2: Install MariaDB

Secure MariaDB Installation:Run the security script to set the root password and secure your MariaDB installation:

sudo mysql_secure_installation

Follow the prompts to secure your installation (set root password, remove anonymous users, disallow root login remotely, remove test database, and reload privilege tables).

Install MariaDB Server:

sudo apt install mariadb-server mariadb-client -y

Step 3: Create a Database and User

Log into the MariaDB shell:

sudo mysql -u root -p

Create a database and user, and grant the user privileges:

CREATE DATABASE my_database;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'user_password';
GRANT ALL PRIVILEGES ON my_database.* TO 'user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Install PhpMyAdmin

  1. Configure PhpMyAdmin:During installation, you’ll be prompted to choose a web server (Apache or Nginx). Select Apache if you have it installed, or configure Nginx separately. You’ll also be prompted to configure the database for PhpMyAdmin. Choose Yes and enter your MariaDB root password when prompted.

Enable PHP Extensions:Enable the necessary PHP extensions and restart Apache:

sudo phpenmod mbstring
sudo systemctl restart apache2

Install PhpMyAdmin:

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl -y

Step 5: Configure Apache (if using Apache)

If you’re using Apache, ensure the PhpMyAdmin configuration is included. You can do this by creating a symbolic link:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo systemctl reload apache2

Step 6: Access PhpMyAdmin

Access PhpMyAdmin by navigating to http://localhost/phpmyadmin in your web browser. Log in with the MariaDB credentials you created earlier.

Conclusion

This guide provides a comprehensive overview of how to install MariaDB with PhpMyAdmin on Ubuntu, using both Docker/Docker Compose and a traditional installation method. Whether you prefer containerized environments or traditional setups, you can now manage your MariaDB databases with the powerful PhpMyAdmin web interface.








Open-source Apps

9,500+

Medical Apps

500+

Lists

450+

Dev. Resources

900+

Read more