Simple Nextcloud Installation on Raspberry Pi

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.

The below procedure describes how to install Nextcloud version 10.0.1, the latest version at the time of writing (20th Nov 2016), but it should 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 2 was purchased from RS Components in the UK. It was installed with Raspbian “Jessie” (Debian 8) by applying the image “2016-09-23-raspbian-jessie.img” downloaded from the downloads page, where it is described as “Raspbian Jessie with Pixel”. The following procedure was then performed without any further pre-work (other than enabling ssh in the basic setup).

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 PHP5 and Associated Packages

Owncloud requires PHP 5 and few other packages. Install them as follows.

$ sudo apt-get install php5
$ sudo apt-get install php5-gd
$ sudo apt-get install sqlite
$ sudo apt-get install php5-sqlite
$ sudo apt-get install 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.

Surf to the Nextcloud download page.  At the top left is a section entitled “Get Nextcloud Server”.  Click in the “Download” button just below that.  A popup window opens.  Click on the big blue “Download Nextcloud” button.  Download the .zip file. Then copy it to the Raspberry Pi.

Alternatively (quicker), get the file on one step with this command on your Pi:

$ wget

At the time of writing (20th November 2016), the latest version of Nextcloud is 10.0.1. The version, and the link to download it, might have changed by the time you read this article. If so, just change the link accordingly (check it at the download page above.  For example in Firefox, right-click the download button and select “Copy Link Location”.  Then just paste the link into a wget command, as above).

Now move the Nextcloud package into place and unpack it:

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

Tip: if you are new to Linux. in case you were not aware, the tab key can be used to automatically enter file names, which saves on typing.  For example, to enter the last command, I could have just typed “sudo unzip -q next” and pressed the tab key.  In fact I did.  The whole file name is then inserted automatically.

Create the Data Directory

You must create a “data” folder for Nextcloud and set permissions.  We will put the data in /var/nextcloud/data, because it is a secure location.  Proceed as follows.

$ sudo mkdir -p /var/www/html/nextcloud/data
$ sudo chown www-data:www-data /var/www/html/nextcloud/data
$ sudo chmod 750 /var/www/html/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/www/html/nextcloud/data
drwxr-x--- 2 www-data www-data 4096 Nov 20 14:41 /var/www/html/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

Create a Login for Nextcloud

In a browser, surf to your new Owncloud 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 “Finish Setup” button.

…Wait for a couple of minutes while Nextcloud competes the installation.  During this time, Nextcloud creates more files and directories in our data directory, and it puts a database in there too.

Hey Presto! After a after a short delay, 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.


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.

Below is a procedure for securing the Nextcloud data directory. I highly recommend it, especially if you are planning to make Nextcloud files accessible from the Internet. After that are instructions for increasing the Nextcloud upload limit.

Secure the Nextcloud Data Directory

It is highly recommended to make Nextcloud more secure by moving the “data” directory to a secure location.  Let’s move it to /var/owncloud/data.  That will prevent any unauthorized users from accidentally gaining access through the web browser.

Move the data directory:
$ sudo mkdir -p /var/nextcloud
$ sudo mv -v /var/www/html/nextcloud/data /var/nextcloud/data

Configure the new data location into Nextcloud.  Using vi or another editor of your choice, edit the configuration file.  Make a backup copy first, just in case there is a mistake with the edit:

$ cd /var/www/html/nextcloud/config
$ sudo cp -p config.php
$ sudo vi config.php

Change this line:

'datadirectory' => '/var/www/html/nextcloud/data',

to this:

'datadirectory' => '/var/nextcloud/data',

Be careful not to delete the comma at the end of the line.  Save the file and exit the editor.

Now,  in the browser, refresh the Nextcloud web page.  You should see the same files and folders as before.  That completes the securing of the Nextcloud data.

Increase the Nextcloud Upload File Limit

Upload a file to Nextcloud as follows. Click on the square button containing a plus sign (“+”) near the top of the page. A drop down menu appears. Choose the first menu item, “Upload”, and select a file. The file will be transferred and you should see it appear in the Owncloud list of files. However, if the file was more than 2 MB in size, it will not upload. Instead a message will appear at the top of the screen – “Error uploading file “filename”: Total file size XX MB exceeds upload limit 2 MB”.

By default, the maximum size of file that can be uploaded is 2 MB, which is not enough for many people, Increase it as follows.

Edit the file /etc/php5/apache2/php.ini.  You can use the “vi” editor, or another if you prefer:
$ sudo vi /etc/php5/apache2/php.ini

Change these two lines:
post_max_size = 8M
upload_max_filesize = 2M


post_max_size = 20M
upload_max_filesize = 20M

and save the file. Note: if you are having difficulty finding these settings in the file, use your editor’s search facility.  In vi, you can search by pressing the slash key (“/”), then typing what you are searching for, such as “post_max_size”, then pressing enter.

Restart Apache:
$ sudo service apache2 restart

And refresh your browser page. The upload limit should have increased to 20 megabytes, which you can verify by trying another upload, as above.


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

  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

  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.

Leave a Reply

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