To view this tutorial on Nextcloud (with proper Markdown formatting): https://nuage.fiatlux.tk/s/o4gBeiR2gYkmbXR
Prerequisites:
- Create a PHP website/domain with SSL certificate for your Nextcloud site
- Create a blank mysql database for Nextcloud
- SSH access to the VPS (or a SSH access to the website account)
- Alternatively : an FTP access to the website
Steps :
- 1. Get the Nextcloud archive and installer
- 2. Run the installer
- 3. PHP settings (CyberPanel)
- 4. Nextcloud basic config
- 5. Force HTTPS (.htaccess)
- 6. Tweak and optimize your instance
1. Get the Nextcloud archive and installer
Select the version of Nextcloud you want to use here: https://nextcloud.com/install/#instructions-server
- For SSH, we only need the link to the archive
- For FTP, we need to download the archive and installer first (download installer here: https://download.nextcloud.com/server/installer/setup-nextcloud.php)
SSH (CyberPanel)
Log to your VPS and switch to the webite user. To list usernames for each website:
# sudo ls -l /home
To switch user :
# sudo su <username>
I guess you can use a SSH account created in CyberPanel for the website too, in which case you wouldn’t need to switch user (I didn’t try).
Move to the public directory and download the archive and installer (here with Nextcloud 21.0.0) :
# cd ~/public_html
# wget -O nc.zip https://download.nextcloud.com/server/releases/nextcloud-21.0.0.zip
# wget https://download.nextcloud.com/server/installer/setup-nextcloud.php
FTP
Simply upload the archive and the installer to the website’s public_html
. Make sure you rename the archive nc.zip
before launching the installer.
2. Run the installer
Navigate your broswer to https://<domain>/setup-nextcloud.php
and follow the instructions.
A few notes:
- Dependency Check screen : enter
.
to install Nextcloud at the root of the site (unless you want to access your instance viahttps://<domain>/nextcloud/
) - Use a (very) strong password for the admin account
- Storage and database :
- Data directory : remove
public_html
from the path, eg. enter/home/<domain>/data
in place of/home/<domaine>/public_html/data
(default vallue) – this will ensure that user data will not accidentally get exposed publicly. - Database : select MySQL/MariaDB and enter the database credentials. Leave
localhost
as hostname.
- Data directory : remove
There you go, you have a running Nextcloud instance.
3. PHP settings (CyberPanel)
We’ll override some PHP settings for that specific website instead of tweaking php.ini
for the entire server. Set this way, they will also apply regardless of the version of PHP used, so you can switch them freely.
In CyberPanel, go to Websites > List Websites > Manage (for the Nextcloud website)
Under Configurations, click the vHost Conf icon.
Spot the phpIniOverride
section (which should be empty) and replace it with this and hit the Save button:
phpIniOverride {
php_value mbstring.func_overload 0
php_value always_populate_raw_post_data -1
php_value default_charset "UTF-8"
php_value output_buffering 0
php_value memory_limit "512M"
php_value max_execution_time 300
php_value upload_max_filesize "1024M"
php_value post_max_size "1280M"
php_value max_input_time 600
}
(Some of these values would be debatable, be my guest!)
4. Nextcloud basic config
Edit the Nextcloud configuration file located at ~/public_html/config/config.php
(or ~/public_html/nextcloud/config/config.php
if Nextcloud was installed in the default directory).
# nano ~/public_html/config/config.php
For now, we’ll simply set the default locale/language and get rid of the ugly index.php
compound in the URLs. Insert the following lines, save and exit (CTRL+X in nano):
'default_locale' => 'en_US',
'default_language' => 'en',
'htaccess.RewriteBase' => '/',
'htaccess.IgnoreFrontController' => true,
Then ask Nextcloud to rebuild .htaccess
to account the changes (you need SSH for this).
# php ~/public_html/occ maintenance:update:htaccess
Doing so might destroy custom rules in your
.htaccess
, that’s why we do it now. You only need to run that command if you change anyhtaccess.*
value.
5. Force HTTPS (.htaccess)
In CyberPanel, go to Websites > List Websites > Manage (for the Nextcloud website)
Under Configurations, click the Rewrite Rules icon.
Right under #### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####
, paste the following:
<IfModule mod_rewrite.c>
## Forcer HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTPHOST}%{REQUESTURI} [R,L]
</IfModule>
6. Tweak and optimize your instance
There is a lot more you can do to optimize your Nextcloud instance. A good start is to login into your Nextcloud administrator account, navigate to Settings (top right menu) > Overview, and follow the recommendations that show up on that screen.