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 (20.1 at the time of writing), but should work for future versions too.  It has also been successfully tested on the latest Pi hardware, the Raspberry Pi 4, and on earlier Pi versions, and on the latest OS, Raspbian/Raspberry Pi OS 10 “Buster”.  Article last updated 21/6/2021.

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, Pi 3 and especially a Pi 4 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 4 was purchased from The Pi Hut in July 2019. It was installed with Raspberry Pi OS (Raspbian) 10 “Buster” by applying the image “2021-05-07-raspios-buster-armhf-lite.zip” downloaded from the raspberrypi.org downloads page.

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. Chromium or Netsurf.

Install PHP and Associated Packages

A few packages will now be installed, including the latest version of PHP (7.3 at the time of writing).

Issue the following command. We will use the “-y” switch this time, which answers the “yes/no” question automatically.

$ sudo apt-get -y install php php-gd sqlite php-sqlite3 php-curl php-zip php-xml php-mbstring libapache2-mod-php

The software will be installed, which takes a few minutes.

Restart Apache

Restart the web server now with:

$ sudo systemctl restart apache2

The command restarts Apache, but does not print out any messages.

Download Nextcloud

Okay, the system is ready for Nextcloud to be installed. Download the latest version of the software as follows.

$ wget https://download.nextcloud.com/server/releases/latest.zip

Unpack Nextcloud

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

Unzipping takes a minute or two.

If you are curious, the version can be be checked with:

$ grep VersionString nextcloud/version.php
$OC_VersionString = '21.0.2';

At the time of writing, (June 2021), the latest version is 21.0.2. 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, especially if you are using a P 2 or a Pi 3. 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”.

On the other hand, if you want to use MySQL instead, proceed to Install and Configure MySQL Database.  MySQL is an appropriate choice for larger installations, if you plan to have more users, and particularly if you are using a Raspberry Pi 4.

Install and Configure MySQL Database

In order to use the MySQL database (also known as MariaDB), install it now, along with an extra php package:

$ sudo apt-get install -y mariadb-server python-mysqldb php-mysql

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 57
Server version: 10.3.29-MariaDB-0+deb10u1 Raspbian 10

Copyright (c) 2000, 2018, 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.001 sec)

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

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

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

MariaDB [(none)]> exit
Bye

Restart the Apache web server once more with:

$ sudo systemctl restart apache2

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 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

While the installation runs, a dark blue “Recommended apps” box will appear, and a few Nextcloud add-ons are installed.  It takes a few minutes, so be patient.

A few minutes later,  you should see the Nextcloud intro page with the legend “Nextcloud Hub”.  Click the right arrow to read more, or click the cross at the top right of the dialogue to dismiss it. You should now be looking at the main Nextcloud page. There you can see a few widgets, such as “Recommended files” and “Talk mentions”.

Congratulations!  You have successfully installed Nextcloud!


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.

174 thoughts on “Simple Nextcloud Installation on Raspberry Pi

  1. Pingback: Simple Owncloud Installation on Raspberry Pi 2 | Unix etc.

  2. this worked great for me thank you for all your time in making this guide. i have a 1tb hard drive connected to my raspberry how do i make next cloud save the files to my hard drive not the sd card? thanks

  3. Hi Cody. All that is needed is to (1) reformat your 1 TB drive and then (2) Move the Nextcloud “data” directory onto it. (WARNING: reformatting the 1 TB drive will destroy any data already existing on the drive).

    For a more detailed guide on this, see the accompanying Owncloud article – scroll down to the section entitled “Move the Owncloud Data Directory (optional)”.

    • Thank you i have everything working great and moved over to my hard drive. Is there a part in the guide where i can log into my nextcloud without being on the nextwork? i have my ports forwarded but i dont know how to go to “192.168.0.21/owncloud” i also have a no-ip for my DNS ip. thanks again your guide was the best guide ive read.

      • Hi Cody. Unfortunately I don’t understand the question about being able to log into Nextcloud “without being on the network”. You should be able to obtain a domain name from no-ip, point it to your IP address and then access Nextcloud by name.

      • This applies to the April 2020 timeframe: There is a problem installing php-curl in Raspian Buster. It wants to see libcurl3, but php currently installs libcurl4. When I tried to force install of libcurl3, then apt “helpfully” removed apache2. GRRRRR! You can force php7.3 to install, but the control file (packaged in the php7.3-curl_yada_yada.deb file) contains a Depends:…. php7.3-common (= 7.3.14-1~deb10u1),… statement, and won’t install due to newer ‘common installed with php7.3. By changing the ‘=’ to ‘>=’ and repackaging under a new name (eg. php-curl_fixed.deb) then I was able to apt (no -get) php-curl_fixed.deb, and finally make nextcloud happy.
        To do this, you may need to research how to unpack and repackage a .deb file…I’m not including that, because I’m a noob, and would probably explain it wrong. I think this kludge may break the upgrade process if TPTB don’t update the .deb file.

        nextcloud18 can use php7.4, but php7.4 also has broken dependencies for both php-curl AND php-mbstring, as well as a few others that nextcloud needs. By reverting to php7.3, I only had to fix the ‘cURL issue.

        • Hi Kevin
          I have just repeated the procedure up to the point of the php-curl install, using the latest (Feb 2020) release of Raspbian, and it completes without error. So, a couple of questions:

          – Are you using a fresh installation of Raspbian ?
          – At which procedure step did you first encounter an error?
          – What was the *exact* error text?

          Also, I am not quite sure why your post was made in reply to an unrelated matter from another reader.

          Cheers,
          Jim

    • Hello Cody,
      I’m having annoying trouble sorting out my external drive. Everything works perfectly until I try to move nextcloud data on to a separate disk. I used the following commands as this is how my disk is mounted, am I doing it right?
      sudo mv /var/nextcloud/data /media/pi/UNTITLED/data
      sudo ln -s /media/pi/UNTITLED/data /var/nextcloud/data

      When I visit the nextcloud page at 192.168.1.200/nextcloud I just get a blank page.

      Any help much appreciated. 🙂

      • Hi Mike,

        I am not sure whether your question was for me or Cody. Sorry about the late reply. Anyway your commands look fine, and I am not sure why you would see a blank page.

        Cheers,
        Jim.

      • Hi,

        If anyone comes across this, here is what worked for me:

        sudo mv /var/nextcloud/data /media/pi/UNTITLED/
        sudo ln -s /media/pi/UNTITLED/data /var/nextcloud/data

        Otherwise you copy the folder data into /media/pi/UNTITLED/data and your files will be stored at /media/pi/UNTITLED/data/data.

        Hopes this helps anyone.

        Regards,
        Christian

        • Hi, Christian!

          Thank you very much for your response, it took me off the white screen.

          In my case I’ve a external hd mounted in /mnt/usb, so I used:
          $ sudo mv /var/nextcloud/data /mnt/usb
          $ sudo ln -s /mnt/usb/data /var/nextcloud/data

          But now I have an error saying:
          “The data directory is readable to other users
          Please change permissions to 0770 so the directory can not be read by other users.”

          I have already tried using chmod 0770 in /var/nextcloud/data but the error persists.

          Please, can you help me? Thanks.

          • Hi Rodrigo, thanks for commenting. Your “mv” and “ls” commands should work. I am not sure why you are getting the 0770 errors. Check out my comments to Christian, below.

        • Hi Christian. Thanks for coming back and sorry for the lateness of this reply. Care is needed with the Linux “mv” command. Because of the way the command works, it is easy for confusion to arise, even for experienced Linux users. The commands in the article:

          $ sudo mv /var/nextcloud/data /disk1/data
          $ sudo ln -s /disk1/data /var/nextcloud/data

          … will work if typed exactly. The mv command moves the last sub-directory only, ie just the “data” bit in this case. So what you end up with here is /disk1/data. It is important, although not mentioned in the article, that a directory of the same name does not already exist at the target. Let’s say that your disk already happens to contain a directory called “/disk1/data” and you type the mv command above. In this case your data would be moved to /disk1/data/data, leading to an eventual failure of Nextcloud. The mv command “sees” the directory already existing at the target and “helpfully” moves your sub-directory into it.

          So, mv can be confusing to experts and novices alike, and care is needed when using it.

  4. Hi Jim! Thank you for this perfect description to install nextcloud!! Do you know how I can use the usb storage at my pi. I just don’t know how to mount it? Thanks for your answer, Johannes.

  5. Thank you , thank you. Your article represents my fourth attempt at getting a local cloud server up and running on the Rpi. Needless to say , the others failed at some point. Your’s is clear and absent any typos! Grats. Everything went great until… I attempted to access the server from a different computer on the same network ( e.g. the server is at 10.0.0.30 and the other computer is at 10.0.0.4 ). No response from the Rpi. Any suggestions?

    • no-ip.org

      sign up there.
      Setup port forwarding on your home router.
      If your home router supports ddns then you put in your username and password for no-ip.org into your router and it keeps it up to date.

    • Hi Igor, to access Nextcloud from outside your home, 2 steps are needed:

      1. On your modem/router, forward port 80 to the Pi containing Nextcloud.
      2. As Randell says, obtain a domain name from no-ip or another provider. You can access Nextcloud without a domain, simply by surfing to your router’s external IP address. But this IP address changes every few days, so it is more convenient to obtain a domain name.

      Note that there are security implications if you forward the port as in step (1). For more information, see the section entitled “A Note on Security” in my partner article: http://unixetc.co.uk/2015/02/21/simple-owncloud-installation-on-raspberry-pi-2/

  6. Hi,

    Would like to ask if you could also guide me in making nextcloud more secure? I heard that using http (which this guide is using) is not really that secure.

    I also would like to ask how to configure the email notification in nextcloud.

    I also have setup a pi-hole on my pi so not sure if this will conflict anything

  7. Regretably however, at the end of the process after entering username and passwd nextcloud came up with a blank page, what has gone wrong?

    • Hi Debonaire,

      A blank page at the end of the process ? Blank pages can be tricky to diagnose, but they sometimes happen due to PHP errors. Have a look at the apache error log file /var/log/apache2/errors.log.

      Type this show errors at the end of the log:
      tail /var/log/apache2/error.log

      …then try to log in to Nextcloud again, so that the white screen comes up again.

      And repeat the command:
      tail /var/log/apache2/error.log

      Did any new error messages show up ?

      • Wow, many thanks for volunteering help,I amimpressed and grateful. I reinstalled nextcloud and set the data directory to my USB HD. Now the problem is that nextcloud is insuferably slow to come up. It lookslike the USB disk is accessed but just ‘spins’ for minutes before loading the page. I will try to point nextclud back to the sd card datadirectory andseewhathappens.

  8. Pingback: Setting up NextCloud on Raspberry Pi 3 | David R. Wilson

    • Hi David, you report that UBlock Origin interferes with Nextcloud under Chrome. I use UBlock Origin in Firefox, and with that setup, it does not seem to block Nextcloud.

    • Thanks for the suggestion I do not think that I am running UBlock in my laptop’s firefox and I get the same from th eEpiphany browswer on the pi. I think the problem is somewhere in the output of the tail command listed below

    • Hi David. I get the page shown on the link from your blog. When I switch off Ublock Origin in Chromium I still get the same result. I’ve also tried in Safari on Mac and old and new iPads with the same result. Also, when I installed Php5 I got a message suggesting it wasn’t found. Can I use Php7 insread?

      Kate.

  9. Hi Jim,

    As I said above, I pointed nextcloud to the data directory on the sd card! Now I am back to the blank page. Following your instructions I issued the ‘sudo tail /var/log/apache2/error.log’ command. Here is what the command spews out:

    [Sun Feb 05 14:33:05.893221 2017] [:error] [pid 3456] [client xxx.xx.xxx.211:40444]
    PHP Fatal error: Uncaught exception ‘Doctrine\\DBAL\\DBALException’ with message
    ‘Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000]
    [14] unable to open database file’ in /var/www/html/nextcloud/lib/private/DB/Connection
    .php:60\nStack trace:\n#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/
    Doctrine/DBAL/Connection.php(973): OC\\DB\\Connection->connect()\n#1 /var/www/
    html/nextcloud/lib/private/DB/Connection.php(215): Doctrine\\DBAL\\Connection->
    executeUpdate(‘PRAGMA read_unc…’, Array, Array)\n#2 /var/www/html/nextcloud/
    3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(621): OC\\DB\\Connection->
    executeUpdate(‘PRAGMA read_unc…’)\n#3 /var/www/html/nextcloud/lib/private/DB/
    Connection.php(147): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#4 /
    var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php
    (172): OC\\DB\\Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\
    PDOSqlite\\Driver), Object(Doctrine\\DBAL\\Configuration), Object(Doctrine\\
    Common\\EventManager))\n#5 / in /var/www/html/nextcloud/lib/private/DB/Connection.
    php on line 60, referer: http://somesite.com/nextcloud/
    [Sun Feb 05 14:33:05.904833 2017] [:error] [pid 3456] [client xxx.xx.xxx.211:40444]
    PHP Fatal error: Uncaught exception ‘Doctrine\\DBAL\\DBALException’ with message
    ‘Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [14]
    unable to open database file’ in /var/www/html/nextcloud/lib/private/DB/Connection.php:60
    \nStack trace:\n#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/
    Connection.php(973): OC\\DB\\Connection->connect()\n#1 /var/www/html/nextcloud/lib/
    private/DB/Connection.php(215): Doctrine\\DBAL\\Connection->executeUpdate(‘PRAGMA read_unc…’,
    Array, Array)\n#2 /var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.
    php(621): OC\\DB\\Connection->executeUpdate(‘PRAGMA read_unc…’)\n#3 /var/www/html/nextcloud/
    lib/private/DB/Connection.php(147): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#4 /
    var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\\DB\\
    Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\PDOSqlite\\Driver), Object
    (Doctrine\\DBAL\\Configuration), Object(Doctrine\\Common\\EventManager))\n#5 / in /var/www/html
    /nextcloud/lib/private/DB/Connection.php on line 60, referer: http://somesite.com/nextcloud/

    There is obviously lots wrong…

    • Hi Debonaire,

      The output above is basically the same (long) line repeated twice, showing that Nextcloud cannot connect to the database. Here is the significant bit: “SQLSTATE[HY000] [14] unable to open database file”.

      This is why you get the blank screen. It is difficult to say what the problem is with the database. Did you make any changes apart from what is in the procedure ? I would try repeating the procedure from the start and see if it works.

  10. Just to let everyone who will follows this thread just follow Jim’ s instructions line by line and Nextcloud will be installed no problems. Jim is a real Posix man…

    • Will this replace an existing but non-functional installation of nextcloud? Let me describe where I have arrived at, As Ii said in my previous comment, follow Jim’s instructions and all will go well. The rub is that once you transfer the nextcloud data directory to an external USB HD, nextcloud fails, you get a blank page! The installation worked very well from the SD card,but the storage capacity even with my 64 GB card is limited, hence why I chose to trnasfer to USB storagedevice. I followed Jim’ s instructions from his owncloud tutorial, substituting nextcloud references for owncloud references.

      Here is what the sudo ls -l /myusbdisk/nextcloud/data lists after a lengthy wait accessing the disk:

      ls: cannot access /mnt/nextcloud/data/owncloud.db-shm: Structure needs cleaning
      ls: cannot access /mnt/nextcloud/data/owncloud.db-wal: Structure needs cleaning

      The listing after that makes sense, showing users etc…

      In any case good on you Nachoparker for helping the community

      • Hi Debonaire, note that the error message “Structure needs cleaning” is quite unusual in Linux, and needs your attention. It comes from the EXT4 file system, and indicates file system corruption. I would recommend fixing it before continuing to use the disk. Personally I’ve not encountered the “Structure needs cleaning” error, but it doesn’t seem too difficult to repair. Search on Google or check this out:

        https://www.reddit.com/r/linuxquestions/comments/4b47r2/has_anyone_ever_gotten_structure_needs_cleaning/

        Jim.

        • After tinkering on and off this is what I conclude. As I said above everything works fine if all is on the sd card, specifically data in /var/nextcloud/data and the config.php file in /var/www/html/nextcloud/config, again on the sd card. The reason the data directory was moved to /var/nextcloud comes from Jim’ s suggestion in the tutorial… I think there is more to transferring the data directory from the sd card at /var/nextcloud/data to a USB drive at say /mnt/nextcloud/data and changing the config.php to point to the USB directory. Config.php in my installation -which follows the above instructions- sits at /var/www/html/nextcloud/config. I think this may be the problem, it should be elsewhere, but I could be wrong. Any suggestions are welcome…

          • Hi Debonaire

            The correct location of the config file is /var/www/html/nextcloud/config/config.php, as detailed in the procedure. Cheers, Jim

  11. Thanks to all, Jim especially and you Nachoparker. These exhanges are very civilized and non-hostile, as is too often the case on web forums.

  12. This install went absolutely painlessly on my rpi. Thanks!

    Now to figure out how to get it to share a calendar amongst the user accounts. The necessary section for the manual hasn’t been written yet.

    • Great, Karsten. The calendar sharing function still seems a bit doubtful on Nextcloud. They will probably get it running properly in a couple of months. You might have to upgrade though. Jim.

  13. Thank you Jim for this article, I’ve installed NextCloud on my 120GB SSD giving me over 100GB of available storage and it’s fast too 🙂

    I made a folder in /home/”username”/cloud-data to keep it away from the default site and just did:
    sudo chown -R www-data:www-data /home/”username”/cloud-data

    I did this before I created the admin.

    Now to find a https tutorial 🙂

    Thanks again,
    Darron

  14. Great tutorial!

    But I got stuck at

    Change this line:
    ‘datadirectory’ => ‘/var/www/html/nextcloud/data’,
    to this:
    ‘datadirectory’ => ‘/var/nextcloud/data’,

    Basically screwed up the vi editing. Can I get some tips on how to go about doing that?
    thanks.

    • Hi Ak. Sorry to hear the edit did not go right. Having followed the procedure, you should have a backup file, created just before the edit, called “config.php.org”. Just delete your messed up file and copy the original back into place:

      $ cd /var/www/html/nextcloud/config
      $ sudo rm config.php
      $ sudo cp config.php.org config.php

      and try the edit again:

      $ sudo vi config.php

      If you don’t like vi, try another editor.

  15. Thank you very much for the great tutorial!
    I just have a question regarding the use of SQLite as the DB. Since during the the completion of the Nextcloud setup on the web interface it is written that SQLite is not recommended for Nextcloud. Since the performance is supposed to be worse than MySQL.
    Will I have huge performance problems with SQLite? Since I will be the only user on my Nextcloud at the moment and in my short upload and download tests the performance was satisfactory for my use.

    Thanks in advance.

    • Hi Carello. With a small system such as a Raspberry Pi, SQLite is an appropriate choice. MySQL is a powerful database system, much more sophisticated than SQLite, and is usually intended for much bigger workloads. MySQL also uses more system resources such as CPU and memory, and is more complicated to set up. As you are the only user, the performance of SQLite should be fine. I don’t think performance would be any better with MySQL. But both will work.

  16. Hello everyone…

    I thought it appropriate to bring things referred to in my comments to a conclusion. I was finally able to get Nextcloud to work on an external HD, i.e. where the data is stored. I don’t know exactly what errors I may have made in my first try or two. My advice is to really mind mounting the USB drive permanently in the first instance, lots of info. out there on that. Then proceed to copy the data directory from the sd card to the USB drive and changing the entry in the config.php file.

    All that is in Jim’ s tutorial works well…

  17. Hi,

    Would like to ask how to update nextcloud if there is an update. currently there is an update 11.0.2 and i want to update to that. please help

    • Hi Ace. Unfortunately I haven’t yet written a section for updating Nextcloud. All I can suggest is starting from the beginning with a fresh Pi install and the latest version of Owncloud.

      • that sucks as i have already started and have put alot of time personalizing the contacts page and other things. feelsbadman

        • Hmm. Well, if you check my earlier (and now obsolescent) article on installing Owncloud (Nextcloud’s predecessor), here: http://unixetc.co.uk/2015/02/21/simple-owncloud-installation-on-raspberry-pi-2/, there is a section called “Upgrading Owncloud to Vsersion 8.2.2 (on Wheezy)”.

          Although the versions are out of date, the same basic procedure will *probably* work for upgrading to Nextcloud 11.0.2. Remember the old procedure was for Wheezy, so the paths change from /var/www to /var/www/html.

          Cheers,
          Jim

          • btw. I simply updated to 11.0.2 from my web-interface, logged in as the admin.
            Went perfectly fine. So, I’m not sure why the frustration. Just go ahead and follow the instructions.

  18. Hi, I was going to backup my nextcloud install following the official guide: https://docs.nextcloud.com/server/9/admin_manual/maintenance/backup.html
    Backing up the data directory was straight forward. But I struggle with the database.
    Maybe I have an old version of your script but I only seem to have mysql installed and not sqlite3.
    Also, I’m not sure what Database I would have to backup? All three (mysql, sqlite, postreSQL)? Or only one of them? Do you have any advice?

    • btw, I just realized that I have the mysql version installed. So, I guess I would only have to backup mySQL doing this:

      mysqldump –lock-tables -h [server] -u [username] -p[password] [db_name] > nextcloud-sqlbkp_`date +”%Y%m%d”`.bak

      Now (I fell very silly) where do I find the ‘server’, and ‘db_name’? Any idea?

      • Hi Filippo. You can tell if MySQL is running by just looking for the process:

        $ ps -elf | grep -i mysql

        Your server would just be the local machine (your Pi), 127.0.0.1. Regarding the database name, it is set during installation. By default it is “nextcloud”, try that.

        Incidentally, I backup MySQL by stopping the database, taking a copy of the database files, starting the database again (so that it was only down for a short while), then backing up the copied files, eg.

        $ sudo /etc/init.d/mysql stop
        $ sudo tar -cf /var/lib/mysql.tar. /var/lib/mysql
        $ sudo /etc/init.d/mysql start

        Then I just copy the file /var/lib/mysql.tar off to some backup location.

  19. Pingback: Personal cloud storage on the Orange Pi - Pi Projects

  20. Thanks for the help, but I’m stuck at this point:

    sqlite> update oc_storages set id=”local::/var/nextcloud/data/”
    …>

    why?

  21. Hi Jim. I have a feeling that I have the same problem as Vincenzo. The error I receive is: Error: no such table: oc_storages. Any help would be appreciated.

    • Hi Andy. I am not sure why it would say “no such table”. However, if that part didn’t work, I don’t think it is a big problem. Your Nexcloud installation will likely work anyway, even without those SQLite commands.

  22. Like a poster above, I’ve tried a few tutorials on installing NextCloud and agree completely that yours is far and away the clearest and cleanest out there… thank you for the great tutorial and also for your continued Q&A access.

    I do have a question about the sqlite commands in the “Secure the Nextcloud Data Directory” section.

    Re: the command – “sqlite> update oc_storages set id=”local::/var/nextcloud/data/” where id like ‘%local%’;”

    My moved my data file to an external USB drive ” /disk/nextcloud/data” . Is that still considered “local”? Do I just replace “/var” with “/disk”?

    Thanks,

    ScottM

  23. Hi Jim, thank you very much for such detail instruction. I was able to get everything working with RP3 + 2 TB External USB HDD formatted with EXT4. The only problem if I restart my RPi3 the HDD becomes unmounted so I cannot access nextcloud until I manually remount the HD. Is there a detail command line to make the HD auto mount if the RPi restart. Thanks in advance.

    • Hi Sam. Is there an entry in /etc/fstab for the disk? If not, add line to the /etc/fstab file, something like this:

      /dev/sdb1 /var/nextcloud ext4 defaults 0 0

      …where “/var/nextcloud” is the place you want to mount the disk, and “/dev/sdb1” is disk device. You can then mount the disk by just typing “sudo mount /var/nextcloud” (or whatever mount point you have chosen). It should also mount automatically at boot.

  24. Thank you very much Jim for the quick replied. This is what I have in the /etc/fstab:
    proc /proc proc defaults 0 0
    PARTUUID=f5a7a508-01 /boot vfat defaults 0 2
    PARTUUID=f5a7a508-02 / ext4 defaults,noatime 0 1
    # a swapfile is not a swap partition, no line here
    # use dphys-swapfile swap[on|off] for that

    Then I added this line at the bootom, safe and exit:
    /dev/sdb1 /disk/nextcloud ext4 defaults 0 0

    Next when I type:
    sudo mount /disk/nextcloud

    this is what I got:

    mount: special device /dev/sdb1 does not exist

  25. Hello Jim, thank very much for your help. I finally got it working (2 TB USB HDD auto mount even the RP3 reboot) by following your suggestion above. What I did was adding this line:

    /dev/sda1 /disk/nextcloud ext4 defaults 0 0

    in /etc/fstab then safe and exit. Then mount the drive.

    Now the last thing to do is to setup HTTPS. Any suggestion? (I’m new to linux) 🙁

    • Glad you have got the mount working, Sam. /dev/sda1 is the device of your disk, so now it mounts properly.

      Converting a website to HTTPS is quite a long procedure. Sooner or later I will write an article on that, but I haven’t had time yet.

      Cheers,
      Jim

      • Hello Jim,
        Yes, got everything working working then messed it up while trying to set up https with letuscript. Good thing I have image the working sd card. So just need to burn the backup image back to sdcard.
        Waiting for your excellent instruction on setting up https and accessing from outside. Have a good day!

        • Cheers Sam, I will write that article some day, and put a note about it here. It is good that you have an image to “roll back” to, and demonstrates the importance of backups!

  26. Hello,
    I don’t know if what I’s like is possible but I’m sure you’ll have a quick answer for me.
    I would like to store my data at home without encryption and have an automatic backup on a Google drive with encryption. Or even store an encrypted copy on a friend cloud (and he will store his files encrypted at my place).

    • Hi zurpa, pardon the delay in replying. I am not a user of Google drive, and so it is difficult to advise. The general principle would be to encrypt your data and then send it to Google drive. Most backup tools offer encryption. Try to set your backup program to use Google drive as the backup target, and turn on encryption. Cheers, Jim.

  27. I have also moved my data to another mounted location.
    Upon running the below and attempting to update the SQLite table with:
    “update oc_storages set id=”local::/var/nextcloud/data/” where id like ‘%local%’;”

    I get the error “Error: no such table: oc_storages” and now my nextcloud installation will not work, if I attmept to head to xxx.xxx.xxx.xxx/nextcloud it get :
    “Internal Server Error
    The server encountered an internal error and was unable to complete your request.
    Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
    More details can be found in the server log.”

    Any help would be appreciated !

    • Hi Nathan. The update command failed because it could not find the oc_storages table. The command terminated without making any changes, so it will not have been the cause of the “internal server error”. To get more information, load the web page again. When the “internal server error” message appears, check the Apache error log as follows:

      $ tail /var/log/apache2/error.log

      Some helpful message should then appear in the terminal, allowing the problem to be diagnosed.

  28. This procedure worked like a charm, and I managed to successfully move data to the external drive.
    I did run into a few issues, but it was all my bad – typos were the basic issue. Also, Nathan if you have moved the data folder to an external drive then the path will no longer be /var/, it will change to your mounted media /media/ or /sda?/…. I was getting the same error. I also found out that the permission had to be re-setup as you moved physical drives – they don’t automagically inherit across physical devices… go figure in this day and age…
    Anyway, setup the permission with CHMOD and then CHOWN, make sure the path is corrected to the mounted drive /media/… and you should be good to go!
    Thanks for the tutorial, and NextCloud is so much better than OwnCloud – smoother 😉

    • Cheers David, glad it worked. In a few days I will be publishing an another article to do the Nextcloud installation automatically.

  29. When i try to access the nextcloud site on a different host on the same network, I get this error

    <?php
    /**
    * @copyright Copyright (c) 2016, ownCloud, Inc.
    *
    * @author JÃķrn Friedrich Dreyer
    * @author Lukas Reschke
    * @author Morris Jobke

    I tried to give the .htaccess apache2.conf file Allowoverride all access but that didn’t seem to help

    Any ideas?

    • I should also mention that I am going to http://ipofnextcloud/nextcloud and it redirects to http://ipofnetcloud/nextcloud/index.php

      That is where I get the error.

      If I go to …/nextcloud/index.php/login I can get to the login page however it won’t let me login. I feel I missed something in your guide but I have checked it over and over again.

      Also how do I ensure I allow outside access to this host in regards to “trusted domains.” Is that the host in the html header or is something else?

      • Hi Ginger. What you are seeing is the contents of the Nextcloud’s “index.php” file. Rather than execute the file, your Pi is simply displaying it. The problem might be that you haven’t installed PHP. Please check. Type “php –version” at the shell propmpt and see what it says.

        If PHP is not installed, please repeat the commands to install it from the procedure.

        (NB I removed most of the file from the your comment to save space)

        • Jim,

          Thanks for the help. When I type the command I get the display

          PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )

          When I go to http://ip I get the apache display.

          • Hi Ginger. Well you definitely have PHP installed. I am not sure what the problem might be. All I can suggest is to start again from the beginning of the procedure. Alternatively, you might like to try a new procedure I published a few minutes ago. It installs Nextcloud, exactly as above, but in an automated way. In fact, you just have to type 3 commands. Here it is: Automatic Nextcloud Installation on Raspberry Pi. Give it a try. (Note it is best to start from a fresh Raspbian install).

  30. Pingback: Automatic Nextcloud Installation on Raspberry Pi | Unix etc.

  31. Looks like I have an different error. I got as far as issuing the sqlite update oc_storages.id and get this error:

    Error: UNIQUE constraint failed: oc_storages.id

    Any clues as to what has happened? Followed the instructions otherwise to the letter to that point except that the most recent version of nextcloud is now 12.0.4.

    Appreciate any help!

  32. Hi Steve. That is strange. Apart from seeing this error, does Nextcloud work properly ? (Although the procedure includes the above step, it might not be strictly needed for Nextcloud to work).

  33. If I set the data directory back into /var/www/html/nextcloud then everything seems to work just fine. Not that I have much in the cloud just yet, but I can navigate the Nextcloud site without difficulty.

    • Ultimately, I’d like to have the data reside on an external hard drive – not sure if that makes a difference, since the trouble seems to be with reassigning the data directory within sqlite.

      • Hi Steve, not sure why that would be. Incidentally, I will be re-writing the above procedure soon, so that the data directory is already at the preferred location, and there is no need to move it.

  34. Hi there, i just wanted to say thank you for making this article. I tried to make a nextcloud server using articles but this has been the best and explained it the best to me. Thank you!

    • I got it
      Problem be that I haven’t installed PHP… but i’ll have another one:
      When i’ll try make Admin account, i don’t have permission to /var/www/html/nextcloud/data

    • ok… this is simple too

      ill create like in this tutorial
      sudo mkdir -p /var/nextcloud/data
      and add privileges
      sudo chmod 750 /var/nextcloud/data

      but on configuration page default path is:
      /var/www/html/nextcloud/data
      i change it manually on /var/nextcloud/data

      • Hi Kamil, I hope you got Nextcloud working. The procedure above is for installing Nextcloud on Raspbian, not OSMC. The procedure has been tested on Raspbian Jessie and the Raspbian Stertch (the latest version). OSMC is a different operating system/environment. The above procedure does not apply to OSMC.

  35. Hi, I have Nextcloud up and running on an early Pi 3. Operating system is jessie Nextcloud is 13.0.1. My setup is using an external hard disks and is currently holding about 350GB of data.
    I have noted that Nextcloud 14 will not run with PHP 5. Thus I need to update to stretch and PHP 7.
    I am not familiar with the implications of making these upgrades.
    I have previously updated other machines to stretch – I guess this would have limited implications.
    PHP 7 on the other hand is out of my league and I cannot find anything which gives an idea how to make that upgrade. Is anybody able to help (specifically in relation to Nextcloud and the Raspberry Pi).
    Any assistance will be greatly appreciated.
    Peter

    • Hi Peter. Sorry for this very late reply. I somehow overlooked your comment back in March.

      You want to run Nextcloud 14 on Raspbian Jessie, but Jessie has only PHP5 available and Nextcloud requires PHP7. PHP7 is not in the repos for Jessie, so installing it would be a bit more complicated that just typing “apt-get install…”. There are procedures out there for installing PHP7 on Jessie, but they are somewhat complicated. This one requires compiling PHP7 from source. Others introduce dependencies you might not want, such as enabling specific PPAs or non-standard repos.

      It might be easiest just to rebuild your Pi with Raspbian Stretch and install Nextcloud all over again. (Backup your data first). After installing stretch, you could perhaps build Nextcloud quickly by following my article on Automatic Nextcloud Installation. Cheers, Jim.

  36. Thanks very much for this tutorial. I’ve built nextcloud several times by hand and this was far easier. Everything worked great until I got to the point of moving files onto an USB drive. Here are a few configuration items and the problems that occurred when trying to mv files onto the USB drive.

    started with a clean 2018-03-13-raspbian-stretch.img
    changed the default username/pw and enabled ssh
    followed your recipe exactly
    created a mount location at /mnt/FLASH64
    mounted the drive
    // everything is good so far … and then
    sudo mv /var/nextcloud/data /mnt/FLASH64

    I received messages for every file of the form
    mv: failed to preserve ownership for ‘/mnt/FLASH64/data/nextcloud.log’: Operation not permitted

    Any thoughts on where things went wrong?

    thanks again

  37. Hello, can you comments as to how your guide is different to the snap image provided by nextcloud? what does your guide have that snap is missing or vice versa, thanks

  38. Hi. Your guide worked perfectly for me, thanks. I’ve now got a Pi2 with Nextcloud 13 and with 4Tb drive attached and domain name that I use with Duplicati as a backup for all the family. A bit of extra work was needed for my setup. Added an entry to /etc/fstab to automatically mount the ext drive, setup a static IP and added the domain name as a trusted domain. Seems quicker than previous setup of Owncloud 9, which I also setup following your guide 🙂 Thanks again, Cheers john.

    • Cheers John. Adding your domain name as a trusted domain sounds right, as does the fstab update and the static IP change. On a Pi 2 you would should see maximum backup speeds of about 8 MB/s. That is roughly the Pi 2’s maximum network speed.

      The Pi3 B+ was launched a few weeks ago. I haven’t tested one yet, but it has gigabit networking and reported network speeds are 26MB/s or so. It could potentially triple your backup speeds. Cheer, Jim.

  39. Huge thanks for all the work you put into this. Helped me out a lot during my first Nextcloud setup!

    Greetings from Germany,
    Daniel

  40. Thanks so much.
    I’m now on my 5th installation, all others having failed. As a mere user, can I recommend installing noobs lite onto your sd card (Berry boot no longer seems to work) then when the pi boots, tell it to install onto sda or whatever is the name of your external drive. That way nextcloud will be running on your external drive without you having to mess around with moving the data. One install failed at that point and it took me a long time to realise that nextcloud was using the SD card for data, which filled up rapidly.
    I’m using a Pi2 and an old 110gb HDD dedicated to nextcloud – a very cheap install.
    Other failures were due to my typing errors, or trying to use other methods of installation such as the nextcloudplus_berryboot image, which simply failed to work.
    I would also recommend using MySQL and not MySQL lite if you are using more than a few GB of data. One SQL Lite install simply gave up the ghost after a couple of weeks. The RPI2 seems to cope OK with MySQL.
    This is just the experience of a mere user, who is learning a great deal through successive failed attempts, so many thanks Jim for your excellent work.
    (PS. I’m using Nextcloud because I’m trying to move all my work to ARM based machines, on which Dropbox doesn’t want to work and I’m finding Nextcloud so much better, despite all my failed attempts.)

    • Hi Greg. Glad that you were able to persevere and get the procedure to work with a noobs built Pi. I would also recommend MySQL in all but the simplest (perhaps single user) setups. Cheers, Jim.

Leave a Reply to Filippo Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.