Uncategorized

Install Nextcloud 20 on Ubuntu 19.10/20.04

INSTALL SOFTWARE:

# apt-get install apache2 php7.4 bzip2
# apt-get install libapache2-mod-php php-gd php-json php-mysql php-curl php-mbstring
# apt-get install php-intl php-xml php-zip php-bcmath php-gmp php-imagick

INSTALL MARIADB DATABASE & SECURE MARIADB

# apt-get install mariadb-server php-mysql
#  mysql_secure_installation

TO ENABLE EMOJI

# echo -e "[mysqld]\ninnodb_large_prefix=true\ninnodb_file_format=barracuda\ninnodb_file_per_table=1" >> /etc/mysql/conf.d/00-innodb.cnf
# systemctl restart mysql

ENTER THE DATABASE AND CREATE TABLE AND USER

$ mysql -u root -p
CREATE DATABASE nextcloud;
CREATE USER 'nc_user'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_HERE';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nc_user'@'localhost';
FLUSH PRIVILEGES;
CTRl + D to exit mariadb

INSTALL NEXTCLOUD

# cd /var/www
# wget https://download.nextcloud.com/server/releases/latest-20.tar.bz2 -O nextcloud-20-latest.tar.bz2
# tar -xvjf nextcloud-20-latest.tar.bz2
# chown -R www-data:www-data nextcloud
# rm nextcloud-20-latest.tar.bz2

create a new file in /etc/apache2/sites-available/nextcloud.conf 

Alias /nextcloud "/var/www/nextcloud/"
<Directory /var/www/nextcloud/>
  Options +FollowSymlinks
  AllowOverride All
 <IfModule mod_dav.c>
  Dav off
 </IfModule>
 SetEnv HOME /var/www/nextcloud
 SetEnv HTTP_HOME /var/www/nextcloud
</Directory>

ENABLE APACHE MODS AND RAISE PHP MEMORY LIMIT

# a2dissite 000-default
# a2ensite nextcloud
# a2enmod rewrite headers env dir mime
# sed -i '/^memory_limit =/s/=.*/= 512M/' /etc/php/7.4/apache2/php.ini
# systemctl restart apache2

ENABLE FIRWALL

# ufw enable
# ufw allow http
# ufw allow https
# ufw allow ssh (if your ssh'ing to a remote machine

ONCE YOUR DONE HEAD OVER TO HTTP://YOUR_IP_ADDRESS/nextcloud

enter the database details, It might change address to the wrong address, just change to IP address again.

ENABLE CACHING (WILL HELP)

# apt-get install php7.4-opcache

NOW EDIT FILE /etc/php/7.4/apache2/conf.d/10-opcache.ini 

; configuration for php opcache module
; priority=10
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

RESTART APACHE

# systemctl restart apache2

INSTALL AND CONFIGURE REDIS  /var/www/nextcloud/config/config.php

<?php
$CONFIG = array (
  'instanceid' => '',
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' =>
    array (
          0 => 'YOUR_IP',
    ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '19.0.0.12',
  'overwrite.cli.url' => 'http://YOUR_IP/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nc_user',
  'dbpassword' => 'YOUR_PASSWORD_HERE',
  'installed' => true,
  'memcache.locking' => '\OC\Memcache\Redis',
  'memcache.distributed' => '\OC\Memcache\Redis',
  'memcache.local' => '\OC\Memcache\Redis',
  'redis' => [
  'host' => 'localhost',
    'port' => 6379,
    'timeout' => 3,
  ],
);

RESTART WEBSERVER AGAIN:

# systemctl restart apache2

SETUP VIRTUAL HOST FOR APACHE – EDIT THE PREVIOUS FILE CREATED: /etc/apache2/sites-available/nextcloud.conf 

<VirtualHost *:80>
  ServerName YOURDOMAIN.TLD
  ServerAdmin YOUR@EMAIL.TLD
  DocumentRoot /var/www/nextcloud
  <directory /var/www/nextcloud>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
    SetEnv HOME /var/www/nextcloud
    SetEnv HTTP_HOME /var/www/nextcloud
  </directory>
</VirtualHost>

SET DOMAIN AT REGISTRAR ADD A RECORD AND POINT TO YOUR VPS/SERVER IP ADDRESS, ONCE COMPLETED ADD THE TRUSTED DOMAIN TO NEXTCLOUD:

$ sudo -u www-data php /var/www/nextcloud/occ config:system:set trusted_domains 2 --value=YOURDOMAIN.TLD

ONCE YOU HAVE COMPLETED THIS YOU WILL NOT BE ABLE TO ACCESS NEXTCLOUD THROUGH IP ADDRESS IT WILL BE: HTTP://YOURDOMAIN.TLD

SETUP CERTBOT TO ENABLE SSL FOR DOMAIN:

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository universe
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache 
$ sudo certbot --apache
$ systemctl restart apache2

IT MAY DISPLAY AN ERROR ABOUT PYTHON NOT FOUND IS SUGGESTS USING PYTHON3-CERTBOT-APACHE

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *