adduser <username>
Adding the user to the sudo group:
usermod -aG sudo <username>
Before continuing, let’s make sure all installed packages are up to date.
sudo apt update
sudo apt dist-upgrade
Clean up orphan packages (if there are any):
sudo apt autoremove
Edit the following files, and be sure they include the proper hostname or domain name for your server:
sudo nano /etc/hostname
sudo nano /etc/hosts
Reboot your server so that all the changes we’ve made so far will take effect.
sudo reboot
On the server, download the Nextcloud zip file using the URL that you copied from the site:
wget https://download.nextcloud.com/server/releases/latest.zip
First, let’s install the mariadb-server package:
sudo apt install mariadb-server
Check service status
systemctl status mariadb
Although there’s many tweaks and adjustments you can make to secure MariaDB, running the following command and answering the prompts will give us a decent starting point:
sudo mysql_secure_installation
enter current root password: enter (this is empty password will be chnaged within next step)
socket authentication: n (we will use nextcloud authentication insteed of local linux)
change root password: y (set root password for mariadb) <root_mariadb_password> = mariaDBP@ssw0rd
remove anonymous users: y
allow root to login remotley: y
disallow root login remotley: y
remove test database: y
reload provolege tables: y
Next, we’ll create the database we’ll be using for Nextcloud. To do this, we’ll need to access the MariaDB console:
sudo mariadb
Then, we’ll create the database and set up permissions with the following commands:
CREATE DATABASE nextcloud;
SHOW DATABASES;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'mypassword';
FLUSH PRIVILEGES;
CTRL+D to exit the MariaDB shell.
Installing the required packages to support Apache:
sudo apt install libmagickcore-6.q16-6-extra php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml
Check the status with of Apache:
systemctl status apache2
Enable the recommended PHP extensions:
sudo phpenmod apcu bcmath gmp imagick intl
Install zip and unzip the Nextcloud zip file:
sudo apt install unzip
unzip latest.zip
Now that we’ve unzipped the files, let’s move the files to where they’ll be served from and also set the permissions as well:
sudo chown -R www-data:www-data nextcloud
sudo mv nextcloud /var/www/
Also, let’s disable the default web page that ships with Apache since we won’t be needing it for anything:
sudo a2dissite 000-default.conf
Next, we’ll set up a config file for Apache that tells it how to serve Nextcloud.
sudo nano /etc/apache2/sites-available/nextcloud.conf
Add the following contents to the file (be sure to adjust the file names to match yours):
<VirtualHost *:80>
DocumentRoot "/var/www/nextcloud"
ServerName nextcloud
<Directory "/var/www/nextcloud/">
Options MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /var/log/apache2/nextcloud_access.log
ErrorLog /var/log/apache2/nextcloud_error.log
</VirtualHost>
Enable the site:
sudo a2ensite nextcloud.conf
Almost there! The next step will have us change some PHP options. First, edit the following file:
sudo nano /etc/php/8.2/apache2/php.ini
Find the options in the following list, and ensure they equal the values shown here. Some may already be set to the appropriate value. Also, be sure to remove the semicolon that may be in front of one or more of these options, because we want to ensure none of these are commented out:
memory_limit = 512M
upload_max_filesize = 200M
max_execution_time = 360
post_max_size = 200M
date.timezone = America/Detroit
opcache.enable=1
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
Enable the following PHP mods for Apache:
sudo a2enmod dir env headers mime rewrite ssl
sudo systemctl restart apache2