How to Install NextCloud on Ubuntu Server 22.04 LTS

Post Reply
User avatar
Site Admin
Site Admin
Posts: 1108
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You

How to Install NextCloud on Ubuntu Server 22.04 LTS

Post: # 1129Post LHammonds »

------------- WORK-IN-PROGRESS -------------

Greetings and salutations,

I hope this thread will be helpful to those who follow in my foot steps as well as getting any advice based on what I have done / documented.

To discuss this thread, please participate here: Ubuntu Forums

High-level overview

NextCloud is a web application that can store and serve content from a centralized location, much like Dropbox. The difference is that NextCloud allows you to host the serving software on your own machines, taking the trust issues out of putting your personal data someone else's server.

This tutorial will cover how to manually setup an NextCloud server which will use a separate dedicated database server and SSL encryption.

Advantages of manually installing NextCloud:
* Can use the latest version of NextCloud currently available (Repository rarely contains latest version)
* Are not forced to install database locally (handy if you have a dedicated database server)
* Can install where you want (such as standard / well-known locations)

Disadvantages of manually installing NextCloud:
* Will not automatically update the system via "apt-get update" (although you are not guaranteed you get the latest this way either...just the latest in the repository)
* Not as easy to install (thus this step-by-step guide)

Tools utilized in this process
Helpful links

The list below are sources of information that was helpful in the creation of this document.

This documentation will need to make use of some very-specific information that will most-likely be different for each person / location. And as such, this information will be noted in this section. They will be highlighted in red throughout the document as a reminder that you should plug-in your own value rather than actually using these "place-holder" values.

Under no circumstance should you use the actual values listed below. They are place-holders for the real thing. This is just a checklist template you need to have answered before you start the install process.

Wherever you see RED in this document, you need to substitute it for you will use in your environment.
  • Internet domain:
  • Ubuntu Server name: srv-nextcloud
  • Ubuntu Server IP address:
  • Ubuntu Admin ID: administrator
  • Ubuntu Admin Password: myadminpass
  • Database Server Name (remote): srv-database
  • Database Server IP (remote):
  • Database Admin ID: root
  • Database Admin Password: rootpass
  • Database ID: nextclouduser
  • Database Password: nextclouduserpass
  • Email Server Name (remote): srv-mail
  • Email Server IP (remote):
  • NextCloud Admin ID: NextCloudAdmin
  • NextCloud Admin Password: nextcloudadminpass
Web Server - Setup an Ubuntu server for use as the NextCloud server. This tutorial assumes the server was configured according to this tutorial: How to install Apache web server

MySQL/MariaDB server - Setup a separate and dedicated database server. This tutorial assumes the server was configured according to this tutorial: How to install and configure MariaDB

It is also assumed the reader knows how to use the VI editor. If not, you will need to beef up your skill set or use a different editor in place of it.
User avatar
Site Admin
Site Admin
Posts: 1108
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You

Prior to Install

Post: # 1130Post LHammonds »

Name Resolution

Add your NextCloud domain(s) so they point to the local loopback (
Add your other remote servers such as your mail and database server IPs so you can reference them by name.

Code: Select all

sudo vi /etc/hosts

Code: Select all       localhost       srv-nextcloud  srv-mail  srv-database

Install PHP for Apache with MySQL/MariaDB support

Code: Select all

sudo apt -y install php8.1 libapache2-mod-php8.1 php8.1-mysql
TIP: You can search available PHP packages names by typing this:

Code: Select all

apt-cache search php8.1
TIP: You can see which PHP modules are installed by typing this:

Code: Select all

php -m
There are various required, recommended, app-specific modules listed on the requirements section of the manual.

The below will show what is already installed by default and what will be needed as a complete list. You can customize to your needs.

PHP modules:

Code: Select all

bz2 - Missing (contained in php8.1-bz2)
curl - Missing (contained in php8.1-curl)
dom - Missing (contained in php8.1-xml)
gd - Missing (contained in php8.1-gd)
gmp - Missing (contained in php8.1-gmp)
imap - Missing (contained in php8.1-imap)
imagick - Missing (contained in php-imagick)
intl - Missing (contained in php8.1-intl)
ldap - Missing (contained in php8.1-ldap)
mbstring - Missing (contained in php8.1-mbstring)
simplexml - Missing (contained in php8.1-xml)
smbclient - Missing (contained in php8.1-smbclient)
xmlreader - Missing (contained in php8.1-xml)
xmlwriter - Missing (contained in php8.1-xml)
zip - Missing (contained in php8.1-zip)
Install the missing PHP modules with these packages:

Code: Select all

sudo apt -y install php8.1-bz2 php8.1-curl php8.1-gd php8.1-gmp php8.1-imap php-imagick php8.1-intl php8.1-ldap php8.1-mbstring php8.1-xml php8.1-zip
NOTE: Need to research how to install / configure / enable LibreOffice and video previews.

Enable various options in Apache:

Code: Select all

sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod env (probably already enabled)
sudo a2enmod dir (probably already enabled)
sudo a2enmod mime (probably already enabled)
Modify PHP to allow uploading of larger files and correct OPcache settings. In the below example, it allows 2GB uploads.

Code: Select all

sudo vi /etc/php/8.1/apache2/php.ini

Code: Select all

default_charset = "UTF-8"
post_max_size = 2058M
upload_max_filesize = 2048M
Reload Apache for changes to the config to take affect:

Code: Select all

sudo systemctl reload apache2
PHP Information

To verify Apache, PHP and modules are installed and enabled, lets create the famous phpinfo page.

Code: Select all

echo "<?php phpinfo(); ?>" >> /var/www/html/phpinfo.php
chmod 0644 /var/www/html/phpinfo.php
Open a browser and load up the phpinfo page:

You should be able to scroll down and see sections for each module we wanted enabled. If you don't see a dedicated section, then that module is not installed/enabled.

When done, do not forget to remove the info file:

Code: Select all

rm /var/www/html/phpinfo.php
Post Reply