Install NextCloud on Ubuntu 26.04 (Nginx + PostgreSQL + PHP8.5)
Last Updated: June 10th, 2026
This tutorial will show you how to install NextCloud on Ubuntu 26.04 LTS with the Nginx web server, PostgreSQL database, and PHP8.5.
What’s NextCloud?
NextCloud is a free open-source self-hosted cloud storage solution. It’s functionally similar to Dropbox. Proprietary cloud storage solutions are convenient, but at a price: they can be used to collect personal data because your files are stored on third-party hardware. If you are worried about privacy, you can switch to NextCloud, which you can install on your private home server or on a virtual private server (VPS). You can upload your files to your server via NextCloud and then sync those files to your desktop computer, laptop, or smartphone, giving you full control of your data.
NextCloud Features
- Free and open-source
- End-to-end encryption, meaning files can be encrypted on client devices before being uploaded to the server.
- Can be integrated with an online office suite (Collabora Online, OnlyOffice) so you can create and edit your documents directly from NextCloud.
- The app store contains hundreds of apps to extend functionality (calendar, contacts, note-taking, video conferencing, etc.).
- The sync client is available on Linux, macOS, Windows, iOS, and Android.
Requirements
You can install NextCloud on your home server or a VPS (virtual private server). You also need a domain name so you can enable HTTPS to encrypt HTTP traffic. While NextCloud can be installed without a domain name, using it without encryption exposes your connection to potential snooping. It is highly recommended to use a domain name to utilize the platform securely.
Step 1: Download NextCloud on Ubuntu 26.04
Log into your Ubuntu 26.04 server. Then download the NextCloud zip archive onto your server. The latest stable version is 24.0.0 at the time of this writing. Go to the official NextCloud installation page to see the latest version.
You can run the following command to download it on your server:
wget https://download.nextcloud.com/server/releases/nextcloud-24.0.0.zip
If a new version comes out, simply replace 24.0.0 with the new version number in the URL. Next, install the unzip utility:
sudo apt install unzip
Create the /var/www/ directory and extract the archive file:
sudo mkdir -p /var/www/
sudo unzip nextcloud-24.0.0.zip -d /var/www/
The -d option specifies the target directory. NextCloud web files will be extracted to /var/www/nextcloud/.
Step 2: Create a Database and User for Nextcloud in PostgreSQL
Nextcloud is compatible with PostgreSQL, MariaDB/MySQL, and SQLite. Nextcloud is highly performant with PostgreSQL, which we will use in this tutorial. Run the following command to install PostgreSQL:
sudo apt install -y postgresql postgresql-contrib
Log into PostgreSQL as the postgres user:
sudo -u postgres psql
Create the nextcloud database:
CREATE DATABASE nextcloud TEMPLATE template0 ENCODING 'UNICODE';
Create a user (nextclouduser) and set a secure password:
CREATE USER nextclouduser WITH PASSWORD 'nextclouduser_password';
Grant permissions to the database user:
ALTER DATABASE nextcloud OWNER TO nextclouduser;
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextclouduser;
Press Ctrl+D to log out of the PostgreSQL console.
Then run the following command to test if you can log in to PostgreSQL as the new user:
psql -h 127.0.0.1 -d nextcloud -U nextclouduser -W
Press Ctrl+D to log out.
Step 3: Create an Nginx Virtual Host for Nextcloud
Install the Nginx web server:
sudo apt install nginx
Create a nextcloud.conf file in the /etc/nginx/conf.d/ directory using a command-line text editor like Nano:
sudo nano /etc/nginx/conf.d/nextcloud.conf
Copy and paste the following configuration into the file. Replace nextcloud.example.com with your own preferred sub-domain. Don't forget to create a DNS A record for this sub-domain in your DNS zone editor.
server {
listen 80;
listen [::]:80;
server_name nextcloud.example.com;
# Add headers to serve security related headers
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
add_header X-Frame-Options "SAMEORIGIN";
# Path to the root of your installation
root /var/www/nextcloud/;
access_log /var/log/nginx/nextcloud.access;
error_log /var/log/nginx/nextcloud.error;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
location ~ /.well-known/acme-challenge {
allow all;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
fastcgi_buffer_size 32k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
# Disable gzip to avoid the removal of the ETag header
gzip off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
try_files $fastcgi_script_name =404;
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/php8.5-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~* \.(?:css|js|mjs|wasm)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
access_log off;
}
include mime.types;
types {
text/javascript mjs;
application/wasm wasm;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
access_log off;
}
}
Save and close the file.
Change the owner of this directory to www-data so that Nginx can write to it:
sudo chown www-data:www-data /var/www/nextcloud/ -R
Test the Nginx configuration:
sudo nginx -t
If the test is successful, reload Nginx:
sudo systemctl reload nginx
Step 4: Install and Enable PHP Modules
The latest version of Nextcloud is compatible with PHP8.5. Run the following commands to install required or recommended PHP modules:
sudo apt install imagemagick php-imagick php8.5-common php8.5-pgsql php8.5-fpm php8.5-gd php8.5-curl php8.5-imagick php8.5-zip php8.5-xml php8.5-mbstring php8.5-bz2 php8.5-intl php8.5-bcmath php8.5-gmp php8.5-redis
Step 5: Enable HTTPS
If the web page can’t load, you probably need to open ports 80 and 443 in the firewall:
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
We can obtain a free TLS certificate from Let’s Encrypt. Install the Let’s Encrypt client (certbot):
sudo apt install certbot python3-certbot-nginx
Run the following command to obtain and automatically configure a free TLS certificate using the Nginx plugin:
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d nextcloud.example.com
If you want to manually ensure the HSTS header is enabled, edit the configuration file:
sudo nano /etc/nginx/conf.d/nextcloud.conf
Add the following line inside the SSL server block:
add_header Strict-Transport-Security "max-age=31536000" always;
You can also enable HTTP2 protocol by modifying the listen directives:
listen [::]:443 ssl http2;
listen 443 ssl http2;
Save, close, test, and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Step 6: Launch the Web-based Setup Wizard
Access your Nextcloud web install wizard securely via HTTPS:
https://nextcloud.example.com
To complete the installation, perform the following in the wizard:
- Create an admin account
- Enter the path of the Nextcloud data folder
- Enter the database details created in Step 2 (use
localhost:5432as host address)
For security, it’s best to place the data directory outside of the Nextcloud webroot directory. Create a directory separate from the installation path:
sudo mkdir /var/www/nextcloud-data
sudo chown www-data:www-data /var/www/nextcloud-data -R
Note: In recent versions of Ubuntu, php-fpm systemd unit files utilize strong sandboxing defaults that restrict writing to directories like /usr and /etc. Ensure your data directory is not situated under those paths.
Post-Installation Configurations
Set up Email Notifications
Go to Settings -> Personal Info to set your administrative email. Then navigate to Settings -> Basic settings to adjust the email server settings. Choose your preferred send mode (e.g., sendmail or SMTP) to handle system transactional emails like password resets.
Reset Password From Command Line
If you lose your administrative credentials, reset the password with the following command (replace nextcloud_username with your username):
sudo -u www-data php /var/www/nextcloud/occ user:resetpassword nextcloud_username
How to Move the Data Directory
If you need to move your data directory to another location (e.g., an external drive mount point at /media/storage/nextcloud-data/):
sudo mkdir -p /media/storage/nextcloud-data/
sudo cp /var/www/nextcloud-data/* /media/storage/nextcloud-data/ -R
sudo cp /var/www/nextcloud-data/.ocdata /media/storage/nextcloud-data/
sudo chown www-data:www-data /media/storage/nextcloud-data/ -R
Then update the path inside your configuration file:
sudo nano /var/www/nextcloud/config/config.php
Update the datadirectory parameter:
'datadirectory' => '/media/storage/nextcloud-data',
Step 7: Increase PHP Memory Limit
NextCloud recommends 512MB for optimal performance. Run the following command to update your PHP ini file:
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/8.5/fpm/php.ini
sudo systemctl reload php8.5-fpm
Step 8: Set Up PHP System Environment Variables
Uncomment the clear_env setting to ensure system environments pass accurately:
sudo sed -i 's/;clear_env = no/clear_env = no/g' /etc/php/8.5/fpm/pool.d/www.conf
sudo systemctl reload php8.5-fpm
Step 9: Increase Upload File Size Limit
Update both Nginx and PHP to handle larger uploads (e.g., 1GB):
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 1024M/g' /etc/php/8.5/fpm/php.ini
sudo systemctl restart php8.5-fpm
Step 10: Configure Redis Cache for NextCloud
Install Redis server and its PHP module interface:
sudo apt install redis-server php8.5-redis
Ensure Redis auto-starts on system boot:
sudo systemctl enable --now redis-server
Edit the Nextcloud configuration file to configure caching:
sudo nano /var/www/nextcloud/config/config.php
Add the following configurations right above the closing ); line:
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
'host' => 'localhost',
'port' => 6379,
),
Restart the services:
sudo systemctl restart nginx php8.5-fpm
Optimizing Database Tables (Missing Indexes & Big Int Conversion)
If your NextCloud overview panel warns about missing indexes or Big Int conversions, change to your webroot and run the optimization commands:
cd /var/www/nextcloud/
sudo -u www-data php occ db:add-missing-indices
For Big Int conversion, turn on maintenance mode first:
sudo -u www-data php occ maintenance:mode --on
sudo -u www-data php occ db:convert-filecache-bigint
sudo -u www-data php occ maintenance:mode --off
Using System Cron for Background Jobs
Switch your Nextcloud background settings from AJAX to Cron, then edit the crontab for the www-data user:
sudo -u www-data crontab -e
Append the following line to execute background jobs every 5 minutes:
*/5 * * * * php8.5 -f /var/www/nextcloud/cron.php
Troubleshooting Tips
If you encounter configuration or runtime errors, consult the following server log paths:
- Nginx Error Log:
/var/log/nginx/error.log - Nextcloud Nginx Host Error Log:
/var/log/nginx/nextcloud.error - Nextcloud Application Logs:
/var/www/nextcloud/data/nextcloud.log