Last updated

Self-Hosted

ownCloud File Storage

Set up ownCloud on Ubuntu with NGINX and MariaDB for self-hosted file storage and sharing.

Contents

  1. Prerequisites
  2. Install PHP
  3. Create the Database
  4. Download ownCloud
  5. NGINX Configuration
  6. Add SSL with Let’s Encrypt
  7. Finish Installation

More on this topic:

Prerequisites

  • Ubuntu 20.04+ server
  • NGINX installed and running
  • MariaDB or MySQL installed
  • Domain name pointing to your server

Install PHP

sudo apt update
sudo apt install -y php8.1 php8.1-fpm php8.1-gd php8.1-json php8.1-mysql   php8.1-curl php8.1-mbstring php8.1-intl php8.1-imagick   php8.1-xml php8.1-zip php8.1-bcmath php8.1-gmp

Create the Database

sudo mysql -u root -p
CREATE DATABASE owncloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'owncloud'@'localhost' IDENTIFIED BY 'StrongPassword!';
GRANT ALL ON owncloud.* TO 'owncloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Download ownCloud

cd /var/www
sudo wget https://download.owncloud.com/server/stable/owncloud-complete-latest.tar.bz2
sudo tar -xjf owncloud-complete-latest.tar.bz2
sudo chown -R www-data:www-data owncloud/

NGINX Configuration

sudo nano /etc/nginx/sites-available/owncloud
server {
    listen 80;
    server_name files.yourdomain.com;
    root /var/www/owncloud;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires 30d;
        add_header Cache-Control "public, no-transform";
    }
}
sudo ln -s /etc/nginx/sites-available/owncloud /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Add SSL with Let’s Encrypt

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d files.yourdomain.com

Finish Installation

Browse to https://files.yourdomain.com and complete the web installer by entering your database credentials and admin user details.

Prefer Docker? Run ownCloud with Docker instead

ownCloud publishes a Docker Compose file with the server, MariaDB and Redis. Set your domain and admin password in a .env file, then start it. OWNCLOUD_IMAGE is the version tag; check Docker Hub (owncloud/server) for the newest one.

curl -fsSL https://get.docker.com | sudo sh
mkdir owncloud-docker && cd owncloud-docker
wget https://raw.githubusercontent.com/owncloud/docs-server/master/modules/admin_manual/examples/installation/docker/docker-compose.yml
cat > .env <<'EOF'
OWNCLOUD_IMAGE=11.0
MARIADB_IMAGE=mariadb:10.11
REDIS_IMAGE=redis:7
OWNCLOUD_DOMAIN=files.example.com
OWNCLOUD_TRUSTED_DOMAINS=files.example.com
OWNCLOUD_OVERWRITE_CLI_URL=https://files.example.com
ADMIN_USERNAME=admin
ADMIN_PASSWORD=change-this-long-password
HTTP_PORT=8080
EOF
docker compose up -d

Troubleshooting

Trusted domain error in the browser: add the address you use to the trusted domains (OWNCLOUD_TRUSTED_DOMAINS for Docker, or trusted_domains in config/config.php). Blank page or 502: read the logs. Desktop and phone apps: install the ownCloud app and connect it to your server address.

docker compose logs -f owncloud      # Docker
sudo tail -n 50 /var/log/nginx/error.log   # NGINX install

FAQ

Is ownCloud free?

The ownCloud community server is free and open source. Paid editions add enterprise features and support.

ownCloud or Nextcloud?

Both self-host your files with similar features. Nextcloud is a fork of ownCloud with a larger app store; ownCloud Infinite Scale is ownCloud's newer Go-based server.