Running Nextcloud Locally


Intro

Backup services like iCloud and Google Drive are convenient to use. iCloud and Google Drive have limited space and send your files over the internet. Here, I will cover a free and open-source project called Nextcloud. I will also show you how to host Nextcloud on your internal network.

Prerequisites:

  • Download this example repository.
  • A Computer that can handle running Docker.
  • Docker Installed.
    • WSL2 (Windows Subsystem for Linux) if you are on Windows.
  • Some experience with Docker.
  • Experience with networking.

Acronym meanings:

  • DNS: Domain Name System
  • DHCP: Dynamic Host Configuration Protocol
  • IP address: Internet Protocol Address
  • WSL: Windows Subsystem for Linux

What is Nextcloud?

Nextcloud is a software suite like Google Drive, Microsoft 365, Dropbox, and iCloud. There are many different plugins and configurations that Nextcloud has available. Nextcloud is also a collaborative tool.

Nextcloud after login.
Nextcloud after login.

I will review the following use cases with Nextcloud:

  • Easy automatic content backup from iPhone or Android.
  • On-premise file backup.
  • Local file upload, not using any public internet connection.
  • Using an external drive.

NOTE: using these principles on the public internet is possible. Review security best practices on Nextcloud. Scan your website with Nextcloud Security Scan.

Why would you only run Nextcloud on a local network?

I wanted to run Nextcloud locally because I did not want to expose my home server to the internet. The other reason is I wanted faster upload speeds that do not rely on my internet access.

I like the idea of not sending all my content across the internet.

Nextcloud is a good solution for content creators that use a phone as their creation tool.

Setting up Nextcloud for our local network

First, we will install our dependencies, then configure the network.

Setting up dependencies

To get started, you must install Docker on your system. Docker is a tool that runs defined services in “containers.” Docker helps make for a more standard process when running your services.

After installing Docker, clone my project repository. Everything we will run will be from within the root of this project directory.

Why use Docker?

Now that we have the dependencies set up, I’ll explain why we are using Docker. Docker is a tool that allows developers to define “containers.” The Docker code outlines the services and makes our project more portable. Nextcloud should be able to run on any device supporting Docker. Isn’t that cool?

Specifying our environment information

With Docker installed and our project cloned, we can start configuring network settings.

Setting the static IP address

With Docker installed and our project cloned, we can start configuring the necessary settings for this to run in your network.

It will be helpful to set a static IP address. We can reference our server in the future at the same IP address. Most devices will operate on a dynamic IP address. This means the IP address can change on the network. We don’t want the IP address to change, and that’s where the static IP address will help us.

First, we identify the local network Dynamic Host Configuration Protocol (DHCP) ip range. Most home networks will use 192.168.1.1-192.168.1.254.

Here are the commands for finding your network gateway and IPv4 address.

Windows:

ipconfig

Mac/Linux:

ifconfig | grep "inet " | grep -v 127.0.0.1

If you are on a standard network the, network gateway should be either 192.168.1.1 or 192.168.0.1.

In this example, our network gateway is 192.168.1.1. We should be able to set a static IP address between these two numbers 192.168.1.1 - 192.168.1.254. Let’s configure our computer’s IP address 192.168.1.2.

The configuration will vary on your environment, but the settings will be similar.

To set this IP address in Windows, access your internet access adapter. Control Panel > Network and Internet > Network Connections. Then right-click on your adapter and select properties. Then highlight Internet Protocol Version 4 and click properties.

Now we can set the properties to establish our static IP address of 192.168.1.2.

IP address: IP Address: 192.168.1.2 Subnet Mask: 255.255.255.0 Default Gateway: 192.168.1.1

DNS Settings (using Google’s DNS): Preferred DNS: 8.8.8.8 Secondary DNS: 8.8.4.4

Static IP address settings.
Static IP address settings.

On Mac/Linux, you will want to set the same settings on your default network adapter.

NOTE: If you want a different IP address, make sure you replace all instances of 192.168.1.2 in the example repository.

After setting the IP address, run ipconfig or ifconfig from earlier to verify the change.

Defining the volume locations

Docker allows us to map the files running in the service to a location on our computer. In the root of the example project, there’s an environment file .env; this file sets some of the project settings. The variable we want to look at is NEXTCLOUD_ROOT. NEXTCLOUD_ROOT establishes the default location for the Nextcloud files. By default it’s mapping to the “E:” drive on my computer. You can set this to a local directory on your computer or an external device.

Hard drive location.
Hard drive location.

Defining Nextcloud security

To change the login information, update these two variables in docker-compose.yml.

NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=password

Since this is on your internal network, there shouldn’t be outside access to this server. It’s a good idea to secure these settings.

If you’d like to change other settings, find the options in docker-compose.yml.

Running and testing the Nextcloud installation

We have our static IP address set now we can test running our project.

In the root directory of the example project, run this command:

docker-compose up -d

The -d flag will run this docker command detached from the terminal.

This command will build the Docker services, volumes, and networks.

NOTE: Windows Subsystem for Linux WSL2 is currently very slow. After starting the build, watch the fpm process until initialization. On Windows, this could be a half hour or more.

Docker services running.
Docker services running.

Once the build is successful, you should see all green in the Docker dashboard. Then you should be able to access Nextcloud on your computer at http://192.168.1.2.

The default login:

  • Username: admin
  • Password: password
Configuring the Nextcloud installation

After you log in to your Nextcloud instance, there’s a variety of settings available based on your needs. In the right-hand menu, you will find links for different settings.

I would recommend reviewing the following:

  • Administration settings.
  • Apps.
  • User settings.

Connecting local devices to Nextcloud

Now things get interesting, let’s set up a local device to connect to our Nextcloud instance. In this example, I will use an iPhone.

From the iPhone app store, download the Nextcloud app. After installing the app, use the static IP Address from the server 192.168.1.2. You will need to allow the connection and then enter your admin credentials. And like that, the app connected.

Nextcloud app after login.
Nextcloud app after login.

In the app, you can set up auto-upload. The app now uploads videos and photos. If photos or videos don’t upload, you can click on the upload “entire camera roll.” Auto-upload should check for any missing items. I had this happen once when testing when my videos were too large.

Auto-upload setting.
Auto-upload setting.

Troubleshooting tips

The following is a list of items to help when troubleshooting your setup.

Blank webpage

If you see a blank webpage, the nginx proxy server is working, but the fpm service may have issues.

Check the logs for the fpm service in Docker like this:

FPM service running successfully.
FPM service running successfully.

If you see that fpm is still initializing and you are on Windows, it may just be the slow file writing from WSL.

Slow Nextcloud page loads on Windows

If your pages are loading slowly and you are on Windows, this is WSL. Currently, there isn’t a workaround for this, so it may be beneficial to use Linux instead.

Docker issues on Windows

If you ever run into issues with Docker on Windows, delete the .docker folder in your user directory. Example: \Users\nicholas\.docker.

Conclusion/Key Takeaways

We now have a backup tool for storing photos and videos from our phones. Nextcloud is for anyone who records videos, such as social media content creators.

6 takeaways:

  1. Nextcloud is a free alternative to Google Drive and iCloud.
  2. A static IP address allows us to reference our server.
  3. Docker allows us to run Nextcloud on many operating systems.
  4. Nextcloud can be set up to operate in an internal network.
  5. Nextcloud can use an external drive, allowing us to specify storage locations.
  6. Windows WSL2 may operate a little slowly, but it still works!

Now that you have Nextcloud running, I hope you have an enjoyable process backing up your phone media.

References

Example repositories


About the author