Skip to main content

Simplifying Self-Hosting: Setting Up Nextcloud, MariaDB, and phpMyAdmin with Docker Compose

In today's digital age, privacy and control over our data are becoming increasingly important. Self-hosting solutions offer a way to regain control by hosting applications like cloud storage and databases on your own servers. In this guide, we'll walk you through setting up Nextcloud, MariaDB, and phpMyAdmin using Docker Compose, making self-hosting accessible and manageable for everyone.

Why Self-Host?

Self-hosting allows you to store your data on your own infrastructure, providing greater control, privacy, and security compared to relying on third-party services. By hosting applications like Nextcloud for file storage, sharing, and collaboration, and MariaDB for database management, you can tailor the setup to your specific needs while maintaining full ownership of your data.

Prerequisites

Before we dive into the setup process, ensure you have the following prerequisites:

  • Docker installed on your system
  • Docker Compose installed on your system
  • Basic understanding of Docker and Docker Compose

Docker Compose Configuration

We'll use Docker Compose to define and run our multi-container application. Below is the docker-compose.yml file that orchestrates Nextcloud, MariaDB, and phpMyAdmin:

version: '3.8'

services:
  mariadb:
    container_name: nextclouddb
    deploy:
      resources:
        limits:
          memory: 2603M
    environment:
      - MYSQL_DATABASE=nextcloud
      - MYSQL_PASSWORD= # Blank password for security reasons
      - MYSQL_ROOT_PASSWORD= # Blank password for security reasons
      - MYSQL_USER=ncloud-admin
      - PGID=1000
      - PUID=1000
      - TZ=Europe/Berlin
    image: linuxserver/mariadb:10.11.4
    ports:
      - "3306:3306"
    restart: unless-stopped
    volumes:
      - /DATA/AppData/mariadb/config:/config

  nextcloud:
    cpu_shares: 90
    command:
      - apache2-foreground
    container_name: n-cloud
    deploy:
      resources:
        limits:
          memory: 7751M
    environment:
      - MYSQL_HOST=mariadb
      - MYSQL_DATABASE=nextcloud
      - MYSQL_PASSWORD= # Blank password for security reasons
      - MYSQL_USER=ncloud-admin
      - PHP_OPCACHE_MEMORY_CONSUMPTION=256 # PHP OPCache memory consumption
    image: nextcloud:latest
    labels:
      icon: https://cdn.jsdelivr.net/gh/IceWhaleTech/CasaOS-AppStore@main/Apps/Nextcloud/icon.png
    ports:
      - target: 443
        published: "443"
        protocol: tcp
      - target: 80
        published: "45289"
        protocol: tcp
    privileged: true
    restart: unless-stopped
    volumes:
      - type: bind
        source: /mnt/cloud/nextcloud
        target: /var/www/html

  phpmyadmin:
    container_name: phpmyadmin
    image: phpmyadmin/phpmyadmin
    environment:
      - PMA_ARBITRARY=1
    ports:
      - "8080:80"
    restart: always
    depends_on:
      - mariadb

Understanding the Configuration

  • MariaDB Service: Provides the database backend for Nextcloud.
  • Nextcloud Service: Offers cloud storage and collaboration features.
  • phpMyAdmin Service: Enables convenient management of the MariaDB database through a web interface.

Conclusion

Self-hosting applications like Nextcloud, MariaDB, and phpMyAdmin with Docker Compose empowers you to take control of your data while maintaining privacy and security. With this setup, you can enjoy the benefits of cloud storage and database management on your own terms. Simply run docker-compose up in the directory containing the docker-compose.yml file, and your services will be up and running. Embrace the freedom and control of self-hosting today!