Install NextCloud on Ubuntu 22.04 (Nginx + PostgreSQL + PHP8)
This tutorial will be showing you how to install NextCloud on Ubuntu 22.04 LTS with Nginx web server.
What’s NextCloud?
NextCloud is a free open-source self-hosted cloud storage solution. It’s functionally similar to Dropbox. Proprietary cloud storage solutions (Dropbox, Google Drive, etc) are convenient, but at a price: they can be used to collect personal data because your files are stored on their computers. 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. This way you have 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, so even if someone steals your server, they can not read your files.
- Can be integrated with an online office suite (Collobora Online, OnlyOffice) so you can create and edit your doc, ppt, xls files directly from NextCloud.
- The app store contains hundreds of apps to extend functionality (like calendar app, contacts app, note-taking app, video conferencing app, 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 later on your will be able to enable HTTPS to encrypt the HTTP traffic. I registered my domain name from NameCheap because the price is low and they give whois privacy protection free for life. Nextcloud can be installed without a domain name, but it really doesn’t make sense if you don’t encrypt the HTTP connection to prevent snooping. I recommend buying a domain name if you really want to tinker with server software and use them to the fullest potential.
Now let’s install NextCloud.
Step 1: Download NextCloud on Ubuntu 22.04
Log into your Ubuntu 22.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 https://nextcloud.com/install and click download for server
-> Archive file
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
You can always use the above URL format to download NextCloud. If a new version comes out, simply replace 24.0.0
with the new version number.
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 much faster with PostgreSQL, so we will use PostgreSQL in this tutorial. If you previously install Nextcloud with MariaDB/MySQL database server, you can also migrate to PostgreSQL.
Run the following command to install Postgresql. (PostgreSQL and MariaDB can run on the same server. You don’t need to remove MariaDB.)
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 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 nextclouduser
.
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 Nginx web server.
sudo apt install nginx
Create a nextcloud.conf
file in /etc/nginx/conf.d/
directory, with a command-line text editor like Nano.
sudo nano /etc/nginx/conf.d/nextcloud.conf
Copy and paste the following text into the file. Replace nextcloud.example.com
with your own preferred sub-domain. Don’t forget to create DNS A record for this sub-domain in your DNS zone editor. If you don’t have a real domain name, I recommend going to NameCheap to buy one. The price is low and they give whois privacy protection free for life.
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;
#I found this header is needed on Ubuntu, but not on Arch Linux.
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;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
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;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed 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;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
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;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
Save and close the file. (To save a file in Nano text editor, press Ctrl+O
, then press Enter
to confirm. To exit, press Ctrl+X
.)
We need to change the owner of this directory to www-data
so that the web server (Nginx) can write to this directory.
sudo chown www-data:www-data /var/www/nextcloud/ -R
Then test the Nginx configuration.
sudo nginx -t
If the test is successful, reload Nginx for the changes to take effect.
sudo systemctl reload nginx
Step 4: Install and Enable PHP Modules
The latest version of Nextcloud is compatible with PHP8.1. Run the following commands to install PHP modules required or recommended by NextCloud.
sudo apt install imagemagick php-imagick php8.1-common php8.1-pgsql php8.1-fpm php8.1-gd php8.1-curl php8.1-imagick php8.1-zip php8.1-xml php8.1-mbstring php8.1-bz2 php8.1-intl php8.1-bcmath php8.1-gmp
Step 5: Enable HTTPS
Now you can access the Nextcloud web install wizard in your web browser by entering the domain name for your Nextcloud installation.
nextcloud.example.com
If the web page can’t load, you probably need to open port 80 in the firewall.
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
And port 443 as well.
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
Before entering any sensitive information, we should enable secure HTTPS connection on Nextcloud. We can obtain a free TLS certificate from Let’s Encrypt. Install Let’s Encrypt client (certbot) from Ubuntu 22.04 repository.
sudo apt install certbot python3-certbot-nginx
Python3-certbot-nginx
is the Nginx plugin. Next, run the following command to obtain a free TLS certificate using the Nginx plugin.
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d nextcloud.example.com
Where:
--nginx
: Use the Nginx authenticator and installer--agree-tos
: Agree to Let’s Encrypt terms of service--redirect:
Enforce HTTPS by adding 301 redirect.--hsts
: Enable HTTP Strict Transport Security. This defends against SSL/TLS stripping attack.--staple-ocsp
: Enable OCSP Stapling.--email
: Email used for registration and recovery contact.-d
flag is followed by a list of domain names, separated by comma. You can add up to 100 domain names.
You will be asked if you want to receive emails from EFF(Electronic Frontier Foundation). After choosing Y or N, your TLS certificate will be automatically obtained and configured for you, which is indicated by the message below.
I found that Certbot may not be able to add HSTS header in the Nginx config file for Nextcloud. If you would like to enable HSTS (HTTP Strict Transport Security), then edit the file.
sudo nano /etc/nginx/conf.d/nextcloud.conf
We can then add the following line in the SSL server block to enable HSTS header. (If it’s already there, then your configuration are fine.)
add_header Strict-Transport-Security "max-age=31536000" always;
Also, you can enable HTTP2 protocol by adding the option http2
, which will speed up webpage loading.
listen [::]:443 ssl http2; # managed by Certbot listen 443 ssl http2; # managed by Certbot
Like below.
Save and close the file. Then text Nginx configurations.
sudo nginx -t
If the test is successful, reload Nginx for the change to take effect.
sudo systemctl reload nginx
The above configuration will get A+ score on SSL test.
Step 6: Launch the Web-based Setup Wizard in your Web Browser
Now you can access the Nextcloud web install wizard using HTTPS connection.
https://nextcloud.example.com
To complete the installation, you need to
- Create an admin account
- Enter the path of the Nextcloud data folder
- Enter database details you created in step 2. You can use
localhost:5432
as host address, as PostgreSQL listens on port 5432.
The data folder is where users’ files are stored. For security, it’s best to place the data directory outside of Nextcloud webroot directory. So instead of storing users’ files under /var/www/nextcloud/data/
, we can change it to /var/www/nextcloud-data. which can be created with the following command:
sudo mkdir /var/www/nextcloud-data
Then make sure Nginx user (www-data
) has write permission to the data directory.
sudo chown www-data:www-data /var/www/nextcloud-data -R
Click the Install
button, and in a few seconds you will see the Web interface of Nextcloud. Congrats! You can start using it as your private cloud storage.
How to Set up NextCloud Email Notification
If your NextCloud instance will be used by more than one person, it’s important that your NextCloud server can send transactional emails, such as password-resetting email. First, you should set an email address for your own account. Go to Settings
-> Personal Info
and set an email address for your account.
Then go to Settings -> Basic settings. You will find the email server settings. There are two send modes: sendmail
and smtp
. Choose the sendmail
mode.
Next, follow the tutorial linked below to set up SMTP relay on Ubuntu.
Once the SMTP relay is configured, click the send email button in Nextcloud to test if email is working.
How to Reset Nextcloud User Password From Command Line
If you lost your admin account password, and you didn’t set up email delivery in Nextcloud, then you need to reset the password by running the following command on your server. Replace nextcloud_username
with your real username.
sudo -u www-data php /var/www/nextcloud/occ user:resetpassword nextcloud_username
There are also other commands you might find useful. List available commands with:
sudo -u www-data php /var/www/nextcloud/occ
or
sudo -u www-data php /var/www/nextcloud/console.php
How to Move the Data Directory
In case you need to move the NextCloud data directory, there are 4 steps to accomplish this. First, you need to use the cp
command to copy the data directory to the new directory. For example, the mount point of my external hard drive is /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731
. I create the new data directory on the external hard drive.
sudo mkdir /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/
Then I copy the original data directory to the new data directory. -R
flag means the copy operation is recursive.
sudo cp /var/www/nextcloud-data/* /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/ -R
You also need to copy the .ocdata
file.
sudo cp /var/www/nextcloud-data/.ocdata /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/
Next, you need to set www-data
(Nginx user) as the owner.
sudo chown www-data:www-data /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731/nextcloud-data/ -R
Lastly, you need to edit the config.php
file.
sudo nano /var/www/nextcloud/config/config.php
Find the following line and change the value of datadirectory
.
'datadirectory' => '/var/www/nextcloud-data',
Save and close the file. Reload NextCloud web page and you are done.
Step 7: Increase PHP Memory Limit
The default PHP memory limit is 128MB. NextCloud recommends 512MB for better performance. To change PHP memory limit, edit the php.ini file.
sudo nano /etc/php/8.1/fpm/php.ini
Find the following line. (line 409)
memory_limit = 128M
Change the value.
memory_limit = 512M
Save and close the file. Alternatively, you can run the following command to change the value without manually opening the file.
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/8.1/fpm/php.ini
Then reload PHP-FPM service for the changes to take effect.
sudo systemctl reload php8.1-fpm
Step 8: Set Up PHP to Properly Query System Environment Variables
Edit the www.conf file.
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
Find the following line (line 396).
;clear_env = no
Remove the semicolon to uncomment this line.
clear_env = no
Save and close the file. Alternatively, you can run the following command to uncomment this line without manually opening the file.
sudo sed -i 's/;clear_env = no/clear_env = no/g' /etc/php/8.1/fpm/pool.d/www.conf
Then reload PHP-FPM service for the changes to take effect.
sudo systemctl reload php8.1-fpm
Step 9: Increase Upload File Size Limit
The default maximum upload file size limit set by Nginx is 1MB. To allow uploading large files to your NextCloud server, edit the Nginx configuration file for NextCloud.
sudo nano /etc/nginx/conf.d/nextcloud.conf
We have already set the maximum file size in this file, as indicated by
client_max_body_size 512M;
You can change it if you prefer, like 1G.
client_max_body_size 1024M;
Save and close the file. Then reload Nginx for the changes to take effect.
sudo systemctl reload nginx
PHP also sets a limit of upload file size. The default maximum file size for uploading is 2MB. To increase the upload size limit, edit the PHP configuration file.
sudo nano /etc/php/8.1/fpm/php.ini
Find the following line (line 846).
upload_max_filesize = 2M
Change the value like below:
upload_max_filesize = 1024M
Save and close the file. Alternatively, you can run the following command to change the value without manually opening the file.
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 1024M/g' /etc/php/8.1/fpm/php.ini
Then restart PHP-FPM.
sudo systemctl restart php8.1-fpm
Step 10: Configure Redis Cache for NextCloud
If you go to your NextCloud settings -> overview page, you might see the following warning:
No memory cache has been configured. To enhance your performance please configure a memcache if available.
We will enable memory caching for nextCloud by using Redis. Run the following command to install Redis server from Ubuntu repository.
sudo apt install redis-server
You can check the version with:
redis-server -v
Sample output:
Redis server v=6.0.16 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=a3fdef44459b3ad6
Now we can check if redis server is running.
systemctl status redis
Hint: If the above command didn’t quit immediately, you can press the Q key to gain back control of the terminal.
From the above screenshot, we can see that it’s running and auto-start is enabled. If for any reason it’s not running, execute the following command:
sudo systemctl start redis-server
And if auto-start at boot time is not enabled, you can use the following command to enable it:
sudo systemctl enable redis-server
In order to configure Redis as a cache for nextCloud, we need to install the PHP extension for interfacing with Redis.
sudo apt install php8.1-redis
Check if the extension is enabled.
php8.1 --ri redis
We can see that Redis extension is enabled. If it’s not enabled, run the following command:
sudo phpenmod redis
Next, edit nextCloud configuration file.
sudo nano /var/www/nextcloud/config/config.php
Add the following lines above the ending );
line.
'memcache.distributed' => '\OC\Memcache\Redis', 'memcache.local' => '\OC\Memcache\Redis', 'memcache.locking' => '\OC\Memcache\Redis', 'redis' => array( 'host' => 'localhost', 'port' => 6379, ),
Save and close the file. Then restart Nginx and PHP-FPM.
sudo systemctl restart nginx php8.1-fpm
Now go to NextCloud settings -> overview page again and refresh the web page, the warning about memory caching should be gone.
Adding Missing Indexes
If you see the following message in the NextCloud Settings -> Overview page,
The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically.
Then you need to manually add those indexes. Change to the Nextcloud webroot directory.
cd /var/www/nextcloud/
Run the following command to add indexes to the Nextcloud database.
sudo -u www-data php occ db:add-missing-indices
Now if you refresh the NextCloud Settings -> Overview page, the warning about missing indexes should be gone.
Conversion to Big Int
If you see the following message in the NextCloud Settings -> Overview page,
Some columns in the database are missing a conversion to big int. Due to the fact that changing column types on big tables could take some time they were not changed automatically.
Then you need to manually change the column type. Change to the Nextcloud webroot directory.
cd /var/www/nextcloud/
Change your Nextcloud into maintenance mode to prevent users from logging in and making changes.
sudo -u www-data php occ maintenance:mode --on
Then run the following command to change the column type.
sudo -u www-data php occ db:convert-filecache-bigint
Once it’s done, switch off the maintenance mode.
sudo -u www-data php occ maintenance:mode --off
Now if you refresh the NextCloud Settings -> Overview page, the warning about big int should be gone.
How to Install NextCloud Client on Ubuntu 22.04 Desktop
Run the following commands on Ubuntu 22.04 desktop to install the client from the default repository.
sudo apt install nextcloud-client
NextCloud Client on Ubuntu 22.04
Client software for macOS, Windows, Android and iOS can be found on the Nextcloud download page.
How to Enable OnlyOffice/Collabora Online
By default, Nextcloud ships with support for OnlyOffice, which an online office suite that allows you to edit your doc, ppt, xls files directly from NextCloud. We only need to install an app to use this feature. Go to Nextcloud Apps
-> Office & Text
. Find and enable the community document server
app.
Now when you click the add button (+) in Nextcloud, you will be able to create Word, spreadsheet and presentation documents right from your Nextcloud server.
However, I found this app isn’t very reliable. And the community edition allows only 20 users at most. You need to purchase an enterprise edition if you have more than 20 users. There’s another open-source LibreOffice-based online office suite called Collabora Online that has the same functionality, but without the limitation on the number of users. You can read the following article to integrate it with Nextcloud.
Adding Local DNS Entry
It’s recommended to edit the /etc/hosts
file on your Nextcloud server and add the following entry, so that Nextcloud itself won’t have to query the public DNS, which can improve the overall stability. If your Nextcloud server can’t resolve the nextcloud.example.com
hostname, then you may encounter a 504 gateway time out error.
127.0.0.1 localhost nextcloud.example.com
An IP address in the /etc/hosts
file can have multiple hostnames, so if you have other applications installed on the same box, you can also add other hostnames or sub-domains on the same line like this:
127.0.0.1 localhost focal ubuntu nextcloud.example.com collabora.example.com
Using Cron to Run Background Jobs
By default, Nextcloud uses AJAX to execute one task with each page load. You can use the more efficient system cron service to run background jobs. Go to Nextcloud Settings -> Basic Settings and select Cron.
Next, edit the www-data
user’s crontab file.
sudo -u www-data crontab -e
Add the following line in this file, so the cron job will run every 5 minutes.
*/5 * * * * php8.1 -f /var/www/nextcloud/cron.php
Save and close the file.
(Optional) Prevent Malicious Login Attempts
If your computer has a static public IP address, you can create an IP whitelist in the Nginx config file.
sudo nano /etc/nginx/conf.d/nextcloud.conf
Add the following lines in the SSL server block to restrict access to the /login
URL, so only your IP address can access this URL. Replace 78.56.34.12 with your own IP address.
location ~* ^/login{
try_files $uri /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
allow 78.56.34.12;
deny all;
}
Save and close the file. Then test Nginx configuration.
sudo nginx -t
If the test is successful, reload Nginx for the changes to take effect.
sudo systemctl reload nginx
If you don’t have a static IP address on your home network, you can set up a VPN server in a data center.
Troubleshooting Tips
If you encounter errors, you can check one of the following log files to find out what’s wrong.
- Nginx error log:
/var/log/nginx/error.log
- Nginx error log for the Nextcloud virtual host:
/var/log/nginx/nextcloud.error
- Nextcloud application log:
/var/www/nextcloud/data/nextcloud.log
For example, I once had an “Internal Server Error
” on my Nextcloud instance and the /var/log/nginx/nextcloud.error
file told me that
FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught OC\HintException: [0]: Memcache \OC\Memcache\Redis not available for local cache (Is the matching PHP module installed and enabled?)
It turned out that because I used the ppa:ondrej/php PPA on my Ubuntu server, I also need to install php8.0-redis
in addition to the php-redis
package.
Upgrading Nextcloud
It’s important to keep your Nextcloud server up to date with the latest security and bug fixes. Read the tutorial below to learn how to upgrade Nextcloud.
Wrapping Up
I hope this tutorial helped you install NextCloud on Ubuntu 22.04 server with Nginx. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂
Hello, great tutorial. How can I migrate Nextcloud database from MariaDB to PostgreSQL?
Thanks
To switch from MariaDB to PostgreSQL, follow these steps.
Hint: If you use PHP7.4 with Nextcloud, simply change
php8.1
tophp7.4
. If your Nextcloud is installed under/usr/share/nginx/nextcloud/
, then change/var/www/nextcloud/occ
to/usr/share/nginx/nextcloud/occ
.Step 1: Install Postgresql
PostgreSQL and MariaDB can run on the same server. You don’t need to remove MariaDB.
Step 2: Install PostgreSQL PHP module
Step 3: Create Database for NextCloud in PostgreSQL
Log into PostgreSQL as the postgres user.
Create the nextcloud database
Create a user.
Grant permissions to the database user.
Press
Ctrl+D
to log out of PostgreSQL console.Run the following command to test if you can log in to PostgreSQL as nextclouduser.
Step 4: Start the Migration.
Once it’s done, go to Nextcloud web interface
settings
->System
, scroll down and you will find that Nextcloud is now using PostgreSQL.Hello Xiao,
Greetings from TekConnect!
Kindly share with me your official email address and WhatsApp contact.
I will be very grateful to hear from you.
Thank you.
Yours sincerely,
Isaac
Thank you Xiao Guoan! Worked perfectly. I exception for me was Step 4 double quotes did not work for the password. I used single quotes as shown.
Your site is one of my main GOTO sites because your instructions WORK!
From my WebUI -> Settings > System
Hello, how to switch from Apache/mariaDB to Nginx/PostgreSQL?
Thanks
You can use the same instructions above to migrate from MariaDB to PostgreSQL. Apache will work with PostgreSQL.
If you also want to switch from Apache to Nginx, then disable Apache.
Next, follow step 3, 4 and 5 in this tutorial to set up Nginx.
Hi, I just tried to switch from MariaDB & Apache2 to Nginx & PostgreSQL but now I get: 504 Gateway Time-out nginx/1.18.0 (Ubuntu). If if enter my public IP, I get the famous Apache2 Ubuntu Default Page it works.
Is there someone that could hepl me?
Sorry I solved the issue, it was also related to richdocuments. I used the command that you wrote on comments.
Great guide as always. I love nginx and somehow they keep using apache. Old habits?
Thanks Xiao
So i installed nextcloud with nginx and gave the required permissions and nextcloud login page appeared when i accessed ‘myip/nextcloud’ but when i clicked ‘Finish Setup’ it gave me a 404 error. Now when accessing ‘myip/nextcloud’ it redirects me to ‘myip/nextcloud/index.php/apps/files’ which gives me a 404 error. I dont have any idea whats wrong here? Can someone help me here?
Hi,
The Nginx configuration in this tutorial is for NextCloud on a sub-domain (nextcloud.example.com), not for a sub-directory (example.com/nextcloud). You can always check out Nginx error log to see what’s wrong.
PostgreSQL is indeed much faster than MariaDB! Thanks for the migration instructions.
Will these instructions work on Ubuntu 20.04 Server?
If you want to migrate from MariaDB to PostgreSQL on Ubuntu 20.04, simply change
php8.1
tophp7.4
.If your Nextcloud is installed under
/usr/share/nginx/nextcloud/
, then change/var/www/nextcloud/occ
to/usr/share/nginx/nextcloud/occ
.Why nginx over apache?
For me, it’s because Nginx embraces new technology much earlier than Apache. For example,
Nginx supports the HTTP2 protocol starting with version 1.9.5, which was released in September 2015.
Apache supports HTTP2 protocol starting with version 2.4.26, which was released in June 2017.
Below is how to fix the Your web server is not properly set up to resolve
/.well-known/webfinger
/.well-known/nodeinfo
error if using NGiNX since everything else I could find was for Apache/HTTPD
Any idea? Thank you..
You don’t need to worry about this warning if you don’t use the social app in Nextcloud. This app is currently in alpha and not compatible with Nextcloud 23/24.
Great instructions, thank you very much for putting it together, I was able to install nextcloud without any issues. I do have some questions, when I go to overview, I do see the following warnings. I checked their documentation but is very vague. Can you please guide me on how to fix the following warnings?
1. You don’t need to worry about the
webfinger
andnodeinfo
warning if you don’t use the social app in Nextcloud. This app is currently in alpha and not compatible with Nextcloud 23/24.2. To configure email server in Nextcloud, go to
Settings
->Personal Info
and set an email address for your account.Then go to Settings -> Basic settings. You will find the email server settings. There are two send modes:
sendmail
andsmtp
. Choose thesendmail
mode.Next, follow the tutorial linked below to set up SMTP relay on Ubuntu.
Once the SMTP relay is configured, click the send email button in Nextcloud to test if email sending is working.
3. To set a default phone region, edit your Nextcloud config.php file (/var/www/nextcloud/config/config.php), add a line in this file:
Save and close the file.
I see conflicting information on which database is faster, postgres or mysql. In your experience, is postres preferable?
From my experience, PostgreSQL is faster and has much smaller memory footprint.
When my Nextcloud runs with MariaDB, it occasionally coughs out a 502 gateway timeout error and is slow to process when there are a large number of files. After switching to PostgreSQL, the problems are gone, without doing any performance tuning.
Actually, some of the Nextcloud developers recommend PostgreSQL. Your mileage may vary depending on your server setup. You can always switch back to MySQL/MariaDB if there’s no performance gain.
I’m running into an error when trying to convert MariaDB to Postgresql.
Log into MySQL/MariaDB console:
Select the nextcloud database.
Describe the structure of the
oc_jobs
table.Sample output:
If your
oc_jobs
table doesn’t have thetime_sensitive
column, it means your database is broken in the first place.hi. please i was successful till step.6 open nexctloud page to install nextcloud when i opened my page there is only nginx welcome page, not the nextcloud installation page. i did fresh install on last ubunutu 22 image without any pre-instllation .
thanks
bye
rasto
Are you using an IP address to access the Nextcloud installation page? When you use an IP address, the default virtual host will be used.
i am using domain pointing to my public IP address. so i tried to put in /etc/nginx/conf.d/nextcloud.conf domain name also ip address but result is same.. even when i tried /nextcloud/ – in this case it give me error page.. thank you very much for help
Remove the default virtual host.
Then restart Nginx.
Hi,
I have been trying to get past a permission error on a SSD that I installed on a nuc i3 box as an external storage mount.
I can’t set up this drive up during the wizard setup so I used the main drive and then tried to move the data directory as per your notes. I keep getting that .occdata is not present, which it is.
Ubuntu installed my SSD as /media/keith/nc-data, I have given this drive www-data ownership.
I have included the mount point in fstab with it’s UUID.
not sure where else to look..
Ubuntu 22.04.
Hi,
Solved this issue.. (at last).. my new data directory was “/media/keith/nc-data/cloud-data”, I had changed the ownership of nc-data to www-data as mentioned elsewhere.. but I had to ALSO change keith to www-data as well..
Thanks for a great set of instructions..
Some general comments;
– Collarbora does not work on a Raspberry Pi ARM processor
– Only office is not supported on Nexcloud 24.0 and above.
Ni hao, Xiao!
I’ve followed your directions and when I start the web-based install, I get a bunch of upgrades that need to be run, as well as some apps that get disabled. Then when I click Continue to Nextcloud I get a 504 Gateway Time-out. Nothing happens after this. Can you help?
Hi Ken,
The 504 gateway time-out error is caused by the
Nextcloud Office
app. It seems not compatible with the latest Nextcloud version. Disable this app with the following command and the 504 error will go away.If you can find the following line in the
/var/log/nginx/nextcloud.access
file, it means the Nextcloud Office doesn’t work.I am getting the following errors,
Your web server is not properly set up to resolve “/.well-known/webfinger”. Further information can be found in the documentation ↗.
Your web server is not properly set up to resolve “/.well-known/nodeinfo”. Further information can be found in the documentation ↗.
Your web server is not properly set up to resolve “/.well-known/caldav”. Further information can be found in the documentation ↗.
Your web server is not properly set up to resolve “/.well-known/carddav”. Further information can be found in the documentation ↗.
How do I fix these? I know someone mentioned to ignore the 1st 2, but how do you fix it if I am using social app?
I’m having an issue with Collabora Online – Built-in CODE Server after following this guide. When enabled, nextcloud will show “Internal Server Error”. I have to use sudo -u www-data php -d memory_limit=512M ./occ app:remove richdocumentscode for nextcloud to work again. Any ideas what this could be?
Great tutorial, I managed to set it up on an old PI 2B (bullseye). it’s a bit slow but it’s working. Thanks
Hi
Can php 8.1 run in paralel with 7.4? I have already 7.4 running on my VPS
Thanks
Yes, you can install PHP8.1 alongside PHP 7.4.
How to Install Multiple Versions of PHP on Ubuntu 22.04, 20.04, 18.04
Hello I installed Nextcloud following your excellent guide.
My internal drive is too limited, I would like to extend it.
What do you recommend me.
Is it better to move the data base to my external USB drive or shoudl I try to extend it with the internal app extend storage from nc ?
My feeling is, if the machine crash have the entire data base on the external drive should be better and more safe for recover the data right ?
Should I format the drive in exFAT or ext4 before to move the data base following your guide ? ( I was thinking if my server crash I can just plug the drive on another device and be able to read the data, then it not lost).
You said :
In case you need to move the NextCloud data directory, there are 4 steps to accomplish this. First, you need to use the cp command to copy the data directory to the new directory. For example, the mount point of my external hard drive is /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731. I create the new data directory on the external hard drive.
How do we use CP command ? ( I have interface user can i simply search the data directory and do copy paste ?).
The mount point : /media/linuxbabe/b43e4eea-9796-4ac6-9c48-2bcaa46353731.
This b43e4eea-9796-4ac6-9c48-2bcaa46353731 is the name of your drive ?
Encryption is broken due incompatibility between openssl v3.0.2 and nextcloud with Ubuntu 22.04, to fix this, the following needs to be done:
credit to pako81 post here:
https://github.com/owncloud/core/issues/40071
edit the openssl in the [provider_sect] section as follows:
=================================
=========================================
restart the server and enable encryption.
encryption will now work.
thanks to Xiao for his excellent easy to following tutorials, I owe a great debt to most of my knowledge in Linux.
Thank You
Hi, firstly, thank you for the great tutorial. Unlike others scattered around the net this one is easy to follow and, it works. My basic setup is working fine but I’ve run into an issue moving my data storage to a secondary hard drive. The secondary hard drive is mounted at /mnt/disk1. I’ve made the directory /mnt/disk1/nextcloud-data but when I run the following commands I get “No such file or directory” as seen below:
username@userscloud:/var/www$ sudo cp /var/www/nextcloud-data/* /mnt/disk1/nextcloud-data/ -R
cp: cannot stat ‘/var/www/nextcloud-data/*’: No such file or directory
username@usersscloud:/var/www$
When I run the ls command as seen below it shows the nextcloud-data file as being there. Do you see anything that I am doing wrong?
username@buserscloud:/var/www$ ls
html nextcloud nextcloud-data
I’ve checked and the new nextcloud-data file exists on my new drive.
Thank you.
Hi Xiao Guoan, can you use emoji and Chinese characters in your file and directory name?
I followed your guide, using CREATE DATABASE nextcloud TEMPLATE template0 ENCODING ‘UNICODE’;
I can upload files with Chinese characters in names, say some.mp4, successfully. But when I try to download it by clicking on its name, I get Internal Server Error.
I can’t create a directory using just emojis. It says “Cannot create directory”.
Log file has this:
{“reqId”:”IUjiKqsIgPeUXVrJbDAS”,”level”:4,”time”:”2022-10-01T12:28:28+00:00″,”remoteAddr”:”192.168.1.3″,”user”:”nextcloudadmin”,”app”:”webdav”,”method”:”GET”,”url”:”/remote.php/webdav/\u00e9%BB%83\u00e5%87%B1\u00e8%8A%B9%20Christopher%20Wong\u00e3%80%8A\u00e6\u00b5\u00aa\u00e6%BC%AB\u00e5%92%96\u00e5%95%A1\u00e5\u00ba%97\u00e3%80%8B-MV-.mp4″,”message”:”parse_url(): Argument #1 ($url) must be of type string, null given”,”userAgent”:”Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15″,”version”:”24.0.5.1″,”exception”:{“Exception”:”TypeError”,”Message”:”parse_url(): Argument #1 ($url) must be of type string, null given”,”Code”:0,”Trace”:[{“file”:”/var/www/nextcloud/3rdparty/sabre/uri/lib/functions.php”,”line”:196,”function”:”parse_url”},{“file”:”/var/www/nextcloud/3rdparty/sabre/uri/lib/functions.php”,”line”:114,”function”:”Sabre\\Uri\\parse”},{“file”:”/var/www/nextcloud/3rdparty/sabre/http/lib/Request.php”,”line”:168,”function”:”Sabre\\Uri\\normalize”},{“file”:”/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,”line”:1291,”function”:”getPath”,”class”:”Sabre\\HTTP\\Request”,”type”:”->”},{“file”:”/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,”line”:466,”function”:”checkPreconditions”,”class”:”Sabre\\DAV\\Server”,”type”:”->”},{“file”:”/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,”line”:253,”function”:”invokeMethod”,”class”:”Sabre\\DAV\\Server”,”type”:”->”},{“file”:”/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,”line”:321,”function”:”start”,”class”:”Sabre\\DAV\\Server”,”type”:”->”},{“file”:”/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php”,”line”:87,”function”:”exec”,”class”:”Sabre\\DAV\\Server”,”type”:”->”},{“file”:”/var/www/nextcloud/remote.php”,”line”:166,”args”:[“/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php”],”function”:”require_once”}],”File”:”/var/www/nextcloud/3rdparty/sabre/uri/lib/functions.php”,”Line”:196,”CustomMessage”:”–“}}
My PostgreSQL setting:
nextcloud=> SHOW SERVER_ENCODING;
server_encoding
—————–
UTF8
(1 row)
Yes, I can use Chinese characters and emojis in the folder name.
Here is the screen.
hello xiao I did the whole installation according to your tutorial and everything works great for me but sometimes this error is generated
[PHP] Error: Exception: The requested uri(/.env) cannot be processed by the script ‘/core/templates/403.php’) at /var/www/nextcloud/lib/private/AppFramework/Http/Request.php#760
GET /.env
from 13.90.115.5 at 2022-10-19T18:14:58+00:00
This is a fantastic tutorial and almost exactly what I was looking for. Thank you so much for your work.
However, I would like to setup NC behind a proxy and think SWAG would do a great job, but I don’t know how to do this. Also, I’m not sure, if I could use SWAG for both tasks (nc database and proxy)?
In the meantime I got everything running as I wanted and coming from a TrueNas core to ubuntu I must say: couldn’t be happier. Thank you so much!
The only thing missing now is the turnserver… (for Nextcloud Talk).
I have a server with iredmail, mautic and suitecrm installed from your tutorials. I tried to add this and keep on getting a 502 error. Did I do something wrong?
How about opcache and PHP-FPM –
Im not a geek or anything, but how can we optimize this install so it loads faster and is generally more smooth?
Hi Xiao,
First of all, thank you for the exceptionally well-written Nextcloud implementation process. I was able to roll it out a few times without issues. There is however one, albeit somewhat unrelated issue. Anytime I enable richdocuments (for Nextcloud Office, Collabora Online – Built-in CODE Server, Only Office, etc.) the whole thing stops working (504 error) and only way to recover is to disable the richdocuments app from command line with ‘sudo -u www-data php occ app:disable richdocuments’ command. This maybe specific to Nextcloud 25.0.2 version. I was wondering if you experienced this issue and if so, were you able to come up with a fix for it.
Thank you
Awesome tutorial! I followed your guide on installing nextcloud on ubuntu 18.04 before and now I switched server and this one works great, too!
Nextcloud 25 is buggy, I installed Nextcloud 25 following this guide, and got some random errors and lots of Network 99 errors. But when I tried again to install nextcloud 24.0.9, it went smooth! So I recommend installing the latest stable version of Nextcloud 24.
Can I get a nginx reverse proxy config recommendation? please
your instructions worked great but i want to know how to acess my nextlcoud using the local server ip.
for example i have a domain and i can access nextcloud over the web just fine but i want to be able to access it internally using that servers ip but i cannot.
nevermind figured it out added to trusted sites
I am getting the following errors,
Your web server is not properly set up to resolve “/.well-known/webfinger”. Further information can be found in the documentation ↗.
Your web server is not properly set up to resolve “/.well-known/nodeinfo”. Further information can be found in the documentation ↗.
Those i fixed:
Your web server is not properly set up to resolve “/.well-known/caldav”. Further information can be found in the documentation ↗.
Your web server is not properly set up to resolve “/.well-known/carddav”. Further information can be found in the documentation ↗.
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you’re planning to use this app.
location ^~ /.well-known/nodeinfo {
return 301 /index.php/.well-known/nodeinfo/;
}
location = /.well-known/webfinger {
return 301 /index.php/.well-known/webfinger/;
}
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
# The following rule is only needed for the Social app.
# Uncomment it if you’re planning to use this app.
rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
location = /.well-known/carddav {
return 301 /remote.php/dav/;
}
location = /.well-known/caldav {
return 301 /remote.php/dav/;
}
plus woff2 and “/ocm-provider/”. are giving errors
I’m having problems with letsencrypt setup.
This is the problem I have.
Could not automatically find a matching server block for XXXX.XX. Set the `server_name` directive to use the Nginx installer.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details
Thanks.
Hi, how are you
did you manage to fix the errors?
Thank you so much for creating this guide
Hi Xiao
Can we use this as Instant Messaging in our company?
hello, i wanna make jellyfin to http and nextcloud to https
first follow-up to installed nextcloud, and installed jellyfin
i made two config on nginx. jellyfin.conf and nextcloud.conf
https://www.howtoforge.com/how-to-install-jellyfin-media-server-ubuntu-20-04/
what i need remove redirect option on nextcloud.conf?
i need your help. i dont really understand it
the installation is complete i can access the nextcloud but after sudo apt I tried install certbot python3-certbot-nginx my page is down