In case you prefer installing from the source tarball, you can setup Nextcloud
from scratch using a classic LAMP stack (Linux, Apache, MySQL/MariaDB, PHP).
This document provides a complete walk-through for installing Nextcloud on
Ubuntu 16.04 LTS Server with Apache and MariaDB, using the Nextcloud .tar
archive.

Admins of SELinux-enabled distributions such as CentOS, Fedora, and
Red Hat Enterprise Linux may need to set new rules to enable installing
Nextcloud. See SELinux configuration tips for a suggested configuration.

If you are using Windows, the easiest way to get Nextcloud up and running is
using a virtual machine (VM). There are two options:

Enterprise/SME appliance

Nextcloud GmbH maintains a free appliance built on the
Univention Corporate Server (UCS)
with easy graphical setup and web-based administration. It includes user
management via LDAP, can replace an existing Active Directory setup and
has optional ONLYOFFICE and Collabora Online integration, with many more applications
available for easy and quick install.

It can be installed on hardware or ran in a virtual machine using VirtualBox,
VMWare (ESX) and KVM images.

The Nextcloud VM is maintained by
T&M Hansson IT and several different versions are
offered. Collabora, OnlyOffice, Full Text Search and other apps can easily be installed with the included scripts which you can choose to run during the first setup, or download them later and run it afterwards. You can find all the currently available automated app installations on GitHub.

The VM is made with VMware version 10 and it comes in different sizes and versions:

You can install the VM on several different operating systems as long as you can mount OVA, VMDK, or VHD/VHDX VM in your hypervisor. If you are using KVM then you need to install the VM from the scripts on Github. You can follow the instructions in the README.

A snap is a zip file containing an application together with its dependencies,
and a description of how it should safely be run on your system, especially
the different ways it should talk to other software. Most importantly snaps are
designed to be secure, sandboxed, containerized applications isolated from the
underlying system and from other applications.

To install the Nextcloud Snap Package, run the following command in a terminal:

sudosnapinstallnextcloud

Note

The snapd technology is the core
that powers snaps, and it offers a new way to package, distribute, update and
run OS components and applications on a Linux system. See more about snaps on
snapcraft.io.

The Nextcloud .tar archive contains all of the required PHP modules. This
section lists all required and optional PHP modules. Consult the PHP manual for more information on modules.
Your Linux distribution should have packages for all required modules. You can
check the presence of a module by typing php-m|grep-i<module_name>.
If you get a result, the module is present.

You don’t need the WebDAV module for your Web server (i.e. Apache’s
mod_webdav), as Nextcloud has a built-in WebDAV server of its own,
SabreDAV.
If mod_webdav is enabled you must disable it for Nextcloud. (See
Apache Web server configuration for an example configuration.)

This installs the packages for the Nextcloud core system.
libapache2-mod-php7.0 provides the following PHP extensions: bcmathbz2calendarCorectypedatedbadomeregexiffileinfofilterftpgettexthashiconvlibxmlmhashopensslpcrePharposixReflectionsessionshmopSimpleXMLsoapsocketsSPLstandardsysvmsgsysvsemsysvshmtokenizerwddxxmlreaderxmlwriterzlib. If you are planning
on running additional apps, keep in mind that they might require additional
packages. See Prerequisites for manual installation for details.

At the installation of the MySQL/MariaDB server, you will be prompted to
create a root password. Be sure to remember your password as you will need it
during Nextcloud database setup.

Now you can extract the archive contents. Run the appropriate unpacking
command for your archive type:

tar-xjfnextcloud-x.y.z.tar.bz2unzipnextcloud-x.y.z.zip

This unpacks to a single nextcloud directory. Copy the Nextcloud directory
to its final destination. When you are running the Apache HTTP server you may
safely install Nextcloud in your Apache document root:

cp-rnextcloud/path/to/webserver/document-root

where /path/to/webserver/document-root is replaced by the
document root of your Web server:

cp-rnextcloud/var/www

On other HTTP servers it is recommended to install Nextcloud outside of the
document root.

Next install the PHP modules needed for this install. Remember, because this is a limited basic install, we only install the neccessary modules, not all of them. If you are making a more complete install, please refer to PHP module list at the top of this page.:

There is already an extensive document on database configuration which you can find here: ..admin_manual/configuration_server/automatic_configuration.rst Please follow all instructions there and then head back here.

Again, there is an extensive write-up done on SELinux which can be found at SELinux configuration, so if you are using SELinux in Enforcing mode, please run the commands suggested on that page.
The following commands only refers to this tutorial:

If you need more SELinux configs, refer to the above-mentioned URL, return to this tutorial.

Once done with with SELinux, please head over to http://your.server.com/nextcloud and follow the steps as found Installation wizard, where it will explain to you exactly how to proceed with the final part of the install, which is done as admin user through your web browser.

Note

If you use this tutorial, and you see warnings in the web browser after installation about OPcache not being enabled or configured correctly, you need to make the suggested changes in /etc/php.d/opcache.ini for the errors to disappear. These warnings will be on the Admin page, under Basic settings.

Because we used Redis as a memcache, you will need a config similar to the following example in /var/www/html/nextcloud/config/config.php which is auto-generated when you run the online installation wizard mentioned earlier.

Remember, this tutorial is only for a basic setup of Nextcloud 13 on CentOS 7, with PHP 7.2. If you are going to use more features like LDAP or Single Sign On, you will need additional PHP modules as well as extra configurations. So please visit the rest of the Admin manual, ..admin_manual/index.rst, for detailed descriptions on how to get this done.

On Debian, Ubuntu, and their derivatives, Apache installs with a useful
configuration so all you have to do is create a
/etc/apache2/sites-available/nextcloud.conf file with these lines in
it, replacing the Directory and other filepaths with your own filepaths:

If you’re running mod_fcgi instead of the standard mod_php also enable:

a2enmodsetenvif

You must disable any server-configured authentication for Nextcloud, as it
uses Basic authentication internally for DAV services. If you have turned on
authentication on a parent folder (via e.g. an AuthTypeBasic
directive), you can turn off the authentication specifically for the
Nextcloud entry. Following the above example configuration file, add the
following line in the <Directory> section:

SatisfyAny

When using SSL, take special note of the ServerName. You should specify one
in the server configuration, as well as in the CommonName field of the
certificate. If you want your Nextcloud to be reachable via the internet,
then set both of these to the domain you want to reach your Nextcloud server.

Now restart Apache:

serviceapache2restart

If you’re running Nextcloud in a subdirectory and want to use CalDAV or
CardDAV clients make sure you have configured the correct
Service discovery URLs.

You can use Nextcloud over plain HTTP, but we strongly encourage you
to use SSL/TLS to encrypt all of your server traffic, and to protect
user’s logins and data in transit.

Apache installed under Ubuntu comes already set-up with a simple
self-signed certificate. All you have to do is to enable the ssl module and
the default site. Open a terminal and run:

a2enmodssla2ensitedefault-sslserviceapache2reload

Note

Self-signed certificates have their drawbacks - especially when you
plan to make your Nextcloud server publicly accessible. You might
want to consider getting a certificate signed by a commercial signing
authority. Check with your domain name registrar or hosting service
for good deals on commercial certificates.

After restarting Apache you must complete your installation by running either
the graphical Installation Wizard, or on the command line with the occ
command. To enable this, change the ownership on your Nextcloud directories to
your HTTP user:

chown -R www-data:www-data /var/www/nextcloud/

Note

Admins of SELinux-enabled distributions may need to write new SELinux
rules to complete their Nextcloud installation; see
SELinux configuration tips.

Due to a bug with security implications
in older PHP releases with the handling of XML data you are highly encouraged to run
at least PHP 5.6.6 when in a threaded environment.

System environment variables

When you are using php-fpm, system environment variables like
PATH, TMP or others are not automatically populated in the same way as
when using php-cli. A PHP call like getenv('PATH'); can therefore
return an empty result. So you may need to manually configure environment
variables in the appropropriate php-fpm ini/config file.

Here are some example root paths for these ini/config files:

Ubuntu/Mint

CentOS/Red Hat/Fedora

/etc/php5/fpm/ or
/etc/php/7.0/fpm/

/etc/php-fpm.d/

In both examples, the ini/config file is called www.conf, and depending on
the distro version or customizations you have made, it may be in a subdirectory such as pool.d.

Usually, you will find some or all of the environment variables
already in the file, but commented out like this:

If any of your system environment variables are not present in the file then
you must add them.

Alternatively it is possible to use the environemt variables of your system by modifying

/etc/php/7.0/fpm/pool.d/www.conf

and uncommenting the line

clear_env = no

When you are using shared hosting or a control panel to manage your Nextcloud VM or server, the configuration files are almost
certain to be located somewhere else, for security and flexibility reasons, so
check your documentation for the correct locations.

Please keep in mind that it is possible to create different settings for
php-cli and php-fpm, and for different domains and Web sites.
The best way to check your settings is with PHP version and information.

Maximum upload size

If you want to increase the maximum upload size, you will also have to modify
your php-fpm configuration and increase the upload_max_filesize and
post_max_size values. You will need to restart php5-fpm and your HTTP
server in order for these changes to be applied.

.htaccess notes for Apache

Nextcloud comes with its own nextcloud/.htaccess file. Because php-fpm
can’t read PHP settings in .htaccess these settings and permissions must
be set in the nextcloud/.user.ini file.