Skip to main content

Simple Nextcloud Installation on Raspberry Pi

This article explains how to install Nextcloud on the Raspberry Pi. It has been tested with the latest version of Nextcloud (13.0.4 at the time of writing), but should work for future versions too. Nextcloud is an open source software package providing remote file sharing services, similar to Dropbox. But with Nextcloud, you retain ownership, security and control of the shared data. Nextcloud works well on a Pi 2 and Pi 3 but will run very slowly on a Pi 1.
Note: This is a manual, step-by-step procedure. If you would rather do the installation automatically, please see my recent article Automatic Nextcloud Installation on Raspberry Pi, which explains how to install Nextcloud with 3 commands. It is the quickest and easiest way to get Nextcloud running. Both procedures achieve the same overall result, however.

My Raspberry Pi was purchased from RS Components in the UK. It was installed with Raspbian “Stretch” (Debian 9) by applying the image “2018-06-27-raspbian-stretch-lite.zip” downloaded from the raspberrypi.org downloads page. Raspbian Stretch was launched in August 2017, to supercede the earlier Raspbian “Jessie” (Debian 8). The following procedure works on both versions. Where there are differences, instructions applying to the both versions are provided. (Actually there is only one difference, relating to PHP packages)

Install Apache Web Server

Log into your Pi, either directly or through ssh from another system. I am using ssh. Update the software sources as follows.
$ sudo apt-get update
Install the Apache web server:
$ sudo apt-get install apache2
When asked if you want to continue, type “y” for “yes”. Apache will be installed along with a number of other packages.
In a browser, surf to the IP address of your Raspberry Pi. If you see a page entitled “Apache 2 Debian Default Page”, then Apache is running correctly on the Raspberry Pi. For example, my Pi is using IP address 192.168.1.99. So I start a browser on my PC and surf to http://192.168.1.99/. Alternatively, if you are using the Pi’s graphical desktop, you could start a browser directly on the Pi, eg. Netsurf.

Install PHP and Associated Packages

A few packages will now be installed. On Raspbian Jessie, install PHP 5. On Raspbian Stretch, install PHP 7 instead. If you are not sure what version of Raspbian you are using, check the contents of the file /etc/os-release. Here, I am using Stretch:
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
...
The version of Raspbian is clearly shown on the first line of the file.

Install PHP 7.0 and Associated Packages (Raspbian Stretch only)

On Raspbian Stretch, Nextcloud requires PHP 7 and few other packages. Install them as follows. We will use the “-y” switch this time, which answers the “yes/no” question automatically.
$ sudo apt-get -y install php7.0 php7.0-gd sqlite php7.0-sqlite3 php7.0-curl php7.0-zip php7.0-xml php7.0-mbstring libapache2-mod-php7.0

Install PHP 5 and Associated Packages (Raspbian Jessie only)

On Raspbian Jessie, Nextcloud requires PHP 5 and few other packages. Install them as follows.
$  sudo apt-get install -y php5 php5-gd sqlite php5-sqlite php5-curl
The software will be installed, along with other dependent packages.

Restart Apache

Restart the web server now with:
$ sudo service apache2 restart
The command restarts Apache, but does not print out any messages.

Install Nextcloud

Okay, the system is ready for Nextcloud to be installed. Download the latest version of the software with this command on your Pi:
$ wget https://download.nextcloud.com/server/releases/latest.zip
Now move the Nextcloud package into place and unpack it:
$ sudo mv latest.zip /var/www/html
$ cd /var/www/html
$ sudo unzip -q latest.zip
If you are curious, you can check the version of Nextcloud as follows.
$ grep VersionString nextcloud/version.php
$OC_VersionString = '12.0.4';

At the time of writing, (9th Jan 2018), the latest version is 12.0.4. To check the latest version online, have a look at the Nextcloud download page.

Create the Data Directory

You must create a “data” folder for Nextcloud and set permissions. Proceed as follows.
$ sudo mkdir -p /var/nextcloud/data
$ sudo chown www-data:www-data /var/nextcloud/data
$ sudo chmod 750 /var/nextcloud/data

Check the new directory with ls. You should see output like this, although of course your date and time will be different:
$ ls -ld /var/nextcloud/data
drwxr-x--- 2 www-data www-data 4096 May 27 18:45 /var/nextcloud/data

Set Directory Owners

Next, set the correct ownerships on Nextcloud “config” and “apps” directories:
$ cd /var/www/html/nextcloud
$ sudo chown www-data:www-data config apps


Configure Nextcloud for SQLite or MySQL

Nextcloud can use two kinds of databases: SQLite or MySQL. For a simple installation, with only one or two users, I would recommend SQLite. It is more light weight and uses fewer resources than MySQL, and is therefore a good choice on Raspberry Pi hardware. To use SQLite, skip straight to the section below entitled “Configure Nextcloud”.
If you want to use MySQL instead, proceed to Install and Configure MySQL Database.

Install and Configure MySQL Database

In order to use the MySQL database (also known as MariaDB), first install a few extra packages:
$ sudo apt-get install -y mysql-server python-mysqldb php7.0-mysql
Alternatively, if you are using the older Raspbian 8 (Jessie), use this command:
$ sudo apt-get install -y mysql-server python-mysqldb php5-mysql
Now set the MySQL root password and secure the database installation. Run the script /usr/bin/mysql_secure_installation. It will first ask you to enter the “current password for root”. No password has been set yet, so just press return to log in. Next, it asks if you want to set a root password. Answer “y“, choose a sensible password and make a note of it. Then answer “y” to all of the remaining questions, as below.
$ sudo /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
...
Thanks for using MariaDB!
Next, create a database for Nextcloud, and a database user. In the example I have called the Nextcloud user “ncuser” with a password of “raindrop”. For your own installation, choose a different user name and password. Don’t forget to take a note of both. Note that when running the following command, you will be asked to enter the root password that was set just above.
$ sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database nextcloud;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user ncuser;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> set password for ncuser = password("raindrop");
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all PRIVILEGES on nextcloud.* to ncuser@localhost identified by 'raindrop';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit;
Bye

Restart Apache

Restart the Apache web server once more with:
$ sudo service apache2 restart
The command restarts Apache, but does not print out any messages.

Configure Nextcloud

It is time to configure Nextcloud, either to use SQLite as a database, or, if you performed the commands in the last section, MySQL. Either way, proceed as follows.
In a browser, surf to your new Nextcloud web page. Use the URL:
http://your Pis IP address/nextcloud
For example, the address of my Pi is 192.168.1.99. So I go the the URL: http://192.168.1.99/nextcloud
You should see a mostly dark blue login page. In the middle is a “Performance Warning” about SQLite. Ignore that. Near the top it says “Create an admin account”. Think of a user name and password and type them into the boxes provided. Then click on the “Storage and Database” drop-down. In the “data folder” box which appears, delete what is already there and replace it with “/var/nextcloud/data
If you want to use SQLite as the database, then click on the “Finish Setup” button near the bottom of the page. Wait for a couple of minutes while Nextcloud completes the installation. During this time, Nextcloud creates more files and directories in our data directory, and it puts a SQLite database in there too.
If you want to use MySQL as the database, then where it says “Configure the database”, click on the button marked “MySQL/MariaDB”. Four new fields appear. Complete them as follows.
– for the database user, enter the name of the MySQL user you created above (“ncuser” in the example).
– for the database password, enter the accompanying password (“raindrop” in the example).
– for the database name, enter “nextcloud”
– leave “localhost” as “localhost”.
– then click on the “Finish Setup” button near the bottom of the page. Wait for a couple of minutes while Nextcloud completes the installation. During this time, Nextcloud creates more files and directories in our data directory, and it populates the MySQL database.

Completing the Configuration

Hey Presto! After a delay of 2 minutes or so, you should see the Nextcloud intro page with the slogan “a safe home for all your data”. Click the cross at the top right of the dialogue to dismiss it. You should now be looking at the main Nextcloud “Files” page. There you can see a couple of folders, a Nextcloud MP4 video file, and a PDF Manual.

Storing Nextcloud Data on a Separate Disk (Optional)

If you have a USB disk or thumb drive, you can use it to store the Nextcloud Data. In doing so, you might obtain more capacity for your data and/or improved performance.
First, mount your disk at a suitable location on the pi. Then proceed as follows. In this example, a thumb drive is mounted at “/disk1”. Move the Nextcloud data folder onto the drive as follows.
$ sudo mv /var/nextcloud/data /disk1/data
$ sudo ln -s /disk1/data /var/nextcloud/data
The first command moves the data. The second creates a link from the original data location to the new one. Finally, if you have Nextcloud open in a browser, refresh the page. It should reappear after a few moments. Your data has now been moved onto the disk/thumb drive. Try dragging a large file into Nextcloud – you should see the disk access light flash as the data is written.

Securing the Site with TLS/HTTPS

If you want to secure your Nextcloud installation by converting it from HTTP to HTTPS, see my later article: How to Convert a Website from HTTP to HTTPS.

Conclusion

That is the end of the procedure for installing Nextcloud. Your Nextcloud installation should now be fully working. I hope this guide was easy to follow and not too long or fiddly.
Note: Prior to January 2018, this article included a section on moving the Nextcloud data directory for security purposes. It is no longer necessary. Alterations to the procedure above mean that the data directory is created at a secure location and does not need to be moved.
Note: In the past, this article also included a section explaining how to increase the Nextcloud file size upload limit. This is no longer needed, as recent Nextcloud versions no longer have the old file size limitation.

Appendix – A Note on Nextcloud vs Owncloud

Nextcloud was forked from ownCloud in June 2016. Since then, Nextcloud has increased in popularity and has become, for many users, the natural successor to ownCloud. Previously I wrote an article describing how to install and upgrade Owncloud. Now, I would recommend Nextcloud over ownCloud, except for large corporate users who might already have commercial agreements with ownCloud Inc. If you came here from the ownCloud article, thank you for your patience.
END.

Comments

Popular posts from this blog

OWASP Top 10 Threats and Mitigations Exam - Single Select

Last updated 4 Aug 11 Course Title: OWASP Top 10 Threats and Mitigation Exam Questions - Single Select 1) Which of the following consequences is most likely to occur due to an injection attack? Spoofing Cross-site request forgery Denial of service   Correct Insecure direct object references 2) Your application is created using a language that does not support a clear distinction between code and data. Which vulnerability is most likely to occur in your application? Injection   Correct Insecure direct object references Failure to restrict URL access Insufficient transport layer protection 3) Which of the following scenarios is most likely to cause an injection attack? Unvalidated input is embedded in an instruction stream.   Correct Unvalidated input can be distinguished from valid instructions. A Web application does not validate a client’s access to a resource. A Web action performs an operation on behalf of the user without checking a shared sec

CKA Simulator Kubernetes 1.22

  https://killer.sh Pre Setup Once you've gained access to your terminal it might be wise to spend ~1 minute to setup your environment. You could set these: alias k = kubectl                         # will already be pre-configured export do = "--dry-run=client -o yaml"     # k get pod x $do export now = "--force --grace-period 0"   # k delete pod x $now Vim To make vim use 2 spaces for a tab edit ~/.vimrc to contain: set tabstop=2 set expandtab set shiftwidth=2 More setup suggestions are in the tips section .     Question 1 | Contexts Task weight: 1%   You have access to multiple clusters from your main terminal through kubectl contexts. Write all those context names into /opt/course/1/contexts . Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh , the command should use kubectl . Finally write a second command doing the same thing into /opt/course/1/context_default_no_kubectl.sh , but without the use of k

标 题: 关于Daniel Guo 律师

发信人: q123452017 (水天一色), 信区: I140 标  题: 关于Daniel Guo 律师 关键字: Daniel Guo 发信站: BBS 未名空间站 (Thu Apr 26 02:11:35 2018, 美东) 这些是lz根据亲身经历在 Immigration版上发的帖以及一些关于Daniel Guo 律师的回 帖,希望大家不要被一些马甲帖广告帖所骗,慎重考虑选择律师。 WG 和Guo两家律师对比 1. fully refund的合约上的区别 wegreened家是case不过只要第二次没有file就可以fully refund。郭家是要两次case 没过才给refund,而且只要第二次pl draft好律师就可以不退任何律师费。 2. 回信速度 wegreened家一般24小时内回信。郭律师是在可以快速回复的时候才回复很快,对于需 要时间回复或者是不愿意给出确切答复的时候就回复的比较慢。 比如:lz问过郭律师他们律所在nsc区域最近eb1a的通过率,大家也知道nsc现在杀手如 云,但是郭律师过了两天只回复说让秘书update最近的case然后去网页上查,但是上面 并没有写明tsc还是nsc。 lz还问过郭律师关于准备ps (他要求的文件)的一些问题,模版上有的东西不是很清 楚,但是他一般就是把模版上的东西再copy一遍发过来。 3. 材料区别 (推荐信) 因为我只收到郭律师写的推荐信,所以可以比下两家推荐信 wegreened家推荐信写的比较长,而且每封推荐信会用不同的语气和风格,会包含lz写 的research summary里面的某个方面 郭家四封推荐信都是一个格式,一种语气,连地址,信的称呼都是一样的,怎么看四封 推荐信都是同一个人写出来的。套路基本都是第一段目的,第二段介绍推荐人,第三段 某篇或几篇文章的abstract,最后结论 4. 前期材料准备 wegreened家要按照他们的模版准备一个十几页的research summary。 郭律师在签约之前说的是只需要准备五页左右的summary,但是在lz签完约收到推荐信 ,郭律师又发来一个很长的ps要lz自己填,而且和pl的格式基本差不多。 总结下来,申请自己上心最重要。但是如果选律师,lz更倾向于wegreened,