This post is my shortest version of a Nextcloud install on Ubuntu Server 18 LTS. Assuming you have installed the OS and all available updates, run these commands as root:

sudo apt update
sudo apt upgrade
sudo apt-get install apache2 libapache2-mod-php bzip2
sudo apt-get install php-gd php-json php-mysql php-curl php-mbstring
sudo apt-get install php-intl php-imagick php-xml php-zip

sudo apt-get install mariadb-server
sudo mysql_secure_installation

sudo mysql -u root -p
CREATE DATABASE nextcloud;
CREATE USER ‘nextcloud’@’localhost’ IDENTIFIED BY ‘PASSWORD’;
GRANT ALL PRIVILEGES ON nextcloud.* TO ‘nextcloud’@’localhost’;
FLUSH PRIVILEGES;
exit

sudo wget https://download.nextcloud.com/server/releases/latest.tar.bz2 -O nextcloud-latest.tar.bz2
sudo tar -xvjf nextcloud-latest.tar.bz2

sudo rm /var/www/html/index.html

cd nextcloud
sudo mv * /var/www/html
sudo mv .htaccess /var/www/html
sudo mv .user.ini /var/www/html

cd ..
sudo rm nextcloud-latest.tar.bz2
sudo rm -R nextcloud

sudo chown -R www-data:www-data /var/www/html

sudo service apache2 reload

http://192.168.xxx.xxx – install nextcloud

=========== WARNING MESSAGES AND HOW TO FIX THEM ==============

################# .htaccess not working

sudo nano /etc/apache2/apache2.conf

Options Indexes FollowSymLinks
AllowOverride None (change None to All)
Require all granted

sudo service apache2 restart

################ php memory limit

sudo nano /etc/php/7.2/apache2/php.ini
CHANGE memory limit from 128MB to 512 MB

sudo service apache2 restart

############### enable the 4-byte support in MySQL

cd /var/www/html
sudo -u www-data php occ config:system:set mysql.utf8mb4 –type boolean –value=”true”

############### support well-known/caldav

sudo nano /var/www/html/.htaccess

ADD THESE TWO LINES:

Redirect 301 /.well-known/carddav /remote.php/dav
Redirect 301 /.well-known/caldav /remote.php/dav

############### memory cache

sudo apt install php-apcu redis-server php-redis
sudo a2enmod rewrite headers
sudo nano /etc/redis/redis.conf
### CHANGE port 6379 to port 0
### UNCOMMENT unixsocket /var/run/redis/redis-server.sock
### UNCOMMENT unixsocketperm 700 AND CHANGE TO unixsocketperm 770
sudo usermod -a -G redis www-data
sudo service apache2 restart
sudo service redis-server start
sudo nano /var/www/html/config/config.php

#### ADD THIS BEFORE THE LAST bracket );
===============================
‘memcache.local’ => ‘\\OC\\Memcache\\Redis’,
‘memcache.locking’ => ‘\\OC\\Memcache\\Redis’,
‘filelocking.enabled’ => ‘true’,
‘redis’ =>
array (
‘host’ => ‘/var/run/redis/redis-server.sock’,
‘port’ => 0,
‘timeout’ => 0.0,
),
=============================

sudo systemctl enable redis-server
sudo reboot

################# missing indexes

cd /var/www/html
sudo -u www-data php occ db:add-missing-indices

################## MariaDB big int

cd /var/www/html
sudo -u www-data php occ db:convert-filecache-bigint

################## accessing site using http

We don’t care about this one.