Skip to content
Follow
CMS

How to install Nextcloud with Nginx on Ubuntu 24.04

Richard
Written by
Richard
Jun 4, 2024 Updated Sep 15, 2026 7 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 secure place that you control completely, without any monthly subscription fees.

Advertisement

Nginx acts as the fast web server that runs Nextcloud smoothly on your system. Setting up this pairing gives you full ownership of your data with direct access from any device.

⚡ Quick Answer

Install Nginx and MariaDB using `apt install nginx mariadb-server`. Create a Nextcloud database with `CREATE DATABASE nextclouddb` and a user. Finally, install PHP-FPM using `apt install php-fpm php-intl php-mysql`.

Advertisement

Install Nginx HTTP server on Ubuntu

You can install Nginx, the web server that handles your web traffic, by running a few standard commands in the terminal. Nginx acts as the front-end server for your Nextcloud Nginx Ubuntu 24.04 setup, accepting incoming connections and passing them to PHP. Open the Ubuntu terminal and run the update and install commands to get the Nginx HTTP server running.

To do that, open the Ubuntu terminal and run the commands below to install the Nginx web server.

sudo apt update
sudo apt install nginx

Once Nginx is installed, the commands below can start, stop, and enable the Nginx web server to start automatically when your server boots up.

sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx

You can test the Nginx web server by opening your web browser and browsing to the server’s localhost or IP address.

Advertisement

http://localhost

Nginx default welcome page on Ubuntu 24.04
Nginx default welcome page on Ubuntu 24.04

When you see "Welcome to nginx!" the Nginx HTTP server has been installed.

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

You need a database server to store all your user data, files, and settings securely. MariaDB manages this information for your Nextcloud Nginx Ubuntu 24.04 installation. You can install the database software directly from the standard Ubuntu package repositories using the terminal 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.

sudo apt update
sudo apt install mariadb-server

Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.

Advertisement
sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to validate and test if the MariaDB database server is installed successfully.

sudo mariadb

Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.

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 successfully.

Additional help on installing MariaDB.

Advertisement

Create a Nextcloud database

You must create a dedicated database and a user account with full permissions so Nextcloud can save data securely. This step connects your new MariaDB server to your Nextcloud Nginx Ubuntu 24.04 system. Log into the MariaDB command prompt as the root user and run the specific SQL queries to set up the database and user credentials.

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:

sudo mariadb

Then run the commands below to complete the steps:

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
⚠️WarningEnsure to replace 'type_your_password_here 'with your password.

Ensure to replace 'type_your_password_here 'with your password.

Install PHP-FPM on Ubuntu Linux

You must install PHP-FPM (a processor that handles PHP code for web servers) along with required PHP modules to run Nextcloud. Nginx cannot process PHP files on its own, so PHP-FPM bridges this gap for your Nextcloud Nginx Ubuntu 24.04 server. Run the apt install command in your terminal to grab all the necessary packages at once.

Advertisement
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

You need to download the official Nextcloud archive directly to your server and extract it into your web root directory. This downloads the actual application code required for your Nextcloud Nginx Ubuntu 24.04 setup. Grab the link for the latest release from the official site and download the tarball into your temporary folder using the command line.

⚠️WarningAlways check the download page for the latest release.

Replace the download link below with the current so you have the latest version.

First, navigate to the /tmp/ directory and download Nextcloud files. After unzipping the file, move the content into the Nextcloud folder in the Nginx root directory.

The final step is to change the permissions. This will allow the Nginx web server to safely interact with the files, ensuring a secure environment for your Nextcloud installation.

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 all the steps are done, configure the Nginx webserver to serve the Nextcloud content.

Run the commands below to create a Nginx server block file for your Nextcloud.

sudo nano /etc/nginx/sites-available/nextcloud.conf

Then, copy and paste the content block below into the Nginx server block.

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.

The Nginx server block, which tells Nginx how to handle Nextcloud traffic, must be enabled. Run the command `sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/` to create a link to the Nginx configuration file for Nextcloud. After linking, restart the Nginx server using `sudo systemctl restart nginx` to apply the changes.

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

You can secure your login details and file transfers by installing a free SSL/TLS certificate (digital security files that encrypt your connection) from Let's Encrypt. This encryption protects your privacy when accessing your Nextcloud Nginx Ubuntu 24.04 server over the internet. Install the certification tool and configure Nginx to force secure HTTPS connections.

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 browse to the server hostname or IP address defined in the Nginx server block.

http://nextcloud.example.com

A Nextcloud installation wizard page should appear. Create an administrator account and password, enter the database name, database account name, and password created above, and click Install.

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

Your Nextcloud site should be ready to use.

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.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
Ubuntu Linux Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04
How to Install Emby Media Server on Ubuntu 24.04
Ubuntu Linux How to Install Emby Media Server on Ubuntu 24.04

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

Leave a Comment

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