Automatic Nextcloud Installation on Raspberry Pi

Nextcloud is an open source software package providing remote file sharing services. It is similar to Dropbox. But with Nextcloud, you retain ownership, security and control of the shared data. This procedure describes how to build a working Nexcloud service using just 3 commands.

Note: If you would rather do the installation manually, step-by-step, without the help of a script, please see my previous article Simple Nextcloud Installation on Raspberry Pi. It explains how to do the installation in detail, and provides more background information on Nextcloud. Both procedures achieve the same overall result, however.

My Raspberry Pi was installed with Raspbian “Stretch” (Debian 9) by applying the image “2017-09-07-raspbian-stretch” downloaded from the raspberrypi.org downloads page. Raspbian Stretch was launched in August 2017, to supercede the earlier Raspbian “Jessie” (Debian 8). The following procedure works on both versions.

It is recommended to carry out this procedure on a fresh installation of Raspbian.

Download Ansible

Ansible” is an automation system for IT infrastructures. We will use it to set up Nextcloud. Install Ansible now.

$ sudo apt-get -y install ansible

Download the build_nextcloud script from Github:

$ wget https://raw.githubusercontent.com/webtaster/Nextcloud/master/build_nextcloud.yml

Install Nextcloud

Now, install and configure Nextcloud. As it runs, the following command will print various informational messages to the terminal, some of which are shown below. It should complete in about 15 minutes on Raspbian Stretch, or 5 minutes if you are using Raspbian Jessie, so be patient.

$ sudo date ; ansible-playbook -s -c local -i "localhost," build_nextcloud.yml
Sat 18 Nov 15:48:07 UTC 2017
PLAY [127.0.0.1] ***************************************************************
TASK [setup] *******************************************************************
ok: [127.0.0.1]
...

Once the command completes, you will have a basic Nextcloud installation running on your Pi. Proceed as follows to create an admin user.

Create a User for Nextcloud

In a browser, surf to your new Nextcloud web page. Use the URL:
http://your Pis IP address/nextcloud

For example, the address of my Pi is 192.168.1.99. So I go the the URL: http://192.168.1.99/nextcloud

You should see a mostly dark blue login page. In the middle is a “Performance Warning” about SQLite. Ignore that. Near the top it says “Create an admin account”. Think of a user name and password and type them into the boxes provided. Note, however: do not press the [Enter] key while you are on this page. If you do, the system will think you have finished the whole page, and it will try to complete the configuration, and fail, because we have not entered some values yet. Quite likely it will say “can’t create or write into the data directory var/www/html/nextcloud/data“, or something similar. Rather then pressing [Enter] to move between fields, just click the mouse on the field you want to edit. If you run into a problem, just reload the page on your browser and start entering values again.

Just below the “password” box is a “Storage & database” drop-down. Click it to reveal the “Data Folder” box. In that, change the default “/var/www/html/nextcloud/data” to “/var/nextcloud/data“. Finally, click on the “Finish Setup” button.

Wait for a couple of minutes while Nextcloud completes the installation. After 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.

Congratulations, you have just 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.

Conclusion

You now have a running Nextcloud installation. I hops this article has been helpful.

17 thoughts on “Automatic Nextcloud Installation on Raspberry Pi

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

  2. So i figured out what I had to do.

    sudo a2enmod rewrite headers env dir mime

    I had to run that command, at least a portion of it, to allow for php to read the index.php file correctly.

    • Forgive my noobness.

      I moved the files running the mv and ln commands given above, now I am getting a 500 error when I try to go to the nextcloud section of pi.

      How did I mess up?

      Also, now that I have this quasi running, what do you I need to do to have the pi react to a domain that I have purchased and have that domain point to my external IP?

      Again, I am a noob at some of the principles of web applications.

      Thanks for all the help already.

      • Hi Ginger, without knowing the exact state of your Pi, it is difficult to suggest why things might not be working. I would recommend re-imaging your Pi with the latest Raspbian, the doing the procedure above on the fresh Pi. It should all work.

        Your question about domain names is beyond the scope of this procedure, but my other article might be helpful. Check it out: Using a Domain Name with a Raspberry Pi Web Server

        Cheers,
        Jim.

        • So I started over. I moved the data and now I am getting the error that states

          “can’t create or write data into the data directory /var/www/html/nextcloud/data”

          Any suggestions?

          • Hi Ginger, is this on a freshly re-imaged Pi ? The procedure is intended to run on newly installed Pi. Also, please post the whole output of the script, as well as the output of this command:

            cat /etc/os-release

          • Jim,

            The error comes when i try to go to the page and create my admin for the first time.

            Also, here is the output of the /etc/os-release

            PRETTY_NAME=”Raspbian GNU/Linux 9 (stretch)”
            NAME=”Raspbian GNU/Linux”
            VERSION_ID=”9″
            VERSION=”9 (stretch)”
            ID=raspbian
            ID_LIKE=debian

          • Hi Ginger, is this on a freshly re-imaged Pi ? The procedure is intended to run on newly installed Pi.

            You moved the data, and then got the error “can’t create or write data into the data directory /var/www/html/nextcloud/data” when you tried to create the user. However, in the procedure above, the user is created before the data is moved, not after. I am therefore not sure what you have done on the Pi, and it is difficult to advise. I would recommend that you re-image the Pi, then run the procedure above in exactly the order given on the newly installed Pi.

  3. I got a nice message that is quite weird imho.

    TASK [Restart Apache] **********************************************************
    fatal: [localhost]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Unable to start service apache2: Job for apache 2.service failed because the control process exited with error code.\nSee \”systemctl status apache2.service\” and \”jour nalctl -xe\” for details.\n”}
    to retry, use: –limit @/home/pi/build_nextcloud.retry

    When I do it manually with the usual
    $ sudo service apache2 restart

    I got this error as well:
    Job for apache2.service failed because the control process exited with error code.
    See “systemctl status apache2.service” and “journalctl -xe” for details.

    What’s going on?
    And now the script failed I’m a bit worried on the mess it already installed and that I will not be able to clean properly :s

    • Hi Jeremy, that is strange. Is this a fresh installation of Raspbian, or a Pi that has been running for some time?

      Please post the output of the following 2 commands:

      tail /var/log/apache/error.log
      journalctl -xe

      Cheers,Jim.

  4. I have a new Pi 3. I successfully installed:
    – pihole
    – openvpn
    – Plex Server

    “journalctl -xe” is returning:

    nov. 30 20:30:45 raspberrypi apachectl[23560]: AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. S
    nov. 30 20:30:45 raspberrypi apachectl[23560]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
    nov. 30 20:30:45 raspberrypi apachectl[23560]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
    nov. 30 20:30:45 raspberrypi apachectl[23560]: no listening sockets available, shutting down
    nov. 30 20:30:45 raspberrypi apachectl[23560]: AH00015: Unable to open logs
    nov. 30 20:30:45 raspberrypi apachectl[23560]: Action ‘start’ failed.
    nov. 30 20:30:45 raspberrypi apachectl[23560]: The Apache error log may have more information.
    nov. 30 20:30:45 raspberrypi systemd[1]: apache2.service: Control process exited, code=exited status=1

    My other services seem to overlap with Apache :s

    That makes me realize I have some VNC errors as well, strange.

    “tail /var/log/apache/error.log” is returning an error saying it’s impossible to open it because no such file or folder exist.

    Thanks for the debug Jim!

    • This is what a “netstat -tulpn” return:

      Proto Recv-Q Send-Q Adresse locale Adresse distante Etat PID/Program name

      tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 595/lighttpd

      So a service named “lighttpd” is using it apparently. No idea what it is.

      • FYI, the problem was coming from PiHole which is using the port 80 by default.
        The thing was the make it use an other port, and then the problem got resolved.
        (Port is to be changer in /etc/lighttpd/lighttpd.conf )

        • Hi Jeremy, as your Pi is already running Pihole, Plex Server and a VPN, it isn’t too surprising that the above procedure will interfere with their configurations in some way. For example, as you say, Apache2 is competing with lighttpd for access to port 80. (Lighttpd is a web server, probably installed as part of Pihole). I recommend the above procedure for use only on a fresh Raspbian installation, ie. a Pi that isn’t doing anything else. I hope your Plex, VPN and Pihole functionality has not been damaged.

          Perhaps you could install Raspbian on a second SD card, put that in the Pi and do the above procedure? Meanwhile keeping VPN, Pihole and Plex intact on their own card.

          Cheers,
          Jim

          • I ran some tests.

            So if anyone read those comments they can know that Pihole, Plex, OpenVPN, and NextCloud can coexist perfectly well on a Pi 3.
            You just have to be careful to move the default PiHole webserver from the port 80 to an other one of your choice (through the /etc/lighttpd/lighttpd.conf file, I chose 8080 personally, and then restart the lighttpd service).
            No functionalities where damaged, and everything run smoothly now.
            Thanks for your work Jim.

            Now it’s time for me to put in place the https mode, and make a little raid1 system in place.

            Cheers,
            Jeremy

  5. (you should delete my 2 other comments with the 2 long outputs from the journalctl -xe as they were mistake of my part, thinking your website was not accepting them, as well as this one 😉 ).

    • Hi Jeremy, I deleted the two long comments and removed some long output from another. Hopefully it will make sense to future readers. The ansible script (build_nextcloud.yml) failed at the step where it restarts Apache. As you say, the error happened becuase port 80 was already in use by lighttpd, another web server that the Pi already happened to be running. Thanks for coming back, Jim.

Leave a Reply

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