To install NextCloud from the command line, prepare a LEMP/LAMP stack, create a database, download the Nextcloud tarball, configure your web server (Nginx or Apache), run the occ CLI installer, enable HTTPS, and set up cron and caching (Redis).
The steps below cover Docker, Snap, and production-grade manual installs.
If you want a private, self-hosted cloud with full control, learning how to Install NextCloud From Command Line is the fastest and most reliable path.
This guide walks you through Docker, Snap, and a hardened Ubuntu/Debian stack with Nginx, PHP-FPM, MariaDB, and Redis—entirely via CLI.

What you’ll Learn Here (and what you need)
This tutorial is designed for beginners and sysadmins alike. You’ll learn repeatable commands to deploy, secure, and maintain Nextcloud. We’ll use Ubuntu/Debian for examples (24.04/22.04 and 12/11), with notes for RHEL/CentOS/Rocky. You’ll need:
Quick Start: Docker One-Liner (fastest way)
Use Docker for a quick, reproducible CLI deployment. The command below starts Nextcloud with SQLite (great for testing). For production, pair Nextcloud with MariaDB/PostgreSQL and Redis (compose file suggested).
# Install Docker if missing (Ubuntu/Debian)
curl -fsSL https://get.docker.com | sudo sh
# Quick test deployment (SQLite)
sudo docker run -d --name nextcloud \
-p 8080:80 \
-v nextcloud:/var/www/html \
nextcloud:stable
# Open http://SERVER_IP:8080 and complete the setup wizard
# For production, prefer a compose stack with MariaDB + Redis. Example:
cat > docker-compose.yml <<'YAML'
services:
db:
image: mariadb:10.11
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: unless-stopped
environment:
- MARIADB_DATABASE=nextcloud
- MARIADB_USER=ncuser
- MARIADB_PASSWORD=StrongDBPass
- MARIADB_ROOT_PASSWORD=RootDBPass
volumes:
- db:/var/lib/mysql
redis:
image: redis:7-alpine
restart: unless-stopped
app:
image: nextcloud:stable
restart: unless-stopped
ports:
- "80:80"
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=ncuser
- MYSQL_PASSWORD=StrongDBPass
- REDIS_HOST=redis
depends_on:
- db
- redis
volumes:
- nextcloud:/var/www/html
volumes:
db:
nextcloud:
YAML
sudo docker compose up -d
Add a reverse proxy and Let’s Encrypt (e.g., Traefik or Nginx Proxy Manager) to serve your domain over HTTPS.
Production-grade CLI Install (Ubuntu/Debian + Nginx + PHP-FPM + MariaDB + Redis)
This is the most common, performance-friendly stack for Nextcloud. All steps are strictly via command line.
1) Update server and install packages
sudo apt update && sudo apt -y upgrade
# Install Nginx, MariaDB, Redis, PHP-FPM and needed extensions
sudo apt -y install nginx mariadb-server redis-server \
php php-fpm php-cli php-mysql php-xml php-curl php-gd php-zip php-mbstring php-intl php-bcmath php-gmp php-imagick php-apcu php-redis
# Optional: ensure Redis listens on a Unix socket and allow web user
sudo usermod -aG redis www-data
sudo systemctl enable --now nginx mariadb redis-server php-fpm
2) Create database and user
sudo mysql -e "CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
sudo mysql -e "CREATE USER 'ncuser'@'localhost' IDENTIFIED BY 'StrongDBPass!';"
sudo mysql -e "GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncuser'@'localhost'; FLUSH PRIVILEGES;"
3) Download NextCloud and set permissions
# Get latest stable
cd /tmp
curl -LO https://download.nextcloud.com/server/releases/latest.tar.bz2
curl -LO https://download.nextcloud.com/server/releases/latest.tar.bz2.sha256
sha256sum -c latest.tar.bz2.sha256 # (Optional but recommended)
# Extract and move into web root
tar -xjf latest.tar.bz2
sudo rsync -Aax nextcloud/ /var/www/nextcloud/
# Ownership for web server user
sudo chown -R www-data:www-data /var/www/nextcloud
4) Configure Nginx for Nextcloud
Replace cloud.example.com with your domain. This config targets PHP-FPM’s default socket and includes best practices for caching and security.
sudo tee /etc/nginx/sites-available/nextcloud >/dev/null <<'NGINX'
server {
listen 80;
listen [::]:80;
server_name cloud.example.com;
root /var/www/nextcloud;
index index.php index.html /index.php$request_uri;
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# HSTS disabled on HTTP; enabled after HTTPS is configured
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
location = /robots.txt { allow all; log_not_found off; access_log off; }
location = /.well-known/carddav { return 301 /remote.php/dav; }
location = /.well-known/caldav { return 301 /remote.php/dav; }
location ^~ /.well-known/acme-challenge { root /var/www/nextcloud; }
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; }
location / {
try_files $uri $uri/ /index.php$request_uri;
}
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ \.(?:css|js|woff2?|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
access_log off; log_not_found off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
try_files $uri /index.php$request_uri;
access_log off; log_not_found off;
}
}
NGINX
sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/nextcloud
sudo nginx -t && sudo systemctl reload nginx
5) Get a free SSL certificate (Let’s Encrypt)
sudo apt -y install certbot python3-certbot-nginx
sudo certbot --nginx -d cloud.example.com --redirect --agree-tos -m you@yourdomain.com -n
# After HTTPS, you can enable HSTS:
sudo sed -i '/server_name cloud.example.com;/a \ add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;' /etc/nginx/sites-available/nextcloud
sudo nginx -t && sudo systemctl reload nginx
6) Run the NextCloud CLI installer (occ)
sudo -u www-data php /var/www/nextcloud/occ maintenance:install \
--database "mysql" \
--database-name "nextcloud" \
--database-user "ncuser" \
--database-pass "StrongDBPass!" \
--admin-user "admin" \
--admin-pass "AdminPass123!" \
--data-dir "/var/www/nextcloud/data"
# Set trusted domain
sudo -u www-data php /var/www/nextcloud/occ config:system:set trusted_domains 1 --value="cloud.example.com"
7) Enable Redis Caching and Cron
# Configure Redis socket (Ubuntu default is typically /var/run/redis/redis-server.sock)
# Ensure www-data belongs to 'redis' group (we did earlier)
# Add to Nextcloud config.php
sudo -u www-data php -r '
$file="/var/www/nextcloud/config/config.php";
$c = include $file;
$c["memcache.local"] = "\OC\Memcache\APCu";
$c["memcache.locking"] = "\OC\Memcache\Redis";
$c["redis"] = ["host" => "/var/run/redis/redis-server.sock","port" => 0];
file_put_contents($file, "<?php\nreturn ".var_export($c,true).";\n");'
# Set system cron to run every 5 minutes
sudo -u www-data crontab -l 2>/dev/null | { cat; echo "*/5 * * * * php -f /var/www/nextcloud/cron.php"; } | sudo -u www-data crontab -
Visit https://cloud.example.com, log in as admin, and verify there are no critical warnings under Administration > Overview.
Alternative: Install NextCloud with Snap (simplest CLI)
Snap bundles everything for you. It’s easy to maintain, though less flexible than a manual or Docker setup.
sudo apt update && sudo apt -y install snapd
sudo snap install nextcloud
# Create admin user (prompted interactively)
sudo nextcloud.manual-install admin AdminPass123!
# Enable HTTPS (Let’s Encrypt)
sudo nextcloud.enable-https lets-encrypt
# Set domain
sudo nextcloud.occ config:system:set trusted_domains 1 --value="cloud.example.com"
RHEL/CentOS/Rocky Linux quick notes (CLI)
Enable newer PHP via Remi or AppStream, then proceed similarly to Ubuntu. Example:
sudo dnf -y install epel-release
sudo dnf -y install nginx mariadb-server redis
sudo dnf -y module reset php
sudo dnf -y module enable php:8.2
sudo dnf -y install php php-fpm php-mysqlnd php-xml php-gd php-mbstring php-intl php-bcmath php-gmp php-pecl-zip php-pecl-redis php-pecl-apcu
sudo systemctl enable --now nginx mariadb redis php-fpm
# Then follow the same Nextcloud download, Nginx config, certbot, and occ steps.
# If SELinux is enforcing, add proper contexts:
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/nextcloud(/.*)?"
sudo restorecon -Rv /var/www/nextcloud
Post-install Hardening and Performance Tips
Essential NextCloud CLI (occ) Commands
# Run as web user
sudo -u www-data php /var/www/nextcloud/occ status
sudo -u www-data php /var/www/nextcloud/occ user:add alice
sudo -u www-data php /var/www/nextcloud/occ app:list
sudo -u www-data php /var/www/nextcloud/occ app:install contacts calendar
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices
sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off
Troubleshooting From the Command Line
Real-world Guidance From Hosting Experience
For teams and SMBs, reliability matters more than the novelty of the stack. Use Nginx + PHP-FPM with Redis, dedicate fast SSD storage, and keep nightly offsite backups. Monitor disk inode usage, database growth, and PHP-FPM pool saturation to prevent bottlenecks long before users notice slowdowns.
Why host NextCloud With QloudHost
If you’d prefer to skip trial-and-error, QloudHost’s SSD-powered VPS plans are optimized for PHP workloads and include dedicated resources, root access, and optional managed support.

We can pre-harden your Nextcloud stack (Nginx, MariaDB, Redis, HTTPS) and help you scale confidently while you focus on your data, not server plumbing.
FAQs: Install NextCloud From Command Line
Can I install Nextcloud entirely without a web browser?
Yes. Use the occ CLI installer to create the admin account and connect the database. With a proper Nginx/Apache config and HTTPS in place, your instance will be ready. You can also manage users, apps, and maintenance tasks entirely via occ.
What’s the easiest command-line method for beginners?
Snap is the simplest option: snap install nextcloud, then nextcloud.manual-install and nextcloud.enable-https. Docker is the next easiest for reproducibility. The manual Nginx/PHP stack offers the most control and performance for production.
Which database should I use for Nextcloud?
MariaDB and PostgreSQL are both robust. MariaDB is popular and well-documented; PostgreSQL excels at concurrency. Avoid SQLite for multi-user production systems—it’s fine for light testing or personal use but not for scale.
How much RAM and CPU does Nextcloud need?
For small teams (up to ~20 users), 2 vCPU and 4 GB RAM is a practical baseline with Redis caching. Increase resources as user count, apps (Collabora/ONLYOFFICE), and file preview workloads grow.
How do I enable HTTPS for a CLI-only deployment?
Use Certbot. On Ubuntu/Debian with Nginx: certbot –nginx -d cloud.example.com –redirect. Ensure DNS points to your server and ports 80/443 are open. For Snap installs, use nextcloud.enable-https lets-encrypt. For Docker, add a reverse proxy (Traefik or Nginx Proxy Manager) with automated certificates.
Conclusion
With these steps, you can install, secure, and operate Nextcloud completely from the command line—whether you pick Docker, Snap, or a production-ready Nginx + PHP-FPM stack.
Keep your system updated, monitor resources, and you’ll have a fast, private cloud ready for work.


Leave a Comment