If you’re using a monitor and keyboard directly connected to the Raspberry Pi, log in using:
If you're using another computer or phone, the easiest way is to use an SSH app.
raspberrypi.local
pi
/ raspberry
If the above address doesn’t work, skip to Step 7 to find your Raspberry Pi’s IP address.
This makes sure all the software is up to date.
sudo apt update && sudo apt upgrade -y
This installs Apache, MariaDB, and PHP so Nextcloud can run.
sudo apt install apache2 mariadb-server libapache2-mod-php php php-mysql php-gd php-json php-curl php-mbstring php-intl php-imagick php-xml php-zip php-bcmath php-gmp unzip -y
Nextcloud needs a database to store usernames, settings, and file info. We'll use MariaDB, a lightweight version of MySQL.
This command lets you interact with the database server:
sudo mariadb
🔸 If prompted for a password, just press Enter
(there is no password set by default).
Copy and paste the following commands one by one into the MariaDB prompt:
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Here’s what each line does:
nextcloud
nextclouduser
with a password (yourpassword
)nextcloud
databaseMake sure to remember the username and password — you'll need them when setting up Nextcloud in your browser later.
In this step, you'll tell Apache where to find your Nextcloud files and how to serve them to browsers.
This file will define how your site is accessed:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Paste the following into the file:
<VirtualHost *:80>
DocumentRoot /var/www/html/nextcloud
ServerName your-pi-ip
<Directory /var/www/html/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
</Directory>
</VirtualHost>
🔸 Replace your-pi-ip
with your Raspberry Pi’s IP address or your No-IP domain name (e.g., mypihost.ddns.net
).
These commands activate your config and enable necessary Apache features:
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
What each command does:
a2ensite
: Activates your new site configa2enmod
: Turns on key Apache features like URL rewriting and header handlingThis applies the changes:
sudo systemctl restart apache2
sudo apache2ctl configtest
If it says Syntax OK
, you're good to go.sudo systemctl status apache2
hostname -I
Use the IP to access your Pi in a browser.
Open a browser and go to:
http://192.168.x.x/nextcloud
Replace IP with yours. Use:
sudo systemctl enable apache2
sudo systemctl enable mariadb
If you want to use an external hard drive for storing Nextcloud files, follow these steps to mount it permanently.
Connect your USB hard drive to the Raspberry Pi.
Run this command to list all storage devices:
lsblk
Look for something like /dev/sda1
with a size that matches your drive. Make note of the name (e.g., sda1
).
This is the folder where the drive will be accessed from:
sudo mkdir /media/nextcloud-hdd
sudo mount /dev/sda1 /media/nextcloud-hdd
This temporarily mounts the drive. But it won’t survive a reboot—so next we’ll set up auto-mounting.
The UUID is a unique ID that doesn’t change, even if the drive’s name changes:
sudo blkid
Find the line for /dev/sda1
(or your device) and copy the UUID value.
This file controls what gets mounted at boot:
sudo nano /etc/fstab
At the bottom, add a new line using the UUID you copied:
UUID=xxxx-xxxx /media/nextcloud-hdd ext4 defaults,nofail 0 2
⚠️ Replace xxxx-xxxx
with your actual UUID. If your drive is NTFS or exFAT, change ext4
to ntfs
or exfat
.
Make sure your changes work:
sudo mount -a
If there are no errors, your drive is now permanently mounted!
You can check if it worked by running:
df -h
This shows mounted drives and their available space.
To allow Nextcloud to read and write files to your mounted HDD, you need to give proper permissions to the web server (Apache).
This gives full control of the drive to Apache's default user www-data
:
sudo chown -R www-data:www-data /media/nextcloud-hdd
What it does: This command recursively (-R
) changes the owner of all files and folders inside the HDD mount point to the web server user.
This ensures that the Apache server can read, write, and execute within the mounted folder:
sudo chmod -R 750 /media/nextcloud-hdd
What it means:
7
= read, write, execute (for owner: www-data)5
= read and execute (for group)0
= no access (for others)This keeps the drive secure while letting Nextcloud function properly.
If you want Nextcloud to store user files directly on the HDD, create a dedicated folder:
sudo mkdir /media/nextcloud-hdd/data
sudo chown -R www-data:www-data /media/nextcloud-hdd/data
Then, during the browser setup in Step 7, set the Data Folder as:
/media/nextcloud-hdd/data
Your HDD is now ready for Nextcloud file storage with proper permissions and access control.
HTTPS encrypts your connection, making it safer—especially if you plan to access your Nextcloud over the internet.
This tool automatically sets up a free SSL certificate from Let's Encrypt.
sudo apt install certbot python3-certbot-apache -y
This command will configure your Apache web server to use HTTPS:
sudo certbot --apache
When you run it:
mypihost.ddns.net
)If successful, you’ll see a confirmation and your site will now be accessible at:
https://yourname.ddns.net/nextcloud
Certbot sets up automatic renewal by default. You can test it with:
sudo certbot renew --dry-run
If your router or firewall blocks port 80 or 443, this will fail. Make sure those ports are forwarded to your Raspberry Pi’s IP address.
This installs the Nextcloud files into your web directory.
cd /var/www/html
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo chown -R www-data:www-data nextcloud
sudo chmod -R 755 nextcloud
This lets you access your Raspberry Pi remotely using a hostname like yourname.ddns.net
.
mypihost.ddns.net
cd ~
sudo apt install git build-essential -y
git clone https://github.com/no-ip/noip-ddns
cd noip-ddns
make
sudo make install
During setup, enter your No-IP email, password, and hostname.
sudo /usr/local/bin/noip2
sudo /usr/local/bin/noip2 -S
sudo nano /etc/systemd/system/noip2.service
Paste this:
[Unit]
Description=No-IP Dynamic DNS Update Service
After=network.target
[Service]
ExecStart=/usr/local/bin/noip2
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl enable noip2
sudo systemctl start noip2
Now go to:
http://yourname.ddns.net/nextcloud
This will redirect to your Raspberry Pi, even if your home IP changes.