To use the directory-based installation, put the following in your nextcloud.conf replacing the Directory and Alias filepaths with the filepaths appropriate for your system:

nextcloud.conf
Alias /nextcloud "/var/www/nextcloud/"
 
<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews
 
  <IfModule mod_dav.c>
    Dav off
  </IfModule>
</Directory>

To use the virtual host installation, put the following in your nextcloud.conf replacing ServerName, as well as the DocumentRoot and Directory filepaths with values appropriate for your system:

<VirtualHost *:80>
  DocumentRoot /var/www/nextcloud/
  ServerName  your.server.com
 
  <Directory /var/www/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
 
    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
</VirtualHost>
a2ensite nextcloud.conf

For Nextcloud to work correctly, we need the module mod_rewrite. Enable it by running:

a2enmod rewrite

Additional recommended modules are mod_headers, mod_env, mod_dir and mod_mime:

a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime
service apache2 restart