Skip to content
Follow
CMS

How to Install Nextcloud with Nginx on Ubuntu 24.04

Richard
Written by
Richard
Jun 4, 2024 Updated Oct 13, 2026 10 min read
Nextcloud featured image
Nextcloud featured image

Nextcloud on Ubuntu 24.04 turns your computer or server into a private file storage hub that replaces public services like Google Drive. This open-source software keeps your documents, photos, and calendars in one place that you control completely, with no monthly subscription fees.

Advertisement

Nginx is the fast web server that runs Nextcloud on your system. Together with MariaDB for the database and PHP-FPM for the PHP code, it gives you full ownership of your data, with access from any device. Before you start, you need a fresh or lightly used Ubuntu 24.04 server, a user account that can run commands with sudo, and a terminal. A domain name pointing at the server is best, but you can also test with the server’s IP address. Plan for at least 2 GB of RAM and enough disk space for the files you want to store.

⚡ Quick Answer

Install Nextcloud with Nginx on Ubuntu 24.04 by running sudo apt update, then sudo apt install nginx, and then sudo apt install mariadb-server for the database. Enable each service with sudo systemctl enable nginx and sudo systemctl enable mariadb so they start after every reboot. Nginx serves the Nextcloud web interface, MariaDB stores your accounts and files, and PHP-FPM runs the code.

Advertisement

Install Nginx HTTP server on Ubuntu

Nginx is the web server that handles your web traffic. In this setup it is the front end: it accepts incoming connections and passes PHP requests to PHP-FPM. You install it from the standard Ubuntu repositories with a few terminal commands, so there is nothing to download by hand.

Follow these steps to install the Nginx web server:

  1. Open the Ubuntu terminal.
  2. Run the commands below. The first refreshes the package list and the second installs Nginx.
  3. Wait for the install to finish. When you get your prompt back without an error, Nginx is installed.
🐧Bash / Shell
sudo apt update
sudo apt install nginx

On Ubuntu, Nginx usually starts as soon as it is installed. Still, you should know the commands to start, stop, and enable the service. The enable command makes Nginx start by itself every time the server boots, so Nextcloud comes back after a reboot.

  1. Run the commands below in the terminal.
  2. Confirm that no error message appears. A silent return to the prompt means each command worked.
🐧Bash / Shell
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx

Next, check that Nginx answers web requests.

Advertisement
  1. Open a web browser on any computer that can reach the server.
  2. Type the server's address in the address bar. On the server itself, use localhost. From another computer, use the server's IP address.
  3. Press Enter.

http://localhost

Nginx default welcome page on Ubuntu 24.04
Nginx default welcome page on Ubuntu 24.04
📝Good to KnowWhen you see "Welcome to nginx!" the Nginx HTTP server has been installed and is serving pages.

If the page does not load from another computer, check that a firewall is not blocking port 80 and that you typed the right IP address.

Additional help on installing Nginx on Ubuntu is in the link below.

How to install Nginx on Ubuntu

Advertisement

Install MariaDB database server on Ubuntu Linux

Nextcloud needs a database to store its user accounts, file records, and settings. This guide uses MariaDB, which is in the standard Ubuntu package repositories, so you can install it with the package manager.

To install and use the MariaDB database server, use the instructions below.

Open the Ubuntu terminal and run the commands below to install the MariaDB database server. The install can take a minute. Type Y if apt asks you to confirm.

🐧Bash / Shell
sudo apt update
sudo apt install mariadb-server

Once MariaDB is installed, use the commands below to stop, start, and enable the service. As with Nginx, enabling it makes MariaDB start automatically when the server boots. Without that, Nextcloud would show a database error after every restart until you started MariaDB by hand.

Advertisement
🐧Bash / Shell
sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to check that the MariaDB database server is installed and working.

🐧Bash / Shell
sudo mariadb

These commands log you onto the MariaDB console and show a message similar to the one below.

💻Code
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 32
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> 

The message tells you that the server is installed and running. If you get a connection error instead, the service is probably not running, so run the start command again and check for errors.

Additional help on installing MariaDB.

Advertisement

Create a Nextcloud database

Nextcloud needs its own database and its own database user. Do not let it use the MariaDB root account. A dedicated user can only touch the Nextcloud data, which limits the damage if something goes wrong. You create both from the MariaDB command prompt, logged in as the root user.

As part of the setup, we will create a database named 'nextclouddb' and a corresponding user account called 'nextclouddbuser.'

Finally, we'll grant the nextclouddbuser full access to the nextclouddb database.

All the database steps above can be done using the commands below:

Advertisement

But first, log on to the MariaDB database server:

🐧Bash / Shell
sudo mariadb

Then run the commands below to complete the steps. Run them one after another at the MariaDB prompt. Each should answer with an OK message.

💻Code
CREATE DATABASE nextclouddb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER nextclouddbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON nextclouddb.* TO nextclouddbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
📝Good to KnowBe sure to replace 'type_your_password_here 'with your own password.

Use a long, unique one, and write it down. You will need the database name, user name, and this password again in the Nextcloud installation wizard at the end of this guide.

Install PHP-FPM on Ubuntu Linux

Nginx cannot run PHP files on its own. PHP-FPM, a processor that handles PHP code for web servers, does that work, and Nginx hands PHP requests to it. Nextcloud also needs several extra PHP modules for things like databases, image handling, and compression. One apt install command installs PHP-FPM and all the modules together. Ubuntu 24.04 ships PHP 8.3 in its repositories, which works with current Nextcloud releases.

Advertisement
🐧Bash / Shell
sudo apt install php-fpm php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-gmp php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-ldap php-imap php-pgsql php-ssh2 php-soap php-zip

Additional help on installing PHP

How to install PHP on Ubuntu Linux

Download Nextcloud files

Now you download the official Nextcloud archive to the server and extract it into the Nginx web root. This puts the actual application code in place. You fetch the archive into a temporary folder with the command line, so you don't clutter your home directory.

Always check the download page for the latest release. Replace the download link in the commands below with the current one so you get the newest version.

First, go to the /tmp/ directory and download the Nextcloud files. After you unzip the file, move the contents into a Nextcloud folder in the Nginx root directory. The commands below do all of this in order.

The final step is to change the ownership and permissions. This lets the Nginx web server read and write the Nextcloud files safely. If the permissions are wrong, the installation wizard will fail or complain that it cannot write to the folder.

💻Code
wget https://download.nextcloud.com/server/releases/latest.zip -P /tmp
sudo unzip /tmp/latest.zip -d /var/www
sudo chown -R www-data:www-data /var/www/nextcloud/

Once the files are in place, configure Nginx to serve the Nextcloud content. You do this with a server block, which is a configuration file that tells Nginx which site to serve and how.

Run the commands below to create an Nginx server block file for Nextcloud. This opens an empty file in a text editor.

🐧Bash / Shell
sudo nano /etc/nginx/sites-available/nextcloud.conf

Then copy and paste the content block below into the file. Check the server name line and make sure it holds your own domain name or the server's IP address. This is the address you will type in the browser later.

🐘PHP
upstream php-handler {
server unix:/var/run/php/php8.3-fpm.sock;
}

server {
listen 80;
listen [::]:80;
server_name nextcloud.example.com;
root /var/www/nextcloud;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

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/.+|oc[ms]-provider/.+|.+/richdocumentscode/proxy).php(?:$|/) {
fastcgi_split_path_info ^(.+?.php)(/.*|)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param modHeadersAvailable true;
# Enable pretty urls
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}

location ~ ^/(?:updater|oc[ms]-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}

# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ .(?:css|js|woff2?|svg|gif|map)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;

# Optional: Don't log access to assets
access_log off;
}

location ~ .(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}

Save the file and close the editor.

The server block must be enabled before Nginx uses it. Follow these steps:

  1. Run the command `sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/` to create a link to the Nextcloud configuration file.
  2. Restart Nginx with `sudo systemctl restart nginx` to apply the change.
  3. Read any output. If Nginx fails to restart, the configuration file most likely has a typo. Open it again and compare it with the content block above.

To undo this later, delete the link in the sites-enabled folder and restart Nginx. The original file in sites-available stays untouched.

🐧Bash / Shell
sudo ln -s /etc/nginx/sites-available/nextcloud.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Setup Let's Encrypt SSL/TLS for Nextcloud

Without encryption, your login details and files cross the network in plain text. A free SSL/TLS certificate from Let's Encrypt encrypts the connection, and it matters most if you reach Nextcloud over the internet. You install the Certbot tool and let it set up Nginx to use HTTPS. Let's Encrypt only issues certificates for a real domain name that points at your server, so you cannot get one for a bare IP address. For a local test on an IP, skip this section and use plain HTTP.

Please read the post below for additional resources on installing and creating Let's Encrypt SSL certificates for Nginx.

How to set up Let's Encrypt SSL certificate for Nginx on Ubuntu Linux

Once you have restarted the Nginx web server, open your browser and go to the server hostname or IP address defined in the Nginx server block. If you set up a certificate, use the https address.

💻Code
http://nextcloud.example.com

A Nextcloud installation wizard page should appear. Fill it in like this:

  1. Type a username and password for the administrator account. Choose a strong password, because this account controls everything.
  2. Enter the database name, the database account name, and the password you created earlier. If the wizard asks for a database host, use localhost.
  3. Click Install.

The install can take a minute or two. If the wizard reports a database connection error, check that you typed the database name, user name, and password exactly as you created them.

Nextcloud setup wizard interface on Ubuntu 24.04
Nextcloud setup wizard interface on Ubuntu 24.04

When the wizard finishes, you land in Nextcloud and your site is ready to use. Sign in with the administrator account you just created. You can now upload files, add users, and install the desktop and mobile apps.

Completed Nextcloud setup wizard on Ubuntu 24.04
Completed Nextcloud setup wizard on Ubuntu 24.04

That should do it!

Conclusion:

  • Nginx provides a secure and efficient platform for hosting Nextcloud on Ubuntu, offering improved resource utilization and enhanced security features.
  • The installation and configuration process includes setting up Nginx, MariaDB, and PHP-FPM, creating a dedicated database for Nextcloud, and adjusting file permissions for secure interactions.
  • Let's Encrypt SSL/TLS certificates can be installed to further enhance the security of the Nextcloud site.
  • Once completed, the Nextcloud site should be accessible immediately, providing a reliable and secure file and data management environment.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *