How to Setup Nextcloud with MySQL on Ubuntu Using Docker and Sync it with iOS & macOS

Setting up Nextcloud with a MySQL database on Ubuntu using Docker is a great way to create your cloud storage system. This time I will walk you through the process of installing and setting up Nextcloud with a MySQL database, configuring volume settings, and connecting it to an iOS device for syncing files and photos. We’ll also cover how to set up WebDAV for easy access from macOS. Do keep in mind setups for devices like Windows/Android are similar when connecting to your Nextcloud instance. This tutorial is just focused on my devices.

Before starting the setup, ensure you know and have the following:

  • A Ubuntu server with sudo privileges
  • Docker and Docker Compose installed on your Ubuntu machine
  • Basic knowledge of Docker commands
  • A stable internet connection

Step 1: Install Docker and Docker Compose

First, update your system and install Docker and Docker Compose if they are not already installed:

sudo apt update && sudo apt upgrade -y
sudo apt install docker.io docker-compose -y
sudo systemctl start docker
sudo systemctl enable docker

Ensure Docker is installed correctly by running:

docker --version
docker-compose --version

Step 2: Setup MySQL Database Using Docker

To set up a MySQL database, run the following command. This will pull and run a MySQL Docker image:

docker run -d \
  --name mysql-nextcloud \
  -e MYSQL_ROOT_PASSWORD=your-root-password \
  -e MYSQL_DATABASE=nextcloud_db \
  -e MYSQL_USER=nextclouduser \
  -e MYSQL_PASSWORD=your-password \
  -v /your/local/path/mysql:/var/lib/mysql \
  --restart unless-stopped \
  mysql:latest

In this command:

  • Replace your-root-password, nextcloud_db, nextclouduser, and your-password with your preferred values.
  • The -v flag mounts your local directory for persistent MySQL data storage.

Verify that the MySQL container is running:

docker ps --filter "name=mysql-nextcloud"

Step 3: Setup Nextcloud Using Docker

Now let’s set up Nextcloud using the official LinuxServer.io image. This will also map the data folder to a specified location on your host machine:

docker run -d \
  --name nextcloud \
  -e PUID=1000 \
  -e PGID=1000 \
  -e MYSQL_PASSWORD=your-password \
  -e MYSQL_DATABASE=nextcloud_db \
  -e MYSQL_USER=nextclouduser \
  -e MYSQL_HOST=mysql-nextcloud \
  -v /your/local/path/nextcloud/data:/data \
  -v /your/local/path/nextcloud/config:/config \
  -v /your/local/path/nextcloud/apps:/apps2 \
  -p 8080:80 \
  --link mysql-nextcloud:mysql \
  --restart unless-stopped \
  linuxserver/nextcloud
  • PUID and PGID correspond to your user and group ID (you can find them by running id in the terminal).
  • Replace your-password and other environment variables with the values you used for the MySQL container.
  • The -v flags are used to mount your local directories for persistent storage.

You can verify if Nextcloud is running by going to http://your-server-ip:8080 in your web browser. You will most likely get a warning saying that it is not safe due to an invalid certificate, but this is normal due to us initially hosting it under HTTP. If you have an issue with the port for example being used you can specify a different one instead of 8080 if you want to use HTTPS you could forward the 443 port as well.

Step 4: First-Time Nextcloud Setup (Admin & MySQL Configuration)

  • Access the Nextcloud web interface by navigating to http://your-server-ip:8080 in your browser.
  • You’ll be prompted to create an admin account:
  • Set a username and password for the admin account.
  • Configure the MySQL database:
  • Choose MySQL/MariaDB as the database option.
  • Enter the MySQL user, password, and database name you used earlier:
    • Database user: nextclouduser
    • Database password: your-password
    • Database name: nextcloud_db
    • Database host: mysql-nextcloud
  • Complete the setup and Nextcloud will initialize.

Step 5: Installing and Connecting Nextcloud App on iOS

To sync and upload photos or videos from your iOS device to Nextcloud, follow these steps:

  • Install the Nextcloud app from the App Store.
  • Open the app, and when prompted, enter the URL of your Nextcloud server:
    http://your-server-ip:8080.
  • Login using the admin account credentials you created during the setup.
  • To enable photo and video uploads:
  • Go to the settings in the app.
  • Toggle on the “Automatic upload” for photos and videos.

This will start syncing files from your iOS device directly to your Nextcloud instance.

Step 6: Configuring WebDAV for macOS File Access

Nextcloud supports WebDAV, allowing you to access your files directly from Finder on macOS. Here’s how to set it up:

  • You can get the correct WebDAV URL from your Nextcloud web server when you log in.
  • Open Finder on your Mac.
  • Click on Go in the menu bar and then select Connect to Server.
  • Enter the WebDAV URL for your Nextcloud instance in the following format:
http://your-server-ip:8080/remote.php/webdav
  • When prompted, enter your Nextcloud admin credentials.
  • Your Nextcloud files will now be accessible from Finder just like any other network drive.

This makes it easy to drag and drop files to and from your Nextcloud server. You can additionally add it to reconnect when you log back into your Macbook. This can be done from the System Settings and by finding the Open at Login settings. Here you just add the now connected folder and it should reconnect on start-up.

Conclusion

Setting up Nextcloud on Ubuntu using Docker with a MySQL database provides a powerful and customizable private cloud solution. By following the steps above, you can quickly deploy Nextcloud, sync your data across iOS devices, and access your files using WebDAV on macOS. With Docker managing the containers, your data remains organized and easily maintainable, ensuring that you have full control over your cloud storage.

In addition, this setup allows you to take advantage of Nextcloud’s scalability, making it suitable not just for individual use but also for small teams or businesses that need secure file-sharing capabilities. By using Docker, you ensure that your Nextcloud installation is easily portable, manageable, and scalable with minimal maintenance.

While this guide focuses on Apple devices, do not worry Nextcloud is also compatible with Windows and Android devices as they have comparable applications available for other operating systems as well.

As a last point, this also works with a VPN so if you have access to your internal network remotely you can use the Nextcloud storage externally as well without opening it up to the internet. I can confirm this works with the Wireguard setup I have posted previously.
Like always I hope this has helped you out.

Helpful Resources

Here are some helpful resources for further reference:

HTTPS Setup & Certificate Management resources:

Share

Antanaitis

I always wanted to somehow document my work and ideas. I'm finally writing something.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *