Nextcloud is an Open source cloud server application for home and businesses to host their files to access them from anywhere in the world using the internet. Here we will see the tutorial on how to install NextCloud on Ubuntu 20.04 LTS Focal fossa.
What is Next Cloud?
NextCloud is a fork of another opensource software called OwnCloud, however, it is now much popular. As I apprised above it is a server application that has the power to convert your small server such as Raspberry Pi into online storage; if you are so apprehended about your sensitive data to store them on services like Dropbox or Google Drive then you should try the Nextcloud.
Furthermore, you can use Nextcloud for video calls and edit documents with Collabora, which is based on LibreOffice.; along with support to recognize Microsoft Office formats such as DOC, DOCX, PPT, PPTX and the Open Document Format (ODF).
Those are concerned about security, the Nextcloud provides industry compliance security features such as access control to files, protection against Bruteforce attacks, two-factor authentication, encrypted storage and transfer of data.
requirements
The system requirements of NextCloud is not much high even we can run it on Raspberry pi 2.
- Linux WSL App on WIndows- Ubuntu 20.04 LTS or later version such as Ubuntu 18.04 LTS
- WSL should be enabled on your Windows 10 system.
- Nextcloud needs a minimum of 128MB RAM or recommended 512MB on your Server or Desktop,
For this tutorial, we will install the following things needed by the personal cloud server application.
- Database: MySQL 5.7+ or MariaDB 10.2 or PostgreSQL 9.5+
- Webserver: Apache with mod_php or php-fpm or nginx with php-fpm
- Php: 7.3+
Steps to install Nextcloud on WSL Ubuntu 20.04 LTS
The steps given below will also work on full-fledge Ubuntu 20.04 LTS focal fossa Linux system including other versions.
1. Enable WSL and install Ubuntu 20.04 App
Go to Windows 10 search and type “Turn Windows features on or off“, as it appears, click on it to run. There scroll down and check the box of “Windows subsystem for Linux” option and click the OK button. After enabling, the setup will ask to restart the system do it.
Now, go to open Microsoft Store on Windows 10 or use this Link to download Ubuntu 20.04 LTS Linux App.
2. Install Apache web server on WSL
Now, in the Windows 10 search box, type Ubuntu and run it.
As we know installing Apache is not a Sisyphean task on Ubuntu and the same goes for Ubuntu 20.04 Linux app running on Windows subsystem for Linux. Just run the single Linux command given below:
sudo apt install apache2
Once the installation is completed, enable and check the Apache webserver status. When it asks you to allow the Apache access through Windows 10 firewall, give it.
sudo service apache2 start
sudo service apache2 status
To check whether you can access the static page of Apache on Windows 10, open your browser and type: http://127.0.0.1
2. Install PHP on WSL (Windows 10)
The NextCloud is a PHP based application, thus we also need to set up it along with some extensions which are required for the proper working server-side application.
By default, the PHP version available to install on via the official repository on Ubuntu 20.04 LTS is the latest stable version i.e PHP 7.4. Thus, here is the command which you need to execute.
sudo apt install php php-common php-curl php-gd
sudo apt install php-json php-mbstring php-xml
sudo apt install php-zip
Some other Extensions for server performance including LDAP integration and external user authentication
sudo apt install php-ldap php-imap php-apcu php-memcached php-redis
If you are planning to use MySQL like we are going to do here then install its supported PHP extension:
sudo apt install php-mysql
In the same way, those are planning to use PostgreSQL database they need this extension:
sudo apt install php-pgsql
3. Install MySQL for NextCloud on Ubuntu 20.04
Although you can use PostgreSQL, here we are about to install the popular MYSQL database for Nextcloud, thus the command for the same will be:
sudo apt install mysql-server
By default, the Ubuntu 20.04 LTS repository contains MySQL 8.0.
Enable MySQL Service
Once the installation is done, start the MySQL service:
sudo service mysql start
sudo service mysql status
If everything is ok! you will get something like this:
[email protected]:~$ sudo service mysql status * /usr/bin/mysqladmin Ver 8.0.19-0ubuntu5 for Linux on x86_64 ((Ubuntu)) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 8.0.19-0ubuntu5 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 1 min 49 sec Threads: 2 Questions: 5 Slow queries: 0 Opens: 411 Flush tables: 3 Open tables: 27 Queries per second avg: 0.045 [email protected]:~$
Secure MySQL Installation
If you are planning to access and use it via a public network, then it is a good idea to secure the MySQL installation, first before creating users. Type:
sudo mysql_secure_installation
The above command will run a script to secure MySQL installation in which it gives you series options such as enabling password validation component; removing of anonymous users; disable remote root login; set a root password (blank by default); deleting demo database table and more…
You can know more about this on our detail guide of MySQL installation on Ubuntu 20.04 server.
Create a Database and user for NextCloud
“If you have secure and set a password for MySQL then use that one here”
sudo mysql -p
The command to create a database and user.
CREATE DATABASE db_name_here;
Note: Replace db_name_here with the database name you want to give it.
CREATE USER 'h2suser'@'localhost' IDENTIFIED BY 'pass';
Grant rights to manage database activities to the user you have.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON db_name_here. * TO 'h2suser'@'localhost';
Note: Replace the h2suser with the username and pass with the password you want to assign.
exit
4. Download NextCloud
By the time, we are writing this article the latest version of the Nextcloud server edition available to download was 18.04, thus we get the same for installation.
Visit the Download page and get its zipped file.
or use
wget https://download.nextcloud.com/server/releases/nextcloud-18.0.4.zip
Extract Downloaded zipped file
The downloaded file of our was in zipped format thus, we also need a small program for that:
sudo apt install unzip
Now,
sudo apt unzip nextcloud*.zip
After inflating, move the file to Apache public folder
sudo mv nextcloud /var/www/html/nextcloud/
Create a data folder inside the copied folder
sudo mkdir /var/www/html/nextcloud/data
Set the permissions for the copied Nextcloud directory
sudo chown -R www-data:www-data /var/www/html/nextcloud/
sudo chmod -R 755 /var/www/html/nextcloud/
5. Create nextCloud configuration file for Apache
By default, the Apache has the configuration file that points it to use the files available under the /var/www/html folder, we can edit that file to point it to our nextcloud directory inside the HTML folder. However, it is a better idea to create a separate configuration file, in case you are planning to host multiple websites.
sudo nano /etc/apache2/sites-available/nextcloud.conf
Copy-paste the following lines in that file.
Note: If you are want to use custom domain then replaced your.server.com in the following with your domain name and update the DNS record for the same.
<VirtualHost *:80> DocumentRoot /var/www/html/nextcloud/ ServerName your.server.com Alias /nextcloud "/var/www/html/nextcloud/" <Directory /var/www/html/nextcloud/> Options +FollowSymlinks AllowOverride All Require all granted <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/html/nextcloud SetEnv HTTP_HOME /var/www/html/nextcloud </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
To save and exit above nano editor, first press CTRL+O and then CTRL+X.
Enable the newly created site:
sudo service apache2 reload
sudo a2ensite nextcloud.conf
Enable Apache Modules for Nextcloud
However, in most of the cases the following modules will automatically get enabled, yet to confirm run the below command:
sudo a2enmod rewrite headers env dir setenvif mime
Restart Apache
sudo service apache2 stop
sudo service apache2 start
6. Configuring NextCloud server on Ubuntu 20.04 WSL App (Windows 10)
Finally, we are at the final stage of NextCloud setup using GUI. Open the browser on Windows 10 and type http:127.0.01/nextcloud
Note: If you get a message “Your data directory and files are probably accessible from the internet because the .htaccess file does not work. For information on how to properly configure your server, please see the documentation.”
To remove that follow the below steps. This appears because the .htaccess file of the Nextcloud would not be able to override the default Apache configuration thus we directly edit that.
sudo nano /etc/apache2/apache2.conf
Scroll down and find these line:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Now, replace the AllowOverride None to AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Finally, you will have error-free NextCloud login screen.
7. Login Nextcloud
Finally, enter the username and password you want to register as ADMIN account for NextCloud and then furnish the Database details. Last, click on the Finish Setup.
Finally, you will have the Dashboard:
Change Data Folder (Optional step)
By Default, whatever data we upload to NextCloud will go to its data folder that is at /var/www/html/nextcloud/data
, it is in the root directory; so, Ubuntu WSL is in the C drive of the Windows 10, therefore NextCloud will consume your C: Drive to store all the uploaded files. However, we can change.
Here I going to move the data folder from my C: Drive to G: Drive of the system, so all the uploaded files will consume my G: Drive Space and C: drive will remain free.
sudo cp -r /var/www/html/nextcloud/ /mnt/drive-name
Replace the drive-name the one where you want to save your all files.
For example, I want it on G drive thus the command in my case was like this:
sudo cp -r /var/www/html/nextcloud/ /mnt/g
Now, edit the NextCloud Config file:
sudo nano /var/www/html/nextcloud/config/config.php
Here find the line:
'datadirectory' ='/var/www/html/nextcloud/data'.
Replace the current directory location with one where you have copied the data folder.
For example, I have compiled it at /mnt/g/data. Thus, I have used the same. You can see that in the below screenshot.
After that save it: CTRL+O and to exit CTRL+X.
Change the permission of your new data location:
sudo chmod 0770 /mnt/g/data
sudo chown -R www-data:www-data /mnt/g/data
Note: Replace /mnt/g/data with the location of your folder.
So, this was the quick tutorial on installing NextCloud on Ubuntu 20.04 WSL Linux app on Windows 10.
Hi thank you so much for this guide!! I have followed the entire guide step by step and everything works like a charm. Now I would like to move the “data” folder on a different hard drive (ntfs) as suggested at the end of the article. I tried the steps but every time I reboot the WSL machine I get the error: “Your data directory is readable by other users
Please change the permissions to 0770 so that the directory cannot be listed by other users.”
Do you know how to fix this problem? Thank you so much
I found solution googling a bit… just add ‘check_data_directory_permissions’ => false, into “config.php”. This solved the problem.
Hi Thanks for this post!!
I’m having problems with step 5. Create nextCloud configuration file for Apache.
I made the config file but when I try to reload I get the following message:
* Reloading Apache httpd web server apache2 *
* The apache2 configtest failed. Not doing anything.
Output of config test was:
AH00526: Syntax error on line 10 of /etc/apache2/sites-enabled/nextcloud.conf:
Illegal override option Require
Action ‘configtest’ failed.
The Apache error log may have more information.
I don’t know what to do with this.. I’ve tried looking it up, but alas.
Could you please help?
Same here
Domenico, try this:
AllowOverride All
Require all granted
Any tips on how to access this from another computer on LAN?
Can’t seem to connect via IP on this setup.. unless maybe wiser to opt a different route for that? (VM etc)
Just make sure the port number of OwnCloud has been opened in the windows firewall and if you also have enabled the firewall on Ubuntu WSL, then allow the port their as well.
Thanks a lot for this tutorial. But idk how to sync with my android phone and put a static IP because it’s using localhost and 127….
You need to set the static IP address to your Windows 10 PC where WSL has been installed. WSL will automatically start using the IP address.