Create your own Cloud server on Raspberry Pi with OwnCloud

OwnCloud is an all-in-one solution for creating cloud storage, calendar and contacts servers. OwnCloud allows you to share files through an easy-to-use web interface, similar to OneDrive from Microsoft and Google Drive.

To make our OwnCloud installation even more robust, we’re going to use a RAID volume for our storage. I’m going to assume you’ve followed my previous tutorial ‘Create a RAID Volume on Raspberry Pi‘ first, although this is not necessary.

Why use a Raspberry Pi for OwnCloud?

Nowadays, home connections are quick enough thanks to fibre and advances and speed gains in ADSL. Raspberry Pi’s are cheap, use little power and are quick enough to run the required web server needed for OwnCloud.

I’m using two USB Flash drives in an RAID-1 volume configuration (see RAID tutorial) and have my Raspbian OS booting from another USB Flash Drive (see tutorial on booting from USB) so there is a little bottlenecking on the USB bus, but for general usage, it’s not a concern as the speed gains from running the OS from a USB and having 2 other devices is still quicker than a MicroSD card.

TL;DR it’s a cheap way of creating cloud storage with your Raspberry Pi, and they’re more than quick enough for the task.

Step 1 – Installing the web server

We’re going to need to install a web server in order to run OwnCloud. I’m going to install Nginx, PHP7 and MySQL server for this. First, we need to install some updates and upgrades to make sure we’re good to go:

sudo apt-get update -y && sudo apt-get upgrade -y

We need to add some new sources to APT in order to install PHP 7.1. First, we may need to install a couple of packages. Run the following command:

sudo apt-get install apt-transport-https lsb-release ca-certificates

Now we need to modify our sources list in order to install Php 7 using APT. Download a security key in order to continue the installation:

wget -O /etc/apt/trusted.gpg.d/php.gpg

Now we need to create a file for our PHP source to reside. Create the file using nano:

sudo /etc/apt/sources.list.d/php.list

Add the following to the file:

deb jessie main

Save and exit by pressing CTRL + C, saving when prompted. Finally, update Apt to register the new sources:

sudo apt-get update

There are a few packages we’re going to need. Run the following command to install the core files:

sudo apt-get install nginx php7.0-fpm php7.0-curl php7.0-xml php7.0-json php7.0-zip php7.0-mb php7.0-mysql php7.0-mcrypt php7.0-gd

Now try visiting the IP address of your Raspberry Pi, you should see the default Nginx default page.

Step 3 – Install MySQL Database Server

The next step will see us install MySQL Database Server. To do this, run the following command:

sudo apt-get install mysql-server mysql-client

An interactive prompt will start to create the initial configuration. You will see something like this:

Provide a strong password for MySQL server and continue until the installation completes. Next, we need to login to our MySQL server and create a database and user for our OwnCloud installation. Login using the following command:

mysql -uroot -p

You will be asked for your root password that you created during the installation. Once you’re logged into your local MySQL server, run the following command to create your OwnCloud database:


Finally, we create a new user (change the ‘a-secure-password’ to suit, ensure you don’t use your root password and that you make note of it, we’ll need it later on):

GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED BY 'a-secure-password';

We’re ready to start the installation of OwnCloud. Exit by typing ‘quit’.

Step 3 – Configure Nginx and PHP

First, we need to harden PHP to ensure it stays secure. Edit the configuration file for PHP using this command:

sudo nano /etc/php/7.0/fpm/php.ini

Search for ‘; cgi.fix_pathinfo=1’ by pressing CTRL + W, edit this line to look like this by removing the semicolon and space at the start and changing the value to 0:


Modify your default site using the following command:

sudo nano /etc/nginx/sites-available/default

Modify the file until it looks like this. The additions are marked in green:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.php index.html index.htm;

    server_name _;

    location / {
        try_files $uri /index.php$is_args$args;

    location ~ \.php(/|$) {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_read_timeout 300

    location ~ /\.ht {
        deny all;

Save by pressing CTRL + X, saving the changes when prompted. Let’s test the configuration using the following command:

sudo nginx -t

You should see confirmation of successful configuration. Let’s test PHP by creating a new file:

sudo nano /var/www/html/index.php

Enter the following into the nano editor:

<?php phpinfo();

Save by pressing CTRL + X once more, saving when asked to. Visit the IP address of your Raspberry Pi once more, you should see the PHP info page:

We now need to extend the maximum execution time of PHP-FPM to 300 in order to provide Nginx and PHP enough time to go through the installation process. Edit the FPM configuration with the following command:

sudo nano /etc/php/7.0/fpm/pool.d/www.conf

Search for ‘request_terminate_timeout’ and ensure the line reads like this:

request_terminate_timeout = 300

Save using CTRL + X and save when prompted. We’re ready to go ahead and install OwnCloud.

Step 4 – Install OwnCloud

Remove any test or sample files, ensuring we have most definitely changed to the above directory or run the risk of damaging the OS:

sudo rm /var/www/html/*

We need to download the setup script:

sudo wget

Next, we need to change the owner of the ‘/var/www/html’ folder to ‘www-data’:

sudo chown -R www-data:www-data /var/www/html

Now in the browser, navigate to your Raspberry Pi in the browser, adding ‘/setup-owncloud.php’ to the end. My URL looks like this, change yours to the correct IP:

You should see the following screen:

Follow the installation until you reach the end and the installation has completed. You should now see the following screen which means the installation was completely successful.

To begin, provide yourself with an admin username and password. The next stage is very important for configuring the storage. If you followed my previous tutorial on creating a RAID volume on Raspberry Pi, we need to create our data directory. Assuming you did, and your mount point is ‘/mnt/raid0/’, we need to create a directory for our OwnCloud data and set the owner to www-data:

sudo mkdir /mnt/raid0/owncloud && sudo chown -R www-data:www-data /mnt/raid0/owncloud/ && sudo chmod -R 755 /mnt/raid0/owncloud/

After this, we enter the following path into the ‘data folder’ section of the setup page in your browser where you added a username and password earlier:


Enter your MySQL details as following:

  • Username: owncloud
  • Password: your chosen password
  • Database: owncloud
  • Server: localhost

Press ‘Finish Setup’ to complete the installation. That’s it. We’re good to go. You should now see the login screen when visiting the IP address:


We’ve hardened our platform by creating a RAID volume, and gone through the steps to install PHP, Nginx and MySQL. We’ve installed OwnCloud and created a very affordable and robust cloud platform. Please feel free to feedback below or ask any questions.


Web Developer living in Manchester, working for Studio Skylab ( Views and thoughts are my own.

You may also like...

42 Responses

  1. Nice. Have you see openmediavault, that is awsome. I am running that on my server box at home and it should work on a pi as well

  2. Shahnawaz says:

    In the file /etc/nginx/sites-available/default
    ; is required at the end of fastcgi_read_timeout 300

    while trying to access this url (i changed to mine IP) it is downloading the php file.Not getting the setup page.Any idea how to do it? Also i saw the ownership as www-data.Why is that so.

  3. Raj says:

    Can you please let me know what you did to over come the 404 not found. I too face the same issue.

  4. Mike D. says:

    well I tried this but I am stuck at the point where the PHP page should be showing up. I am getting an apache page. I also got the apache page the first time I went to the web page instead of the NGINX page. Not sure what went wrong. I basically copy and pasted each step.

    • Jonas says:

      remove and purge apache2* ‘$ sudo apt-get –purge remove apache2*’ (if you don’t need it anymore of course) remove and purge nginx. then clear the content of the /var/www/index.php and just put <?php phpinfo(); in. reinstall nginx.

  5. ziv says:

    the Mysql server password selection does not appear (step 3)…

  6. Hi,

    Thanks for this guide, very helpful. However, there are a few parts that could do with additional information / correction.

    1. As Shahnawaz stated, there is a missing ; at the end of the “fastcgi_read_timeout 300” section, which causes the nginx test to fail – it should read “fastcgi_read_timeout 300;”.
    2. Before running the “sudo wget” command, you should mention that you need to be in the “/var/www/html” directory first, othertwise when you visit “http://YOUR.PI.IP/setup-owncloud.php”, it won’t work as it is looking for the setup-owncloud.php file in html file – adding a “cd /var/www/html” before the wget command fixes this.
    3. During the setup of OwnCloud in the browser, set the install directory to “.” instead of “owncloud” and then you won’t need to add the path to the URL when accessing the OwnCloud UI.

    Other than that, this is a great guide and I’ve already followed it once (in testing) on my Pi 3, but now I’m going to try it all again with the RAID1 setup you’ve mentioned, once my two USB drives arrive from eBay (plus, I’m going to see if this works on the ASUS Tinker Board too as the 1Gbps LAN would be a nice performance boost for transferring large files…).


  7. Hello just wanted to say great TuT,straight to the point and easy installation just a question mind explaining a way to make this go WAN using no ip?

  8. mark says:

    fuck you Ste, you weird burger eater. you smell like spring onions

  9. Red says:

    Another tutorial that is not working what a waste of time
    [email protected]:~ $ wget -O /etc/apt/trusted.gpg.d/php.gpg
    /etc/apt/trusted.gpg.d/php.gpg: Permission denied
    [email protected]:~ $ deb jessie main
    bash: deb: command not found
    and more, more ,more

  10. Michele says:

    You forgot to mention that it’s necessary to increase the maximum POST and UPLOAD size.
    If not the users will not be able to upload files larger than 2 mb…

  11. Dude says:

    When installing php, dont add the prefix 7.0, somehow it mess with the installation of php7.0-fpm, so that’s the line you use, :sudo apt-get install nginx php-fpm php-curl php-xml php-json php-zip php-mbstring php-mysql php-mcrypt php-gd:

  12. Staff says:

    Can’t get PHP to display properly (putting out source code instead?):

    (If you’re using Stretch rather than Jessie, make sure you put stretch rather than jessie in the
    “deb jessie main” step.)

    sudo apt-get intsall libapache2-mod-php7.0 (assuming you’re using Apache2. This tutorial uses Nginx instead)
    sudo a2enmod php7.0
    to enable PHP on Apache2.

  13. jstarks says:

    phpinfo not appearing (instead shows ”Welcome to nginx on Debian” default page)

  14. Josh says:

    Will owncloud alert you if a hard drive is starting to fail? I know some NAS devices have lights or email the user.

  15. I did a clean install and this is what get
    “Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000][1698] Access denied for user ‘owncloud’@’localhost” (using password:YES)

    Any help you can provide would be great. This is my first time digging into something like this.

  16. Trying to get the security key with the code:
    wget -O /etc/apt/trusted.gpg.d/php.gpg
    and I keep getting:
    /etc/apt/trusted.gpg.d/php.gpg: Permission denied

    Is there something I’m doing wrong or something else to try?

  17. Somebody says:


    Thanks for making the tutorial, but I did not find it very helpful. Apart from some of the missing instructions & improvements that other users already mentioned, the final setup is pretty barebones. You’ll need to configure nginx a lot to make even basic things like reliable uploading usable. There’s also no guidance on how to make is accessible via a client or outside of the local network.

  18. Pascal says:

    For users with mysql issues (like me!)

    /etc/init.d/mysql stop
    sudo killall mysqld_safe
    sudo killall mysqld
    sudo mysqld_safe –skip-grant-tables &
    mysql -u root
    use mysql;
    update user set password=PASSWORD(“mynewpassword”) where User=’root’;
    update user set plugin=”mysql_native_password”;
    /etc/init.d/mysql stop
    sudo kill -9 $(pgrep mysql)
    /etc/init.d/mysql start

  19. Raging Pug says:

    okay, I must be pretty dumb.
    I barely make it in and I’m at, ‘Now we need to modify our sources list in order to install Php 7 using APT. Download a security key in order to continue the installation:’

    entered: wget -O /etc/apt/trusted.gpg.d/php.gpg
    and it says ‘/etc/apt/trusted.gpg.d/php.gpg: Permission denied’

  20. Pascalh says:

    Try the command with sudo

  21. PascalH says:

    Hi Stewy,

    Thanks for your excellent tutorial. I’ve succeeded in installing everything but would like to place my experience into your post. I’ve tested this setup with the following:

    2x 32Gb SanDisk USB 3.0 USB
    1x 16Gb SDHC microSD (Kingston)
    1x Brandless USB (Read 11MB/sec, Write 4MB/sec)

    I’ve tested first the standard setup without booting from USB and the speed was reasonable. Cloud was okay and worked “okay”. With the USB speed was better and it worked fine.

    The app from OwnCloud on the other hand (you buy it for 79 eurocent) is crap. It keeps crashing on 4 phones (Iphone, Samsung S7, S8 and a tablet). So although the setup works for me…the program is not like you expect.

  22. Felix says:

    Hi, Im stuck by this command:

    [email protected]:/home/pi# sudo apt-get install nginx php7.0-fpm php7.0-curl php7.0-xml php7.0-json php7.0-zip php7.0-mb php7.0-mysql php7.0-mcrypt php7.0-gd
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Note, selecting ‘php7.0-mbstring’ for regex ‘php7.0-mb’
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    php7.0-gd : Depends: libwebp5 but it is not installable
    E: Unable to correct problems, you have held broken packages.

    getting a error and didnt find anything on the internet (where I searched)? can somebody help me?

  1. 6th August 2017

    […] As we’re using a software RAID controller, we can’t run the OS from our RAID volume, but we can use to for storage. This tutorial is part one of two where we will use our RAID volume for creating our own cloud storage platform using OwnCloud. View the Installing OwnCloud on Raspberry Pi tutorial. […]

Leave a Reply

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