Simple Nextcloud Installation on Raspberry Pi

*UPDATED January 2018 to add MySQL procedure*. The Raspberry Pi’s low power consumption makes it well suited to the role of always-on web server. This post describes how to install Nextcloud onto the Pi.  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 detailed, 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.

The below procedure describes how to install Nextcloud version 12.0.4, the latest stable version at the time of writing (9th Jan 2018), but it will work for later/future versions too.

NOTE: Nextcloud was forked from ownCloud in June 2016. It now seems that Nextcloud has largely taken over ownCloud’s role, 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 have come here from the ownCloud article, thank you for your patience. Okay, back to the procedure…

My Raspberry Pi was purchased from RS Components in the UK. It was installed with Raspbian “Stretch” (Debian 9) by applying the image “2017-09-07-raspbian-stretch” downloaded from the 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 So I start a browser on my PC and surf to 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

Now move the Nextcloud package into place and unpack it:

$ sudo mv /var/www/html
$ cd /var/www/html
$ sudo unzip -q

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;

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 So I go the the URL:

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.


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.


100 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 “” 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.

    • 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 I just get a blank page.

      Any help much appreciated. 🙂

  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 and the other computer is at ). No response from the Rpi. Any suggestions?


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

  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?


  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]
    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 /
    (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:
    [Sun Feb 05 14:33:05.904833 2017] [:error] [pid 3456] [client]
    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:

    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:


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

  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?

    • 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 “”. 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

      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:, 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.


          • 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:
    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), 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/”


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



  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.


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

    * @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 and get this error:

    Error: UNIQUE constraint failed:

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

Leave a Reply

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