Spiffberrypi | Filesharing setups *

SambaFTPAFPOWN CloudNextCloud

https://pimylifeup.com/raspberry-pi-nas/

SAMBA

Samba is a re-implementation of the SMB (Server Message Block) networking protocol and allows Linux computers to integrate into Microsoft’s active directory environments seamlessly.

CIFS or Common Internet File System is an implementation of the SMB protocol. In modern setups, CIFs or SMB is used interchangeably, but most people will use the term SMB.

By using Samba on our Raspberry Pi, we can easily share directories in a way that they can be accessed on almost every operating system.

Samba is one of the easiest to set up and configure file servers, which makes it one of the best solutions for setting up a NAS, especially when you intend on targeting Windows systems.

There are plenty of other NAS setups that you can run on your Raspberry Pi. I prefer Samba has I run into the least problems, but something else might appeal to you more.

Note: The USB ports on the Raspberry Pi might not be enough to power an external drive so you might need to invest in a powered USB hub.

Setting up Samba on your Raspberry Pi

1. The first thing that we must do before we setup a SMB/CIFS share on our Raspberry Pi is to make sure everything is up to date.

We can update the package list and all our packages by running the following two commands.

sudo apt-get update
sudo apt-get upgradeCopy

2. Now that we have our Raspbian operating system entirely up to date, we can now proceed on to installing the Samba software to our Raspberry Pi.

We can install the packages that we require to setup Samba by running the following command.

sudo apt-get install samba samba-common-binCopy

3. Before we set up our network storage on our Pi, we need to first create a folder that we will share.

This folder can be located anywhere, including on a mounted external hard drive. For this tutorial, we will be creating the directory within the “pi” users home directory.

Create this folder by running the following command.

mkdir /home/pi/sharedCopy

4. Now we can share this folder using the Samba software. To do this, we need to modify the samba config file.

The “smb.conf” configuration file is where you will store all your settings for your shares.

We can begin modifying the config file by running the command below.

sudo nano /etc/samba/smb.confCopy

5. Within this file, add the following to the bottom. This text defines various details of our share.

[pimylifeupshare]
path = /home/pi/shared
writeable=Yes
create mask=0777
directory mask=0777
public=noCopy

[pimylifeupshare]” – This defines the share itself, the text between the brackets is the point at which you will access the share. For example, ours will be at the following address: //raspberrypi/pimylifeupshare

path” – This option is the path to the directory on your Raspberry Pi that you want to be shared.

writeable” – When this option is set to “Yes“, it will allow the folder to be writable.

create mask” and “directory mask” – This option defines the maximum permissions for both files and folders. Setting this to 0777 allows users to read, write, and execute.

public” – If this is set to “no” the Pi will require a valid user to grant access to the shared folders.

6. With the changes made to the file, you can now go ahead and save it by pressing CTRL + X then Y followed by ENTER.

7. Next, we need to set up a user for our Samba share on the Raspberry Pi. Without it, we won’t be able to make a connection to the shared network drive.

In this example, we will be creating a Samba user called “pi” with the password set to “raspberry“.

Run the following command to create the user. You will be prompted afterward to enter the password.

sudo smbpasswd -a piCopy

8. Finally, before we connect to our Raspberry Pi Samba share, we need to restart the samba service so that it loads in our configuration changes.

sudo systemctl restart smbdCopy

9. The last thing we should do before we try connecting to our Samba share is to retrieve our Raspberry Pi’s local IP address.

First, make sure you’re connected to a network by either connecting Ethernet cable or setup WiFi.

While you can connect using the Pi’s network name, we will grab the IP address just in case that option fails to work on your home network.

Run the command below to print out the Pi’s local IP Address.

hostname -ICopy

In the next couple of sections, we will walk you through the process of connecting to your network attached storage on Windows and Mac OS X.

Connecting to your Samba Server on Windows

1. To connect to your Samba on Windows, begin by opening up the “File Explorer“.

Within the “File Explorer” click the “Computer” tab (1.) then click “Map network drive” (2.)

Windows File Explorer Map Network Drive

2. You will now be greeted by the dialog shown below asking you to enter some details.

Within the “Folder” textbox (1.) you will want to enter the following “\\raspberrypi\pimylifeupshare“.

Make sure that you replace “pimylifeupshare” with the name that you defined for your Samba share.

If for any reason the connection fails, you can switch out “raspberrypi” with your Raspberry Pi’s local IP address that you retrieved in step 9 of the setting up section of this tutorial.

Once done, click the “Finish” button to finalize the connection.

Windows Samba Network Drive Details

3. Finally, you will be asked to enter your login details to be able to finish the connection.

Enter the username and password (1.) you set using the “smbpasswd” tool earlier on in the tutorial.

Once done, click the “OK” button (2.) to continue.

Windows Enter Samba Credentials

Connecting to your Samba Share on Mac OS X

1. Now to connect to your Raspberry Pi’s Samba server on a MAC OS X system.

You will have to begin by opening the “Finder” application as we have shown in the screenshot below.

Raspberry Pi Samba Cifs - Mac OS X - 01 Opening Finder on Mac OS X

Raspberry Pi Samba Cifs - Mac OS X - 02 Connect to Server

2. With the “Finder” application now open, click the “Go” button (1.) in the toolbar, then click the “Connect to Server…” option (2.).

3. Now that the “Connect to server” dialog is now open on your device you can go ahead and enter in the details for your Raspberry Pi’s SMB share.

Within the address box (1.) you will need to enter “smb://192.168.0.159/pimylifeupshare“.

You will need to swap out the IP address “192.168.0.159” with the IP address of your Raspberry Pi that you retrieved in step 9 of the setting up section of this tutorial.

Also, if you changed the name of the share name from “pimylifeupshare“, you will need to change that section of the address.

Once you have entered the address, you can click the “Connect” button (2.) to begin the connection to your Raspberry Pi’s Samba share.

Raspberry Pi Samba Cifs - Mac OS X - 03 Connect to Server dialog

4. Before the connection is complete, you will be asked to enter both the username and password that you set up using the “smbpasswd” (1.) tool earlier in this guide.

Once you have entered in both of these details, go ahead and click the “Connect” button (2.) to finalize the connection.

Raspberry Pi Samba Cifs - Mac OS X - 04 Enter Login Details

By now you should have successfully set up a network drive that you can access on both a Windows PC or a Mac computer. You should also be able to access it on other devices such as mobile phones.

I hope that this Raspberry Pi Samba server tutorial has shown you everything you need to know to have your network storage up and working. If you have any feedback then please don’t hesitate to leave a comment below.

 

FTP

 

For those who don’t know, FTP stands for File Transfer Protocol and is simply a method for transferring files between two devices over a network

There is also an additional method that you can be used instead. This method is called SFTP, it stands for Secure File Transfer Protocol. This version of the protocol works over SSH.

The biggest difference between these two methods comes down to their security. SFTP is considered to be much more secure thanks to its use of encryption for the transfer of data.

We should also note that it is possible to use both FTP and SFTP at the same time as they operate on difference ports. By default FTP operates on port 21, while SFTP operates on port 22.

Using FTP is a great way to move files on and off of the Raspberry Pi without needing any fancy setups or physical access to the device itself.

Setting up SFTP is a very straightforward process as it is part of the SSH standard.

Using FTP requires a few more steps but is also fairly simple to set up, mainly requiring us to install a separate server software such as vsftpd.

An extra bonus you should also check out our guide on how to set up a mounted USB drive, so you have plenty of room for files and more. This tweak will help save you space on your SD card.

So, let’s get started with learning how to set up FTP and SFTP on the Raspberry Pi.

In this FTP server tutorial we are using Raspberry Pi OS.

If you don’t have it installed then check out my guide on installing NOOBS Raspberry Pi. (It’s the easiest way to get Raspbian onto your SD Card for a beginner)

Video Tutorial

Be sure to check out our video below for a visual guide on setting up FTP on your Raspberry Pi.

Alternatively we have a full written guide just below this video.

If you like what you see, then please make sure you subscribe or follow us on social media, so you stay up to date on our latest stuff.

Adblock blocking the video? Support us by subscribing to our ad-free service.

Setting up your Raspberry Pi for SFTP

Setting up your Raspberry Pi to be able to use SFTP is a very straightforward process and requires no additional software to be installed.

All we need to do is make sure that SSH is enabled by using the Raspi-config tool.

If you have already got SSH enabled, then you can skip ahead to the “How to Connect” section further down in this tutorial.

1. On the Raspberry Pi open up the terminal.

You can find this in the task bar at the top of the screen by default.

Alternatively you can press CTRL + ALT + T to open the terminal.

2. Within the terminal you will need to enter the following command.

This command will launch the raspi-config tool that we can use to enable SFTP on your Raspberry Pi.

sudo raspi-configCopy

3. Within this tool you need to go to the “5 Interfacing Options” option.

You can navigate through the menu by using the ARROW keys to move up and down, then the ENTER key to select an option.

SFTP On Raspberry Pi - Raspi-Config Main Menu

4. On the next screen find and select the “P2 SSH” option.

This option is what will allow us to enable the SSH service on our Raspberry Pi.

Enabling SSH On the Raspberry Pi for SFTP Menu

5. To actually enable SSH on your device, you need to select the <Yes> option.

Enabling SSH will give us access to the SFTP functionality of the protocol.

Raspi-Config Enable SSH for SFTP on Raspberry Pi

6. At this point you have now successfully enabled SSH on your Raspberry Pi.

You can quit out of this tool now by pressing the ESC key.

Successfully Enabled FTP Server on Raspberry Pi

7. You can now proceed down to our “How to Connect to the FTP Server” section of this tutorial.

This section will walk you through connecting to your Raspberry Pi over the SFTP protocol.

You will be able to connect to the Raspberry Pi over SFTP by using port 22.

Setting up an FTP Server on the Raspberry Pi

In this section we are going to be walking you through the process of getting plain FTP working on your device.

To make all of this work we will be making use of a piece of software called vsftpd.

We chose to use vsftpd as it is regarded as one of the most secure and fastest FTP servers that you can run on the Raspberry Pi.

1. Before we proceed let us ensure that our Raspberry Pi OS is running the latest available packages.

To update all packages on the device you will need to run the following two commands on the terminal.

sudo apt update
sudo apt full-upgradeCopy

Updating all packages ensures that we shouldn’t run in to any weird issues when installing vsftpd on to our Raspberry Pi.

2. Once the update process has completed we can now install the software we require.

Install vsftpd to your Raspberry Pi by using the command below.

sudo apt install vsftpdCopy

3. Before we can connect to our new Raspberry Pi FTP server we need to modify some settings.

Let us begin modifying the vsftpd configuration file by using the nano text editor with the following command.

sudo nano /etc/vsftpd.confCopy

4. Within this file you will need to add or uncomment (Remove the #) the following settings.

If you want to find options faster you can make use of the CTRL + W shortcut to search the file.

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
user_sub_token=$USER
local_root=/home/$USER/FTPCopy

Using these options we set it so that the user logging in is locked in to there directory.

In our case we are using “local_root” option so that the user will be locked to their home directory within a folder called “FTP“.

5. Once you are done press CTRL + X and then Yto save and exit.

6. Now we need to create the FTP directory so we can transfer files.

The root directory is not allowed to have write permissions so we will need a subfolder called files.

Replace <user> with the relevant user

Make sure that you replace “<user>” with the relevant user. For example, the default user on Raspberry Pi OS is “pi“.

mkdir -p /home/<user>/FTP/filesCopy

By using the -p argument we are telling mkdir that it needs to create the entire path tree.

So in our case it will create both our “FTP” and “files” directories.

7. With the directory added we need to modify its permissions so that we remove the write permission from the FTP directory.

Doing this will ensure no one can add files in to the FTP directory that they shouldn’t be.

Again make sure that you replace “<user>” with the user that you are using.

chmod a-w /home/<user>/FTPCopy

8. For our new settings to take effect we need to restart the vsftpd daemon on the Raspberry Pi.

We can now restart the service by using the following command.

sudo service vsftpd restartCopy

9. With the FTP server set up and running on our Raspberry Pi you can now connect to it.

You should now be able to connect to the FTP server on your Raspberry Pi over Port 21.

How to Connect to your Raspberry Pi’s FTP Server

You can now connect to your Raspberry Pi by using either FTP or SFTP, depending on which protocol you decided to go with.

For this tutorial we are going to by using the FileZilla FTP client as it has support for both FTP and SFTP while also working on numerous operating systems.

There are plenty more FTP clients that you can check out. Another solid alternative is WinSCP, however, that is Windows only.

Any FTP client should be able to connect to the server with little to no issues.

1. On your PC head over to the FileZilla download page and download the relevant client for your operating system.

2. Upon opening up the FileZilla software you will be able to login to your FTP server.

1 – First you need to enter in the IP address of your Raspberry Pi. (1.)

2 – Next, you need to enter the username for the user we are trying to connect with. If you are sticking with the default user this will be “pi” (2.).

3 – After that, you will need to enter the password for that user. Again if you are using the default user you will need to use the password “raspberry” (3.).

4 – The final option that needs filling out is the port. The port differs slightly depending if you are using SFTP or FTP on your Raspberry Pi.

If you are using plain FTP enter the port 21 in to the textbox. Alternatively if you are using SFTP, you will need to enter the port 22. (4.)

Connecting to Raspberry Pi FTP Server using FileZilla Details

3. At this point, you should enter in all the connection details for your Raspberry Pi FTP server.

Once you are happy everything is correct, connect by clicking the Quickconnect button.

Using FileZillas QuickConnect Function

4. If everything is working as it should be you should now be successfully connected over FTP or SFTP.

5. To make sure everything is working you should now test the connection by transferring a couple of files.

External Access

If you want to access FTP outside your internal network, then please follow my guide on setting up Raspberry Pi port forwarding.

The port you want to forward for SFTP is 22.

If you’re going to enable plain FTP, then you will need to forward port 21 as well.

I would suggest having a different external port then to the standard internal port to make it harder for someone to try and gain access.

Troubleshooting

Permission denied: This means you’re trying copy files to or from a place where your current user doesn’t have the correct permissions.

To fix this issue, you will need to change the permission of that particular location to allow your current user or login with a different user.

You might find that FTP isn’t enough for what you require. If you’re looking for something a little more advanced, then the network attached storage tutorial might take your fancy.

Using the tutorial you can set your Pi up to act as a NAS by using protocols such as SAMBA.

I hope this guide has provided you with enough information to get your Raspberry Pi up and running with either FTP or SFTP.

If you do come across some issues or you notice a mistake then please don’t hesitate to leave a comment below.

 

AFP

 

The Apple Filing Protocol is Apple’s proprietary network protocol for delivering files over a network. It is Apple’s alternative to the Server Message Block (SMB) and Network File System (NFS) protocols.

By following this tutorial, you will be able to share any directories on your Raspberry Pi using AFP and easily connect to them from a device running the Mac OS X operating system.

All of this is made possible by the “Netatalk” software. This software implements the “AFP” protocol at a server level allowing your Raspberry Pi to serve files over it.

There are plenty of other NAS solutions that you can take advantage of so if this doesn’t take your fancy I highly suggest taking a look at them.

Setting up Apple File Protocol (AFP) On your Raspberry Pi

1. Now before we can setup the Apple File Protocol (AFP) on your Raspberry Pi, we must first ensure that the operating system is up to date.

To ensure everything is up to date run the two commands below.

sudo apt update
sudo apt upgradeCopy

2. With the Raspberry Pi now up to date, we can now proceed to install the package that will be handling everything.

The package that we are installing is called Netatalk. Netatalk is a free and open source implementation of the Apple Filing Protocol (AFP).

The Netatalk program acts as a file server that is capable of serving many Mac clients as it allows your Raspberry Pi to act as an AppleShare file server.

Install the Netatalk application to your Raspberry Pi by running the following command.

sudo apt install netatalkCopy

3. As we have now installed the netatalk software, we will now have to go ahead and configure it to share different directories.

We will explain how to make a connection to thedr AFP share in our next section but for now, let’s look into adding directories to be shared.

To do this, we must modify the “afp.conf” file by running the command below.

sudo nano /etc/netatalk/afp.confCopy

4. Within this file add the following text to the bottom of the file.

Adding Home Directories
[Homes]
  basedir regex = /home

This block defines our home directories. This block will allow any connecting user to access their respective home folders.

We define the “basedir regex” so that the Netatalk software knows where to look for the users home directory.

If you would like to lock the user to a specific directory within their home path, you can add the following option. With being the name of that directory.

[Homes]
  basedir regex = /home 
  path = <foldername>
Adding Custom Directories
[My AFP Share Name]
  path = /path/to/directory

Using something like above we can share any directory that we want.

Within the square brackets ([ ]) that designate the start of the share is the name given to said share.

The “path=” option is the path to the directory that you want to share over the AFP protocol.

Making a share an Apple Time Machine share
[My AFP Share Name]
  path = /path/to/directory
  time machine = true

You can specify any share as a time machine capable share by simply adding the option “time machine = true” under it.

Making a share read only
[My AFP Share Name]
  path = /path/to/directory
  read only = true

If you would like to make a share read-only, all you have to do is add “read only = true” to it. This option is useful for shares, such as sharing a media library.

Setting the guest account
[Global]
  guest account = pi

You can specify a guest account to utilize for connections by setting “guest account =” under the “[Global]” header. By default, this is set to “nobody“.

You can find more information about the options that you can specify by going to NetaTalk’s configuration documentation.

5. With changes to the configuration complete, you can go ahead and save the file by pressing CTRL + X then Y followed by ENTER.

6. As we have made changes to Netatalk’s configuration, we need to restart the service so that it can utilize the new config.

We can restart the service by running the following command.

sudo systemctl restart netatalkCopy

7. Before we connect to our newly shared folders, we should retrieve the IP address assigned to our Raspberry Pi.

Make sure you have an active network connection by using either WiFi or an Ethernet cable.

Write this IP down as we will need it for connecting to the shared drive.

sudo hostname -ICopy

Connecting to your Pi’s AFP share on MAC OS X

1. To connect to your Raspberry Pi’s AFP share begin by opening the “Finder” application available on the Mac OS X operating system.

Opening Finder on Mac OS X

2. Now that we have opened up the “Finder” application go ahead and click “Go” (1.) in the toolbar at the top of the screen. Next, click the “Connect to Server…” (2.) option.

Mac OS X Connect to AFP protocol

3. Within this dialog, you will need to enter your Raspberry Pi’s IP address in front of the “afp://” protocol (1.).

For example, with our Raspberry Pi’s IP address being “192.168.0.159” we need to enter “afp://192.168.0.159” into the input box.

Once entered, click the “Connect” button (2.) to proceed.

Mac OS X Enter Raspberry Pi AFP Details

4. Upon connecting to your Raspberry Pi, you will be greeted by a dialog asking you to enter a username and password to connect to the Apple Filing Protocol server (1.).

As we are just using the default user, we only used “pi” as the name and “raspberry” as the password.

Once you have entered a user to connect with, go ahead and click the “Connect” button (2.) to proceed.

Mac OS X Enter AFP Share Login Details

5. Upon successfully logging into your Raspberry Pi’s AFP share you will now be asked what volumes that you want to mount.

This dialog will show all directories that you set up earlier in the tutorial, each referenced by the name you put next to that share in the config file.

Select the volumes that you want to be mounted (1.) Then click the “Ok” button to proceed.

Raspberry Pi AFP - Step 05 - Select Drives

6. Finally, you will now be able to see the shares that you mounted to your Mac OS X device.

Below we have included a screenshot showing the networked drives under “Locations” in the sidebar. We also show the shared volumes that are within the “Finder” application.

Raspberry Pi AFP - Step 06 - Drives in finder

At this point, you should now have the Apple Filing Protocol running on your Raspberry Pi. You should also be able to use a MAC OS X device to connect to your shared folders over the AFP protocol successfully.

If you have any feedback regarding this tutorial, then please don’t hesitate to leave a comment below.

 

 

hr style="hrstyle10"

 

NFS

 

The Network File System (NFS) protocol was initially developed by Sun Microsystems back in 1983. It was designed as a method for allowing a client computer to access files over a network.

Thanks to the NFS protocol being an open standard that’s defined in RFC, anyone can implement it easily. It has become well used for network administrators setting up a NAS.

Throughout this tutorial, we will walk you through the process of installing the required packages to get the NFS protocol running on your Raspberry Pi.

On top of that, we will show you how to share directories using the NFS protocol.

Lastly, we will show you how to then connect to your Raspberry Pi’s NFS share from both Windows and Mac OS X operating systems.

If you’re ready to get started, then you can find the full tutorial right below.

Setting up Network File System (NFS) On your Raspberry Pi

1. The first thing we must do before we proceed with setting up the Network File System (NFS) protocol on our Raspberry Pi is ensuring all packages are up to date.

To do that on the Raspbian operating system, run the following command.

sudo apt-get update
sudo apt-get upgradeCopy

2. With the Raspberry Pi up to date, we can go ahead and install the packages that we will be relying on for the NFS share.

In this guide, we will require the use of the “nfs-kernel-server” package. This package builds the foundation of serving files over the NFS protocol from our Raspberry Pi.

The “nfs-kernel-server” package handles the server side of the NFS protocol and allows us to share drives easily.

To install these packages, we need by running the following command.

sudo apt-get install nfs-kernel-server -yCopy

3. Now that we have installed the NFS server-side software, we can now proceed to set up an NFS share on the Raspberry Pi.

For this guide, we will be just making a directory within the “/mnt/” directory called “nfsshare“.

If you have already mounted a drive or want to share a different directory make sure you replace “/mnt/nfsshare” in the next few sections of the tutorial with the directory you wish to use.

sudo mkdir /mnt/nfsshareCopy

4. The next thing we need to do is assign the correct rights to the folder we want to share on the network.

To do this, we will be using the following three commands. Each of these commands has a particular purpose.

The first command gives ownership of all the files and folders contained within the directory to the “pi” user and the “pi” group.

The second line searches for all directories within our “/mnt/nfsshare” folder and runs the chmod command to give each directory “755” (Read/Write/Execute for Owner, Read/Execute for Group and Other) permissions.

The third line does a similar thing, but instead searches for all files within the directory and applies “644” (Read/Write for Owner, Read for Group and Other) permissions to the file.

For a better understanding of permissions, be sure to check out the Linux permissions tutorial.

sudo chown -R pi:pi /mnt/nfsshare
sudo find /mnt/nfsshare/ -type d -exec chmod 755 {} \;
sudo find /mnt/nfsshare/ -type f -exec chmod 644 {} \;Copy

5. Next, we will need to retrieve both the “gid” (Group id) and “uid” (User id) for the user that you want to use for accessing the files. You can do this by running the command below.

For this tutorial, we will be just using the “pi” user, but you can utilize this for any user you want.

id piCopy

6. From the previous command, you should get a result as we have shown below.

Make a note of the gid and uid values as you will need these for a step later on.

uid=1000(pi) gid=1000(pi) 

7. Now that we have everything we need and have prepared a folder to share. We need to go ahead and modify the “exports” file by running the command below.

The Raspberry Pi NFS server software that we installed earlier reads from this file to know what directories to share out over the NFS protocol.

sudo nano /etc/exportsCopy

8. Here is where things get a little bit more complicated.

If you want to share the folder so that anyone can gain access to the folder and read and write to it, you can insert the following line without any worry.

We will break down this line further so you can understand what it does, you can, however, read the documentation on the NFS “exports” file.

Make sure that you replace the “anonuid” with the “uid” value you retrieved in step 6, and replace the “anongid” with the “gid” value you also retrieved in step 6.

/mnt/nfsshare *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)Copy

Below is our breakdown of the line so that you get an understanding of what it is doing.

/mnt/nfsshare

This part of the line defines the directory that we want to share. In our case, this is the “/mnt/nfsshare” folder that we created earlier.

*(NTFS Options)

This asterisk defines that all connecting IP addresses should be allowed to access this share. You can change this to allow specific IP’s or an IP range by changing the “*” to the IP.

To allow all IP’s from “192.168.0.0” to “192.168.0.256“, we can replace the asterisk with “192.168.0.0/24“.

All the options contained within the brackets are applied just for that IP address, you can define multiple different IP’s each with their own set of options.

(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

rw – This option allows both read and write requests on the NFS volume.

all_squash – This option will map all uids and gids to the anonymous user.

insecure – This option allows clients with an NFS implementation that doesn’t use a reserved NFS port.

async – This option allows the NFS server to break the NFS protocol to improve performance at the cost of data potentially becoming corrupted if the server crashes.

no_subtree_check – This disables subtree checking, while it comes at a cost to security it can improve the reliability of the NFS server. You can read more about this on the exports documentation page we linked earlier.

anonuid – This is the UID to utilize for a user that is connecting anonymously.

anongid – This is the GID to use for a user that is connecting anonymously.

9. Once you have entered the line, you can then proceed to save the file by pressing CTRL + X then Y followed by ENTER.

10. Now for our newly added folder to be accessible through the NFS protocol, we must run the “exportfs” package by running the command below.

This application updates the current table of exports available to the NFS server.

sudo exportfs -raCopy

11. The last thing we need to do is retrieve our Raspberry Pi’s local IP address by running the command below.

You will need to ensure your Pi is connected to network by either setting up the WiFi or using a ethernet cable.

We need this IP address so that we can successfully connect to the Raspberry Pi NFS server.

hostname -ICopy

Connecting to your Raspberry Pi’s NFS Share on Windows

1. To interact with NFS shares on Windows, we need first to enable the NFS client. By default, this feature is disabled on Windows installations.

To do this, you must search for “turn windows features on or off” within Windows and click the “Turn Windows features on or off” option that appears as shown below.

Search Turn Windows Features on and off

2. Within this menu, search for the “Services for NFS” (1.) folder and click the checkbox to enable all available features.

Once done, click the “OK” button (2.) to finalize the settings. Your windows installation will proceed to set up everything that is required to connect with an NFS share.

Windows Turn on services for NFS

3. Now open up file explorer, and you should be able to see the “Map network drive” option.

Click this option to continue the process of connecting your Raspberry Pi’s NFS share to your computer.

Windows File Explorer Map Network Drive

4. On this screen, you need to enter your Raspberry Pi’s IP address followed by the folder we mounted to the NFS Share (1.).

For example, with our Raspberry Pi’s IP address being “192.168.0.159” and the folder we set up is at “\mnt\nfsshare“. The “folder” that we will be “\\192.168.0.159\mnt\nfsshare“.

Once entered, click the “Finish” button (2.) to finalize the connection.

Windows Map Network Drive NFS Details

5. You should now be able to see your shared Raspberry Pi NFS folder under “Network Locations” or “Network” on your Windows device.

Windows View NFS Networked Drives

Connecting to your Pi’s NFS Share on Mac OS X

1. Now it’s time to connect to your Raspberry Pi’s NFS Share on MAC OS X, and you will have to start by opening up the Finder application.

Mac OS X Opening Finder

2. With the “Finder” application open, click “Go” (1.) in the toolbar at the top of the screen and then click the “Connect to Server...” (2.) option.

MAC OS X Connect to NFS protocol

3. Next, you will be required to enter the address that you want to connect to (1.).

The address that you need to enter into this is a combination of the “nfs:\\” protocol, followed by your Raspberry Pi’s IP address. Lastly, it ends with the directory that you are trying to access.

For example, with the IP “192.168.0.159” and the folder we shared on the Pi being “\mnt\nfsshare” the address we would enter is “nfs:\\192.168.0.159\mnt\nfsshare

Once done, click the “Connect” button (2.) to link the shared volume.

MAC OS X Connect to NFS Server

4. If a connection is successful, you will see a new window that shows you the inside of the folder that you shared using the NFS Protocol on your Raspberry Pi.

MAC OS X Raspberry Pi NFS Connected

You can also find the folder again by looking in the “Locations” section in the Finder sidebar.

By now you should have your Raspberry Pi NFS server setup and accessible on the network. Hopefully, you will be able to easily connect to it using a Windows PC or a Mac OS X computer.

Be sure to also check out our guide on connecting to an NFS server on your Raspberry Pi.

If you have any feedback, tips, or anything else, then please don’t hesitate to leave a comment below.

 

Own Cloud

 

As the protection of your privacy becomes harder and harder, you may be thinking of moving your files to a private cloud storage. If this is the case, then this tutorial is perfect for you.

It is important to remember that since your data will be stored on your local network, you will end up with using more bandwidth if uploading and downloading files from outside your network.

This tutorial will take you through everything you need to know to get Owncloud setup and accessible.

If you’re curious and want to learn more about the Owncloud software, then be sure to check out their website over at Owncloud.org.

I made use of the following for this personal cloud storage setup.

Optional

Note: It is highly likely that the USB ports on the Raspberry Pi will be unable to power an external hard drive so you may need to invest in a powered USB hub.

Video

If you’re a visual person and would like to see our video on how to put this tutorial together, then check out the video below.

It will take you through everything you need to know get your Raspberry Pi Owncloud server up and running.

Setting up The Raspberry Pi Owncloud Server

Firstly, you will need to have a Raspberry Pi with Raspbian installed. If you haven’t installed Raspbian, then check out our guide on how to install Raspbian via NOOBS (New Out of the Box Software).

There are quite a few ways you’re able to install Owncloud onto your Raspberry Pi. In this particular tutorial, we’re going to be downloading a web server (Nginx) and Owncloud.

Installing NGINX and PHP

The first thing we need to do is install both NGINX and PHP to our Raspberry Pi. We will need both of these pieces of software to run the Owncloud software.

1. Firstly, in either The Pi’s command line or via SSH, we will need to update the Raspberry Pi and its packages, do this by entering:

sudo apt update
sudo apt upgradeCopy

2. Next, we need to add the www-data user to the www-data group.

sudo usermod -a -G www-data www-dataCopy

These instructions have been updated to work with Raspberry Pi OS Bullseye. If you’re on an earlier version, then I highly recommend you upgrade to Raspbian Bullseye before continuing.

You can follow our guide on upgrading from Raspberry Pi OS Buster to Bullseye.

Alternatively, we do have a workaround if you want to stick with an older release of Raspberry Pi OS.

3. Once you are running Raspbian Buster, you can safely continue with this tutorial.

In this step, we will be installing all the packages that we require to run Owncloud. This includes PHP 7.4 and its numerous modules that OwnCloud relies upon.

Run the following command to install everything we need.

sudo apt-get install nginx openssl ssl-cert php7.4-xml php7.4-dev php7.4-curl php7.4-gd php7.4-fpm php7.4-zip php7.4-intl php7.4-mbstring php7.4-cli php7.4-mysql php7.4-common php7.4-cgi php7.4-apcu php7.4-redis redis-server php-pear curl libapr1 libtool libcurl4-openssl-devCopy

When running this command on older versions of Raspberry Pi OS, you might run into a “package not found” error. You can work around most of these by adding a third-party PHP repository to your operating system.

Setting up NGINX for Owncloud and HTTPS

Our next step is to now set up and configure NGINX for it to work with the Owncloud software. We will also be setting NGINX up so that it can support HTTPS connections as well. 1. Now we need to create an SSL certificate you can do this by running the following command:

sudo openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.keyCopy

Just enter the relevant data for each of the questions it asks you.

2. In addition to the SSL certificate, we also need to generate a custom dhparam file. This file helps ensure that our SSL connections are kept secure. By default, this would use a default one that isn’t nearly as secure.

To generate a 2048 byte long dhparam file, run the following command on your Raspberry Pi. This process will take quite a long time, up to 2 hours.

Adding the dhparam flag to the command will help speed up the process, but arguably is less secure.

sudo openssl dhparam -out /etc/nginx/dh4048.pem 2048Copy

3. Now we need to chmod the three cert files we just generated.

sudo chmod 600 /etc/nginx/cert.pem
sudo chmod 600 /etc/nginx/cert.key
sudo chmod 600 /etc/nginx/dh4048.pemCopy

4. Let’s clear the server config file since we will be copying and pasting our own version in it.

sudo sh -c "echo '' > /etc/nginx/sites-available/default"Copy

5. Now let’s configure the web server configuration so that it runs Owncloud correctly. I use the nano text editor to edit most files.

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

6. Now simply copy and paste the following code into the file.

upstream php-handler {
    server unix:/var/run/php/php7.4-fpm.sock;
}

server {
    listen 80;
    server_name _;

    #Allow letsencrypt through
    location /.well-known/acme-challenge/ {
        root /var/www/owncloud;
    }

    # enforce https
    location / {
        return 301 https://$host$request_uri;
    }
}
  
server {
    listen 443 ssl http2;
    server_name _;
  
    ssl_certificate /etc/nginx/cert.pem;
    ssl_certificate_key /etc/nginx/cert.key;

    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:AES256+EDH';
    ssl_dhparam /etc/nginx/dh4048.pem;
    ssl_prefer_server_ciphers on;
    keepalive_timeout    70;
    ssl_stapling on;
    ssl_stapling_verify on;
  
    add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" always;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
  
    root /var/www/owncloud/;
  
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
  
    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
  
    location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
    }
  
    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 8 4K;
    fastcgi_ignore_headers X-Accel-Buffering;
  
    gzip off;
  
    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;
  
    location / {
        rewrite ^ /index.php$uri;
    }
  
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        return 404;
    }

    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        return 404;
    }
  
    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_read_timeout 180;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off; #Available since NGINX 1.7.11
    }
  
    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri $uri/ =404;
        index index.php;
    }
  
    location ~ \.(?:css|js)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "max-age=15778463";
        add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        access_log off;
    }

    location ~ \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg|map)$ {
        add_header Cache-Control "public, max-age=7200";
        try_files $uri /index.php$uri$is_args$args;
        access_log off;
    }
}
Copy

7. Now save and exit out of the file by pressing CTRL + X, then Y, followed by ENTER.

8. As we have made changes to NGINX’s configuration we need to restart it’s service by running the following command.

sudo systemctl restart nginxCopy
Tweaking PHP for Owncloud

With NGINX now set up, we can now go ahead and prepare PHP to work with our Owncloud installation. As we use php-fpm, there are a few additional things we need to do.

1. Now that is done, there are a few more configurations we will need to update, first open up the PHP config file by entering.

sudo nano /etc/php/7.4/fpm/php.iniCopy

2. In this file, we want to find and update the following lines. (CTRL + W allows you to search)

Find

upload_max_filesize = 2MCopy

Replace With

upload_max_filesize = 2000MCopy

Find

post_max_size = 8MCopy

Replace With

post_max_size = 2000MCopy

3. Once done, save and then exit by pressing CTRL + X, followed by Y, then ENTER.

4. Our next step is to make some changes to the php-fpm pool configuration. The reason for this is that php-fpm can’t access environment variables.

Run the following command to begin modifying the configuration file.

sudo nano /etc/php/7.4/fpm/pool.d/www.confCopy

5. Within this file, find the following block of code and replace it with what we have below.

You can use CTRL + W to find this block of code faster. Typically its located near the bottom of the file.

Find

;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmpCopy

Replace With

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmpCopy

6. With these changes made, go ahead and save the file by pressing CTRL + X, followed by Y, then ENTER.

Adding Swap Memory

Our next step is to add some swap memory to our system.

Adding swap memory allows the Raspberry Pi to work further beyond its memory by making use of space on the storage device. While a lot slower then RAM it is better then the program crashing

1. To increase the amount of swap memory, we need to modify a file called dphys-swapfile.

To modify this file, make use of the following command:

sudo nano /etc/dphys-swapfileCopy

2. Within this file, find the following line and change it to what we have below.

Find

CONF_SWAPSIZE=100Copy

Replace With

CONF_SWAPSIZE = 512Copy

3. Once done, save and then quit by pressing CTRL + X, followed by Y, then ENTER.

4. For our changes to take effect, we will need to now restart the Raspberry Pi by running the command below.

sudo rebootCopy
Setting up a MySQL Database & User for Owncloud

Before beginning this section, you must have already set up a MySQL server on your Raspberry Pi.

1. To be able to create our database, we will need to make use of the MySQL command-line interface.

We can load up the tool by running the following command.

sudo mysql -u root -pCopy

2. Once logged in, you can begin interacting with your MySQL server.

The database we will be creating is called ownclouddb. We can create this database by running the following command.

CREATE DATABASE ownclouddb;Copy

3. With the database created, let’s now create a user that can interact with it.

We can create a user called ownclouduser by running the command below. Make sure that you replace [PASSWORD] with a secure password and make a note of it for later.

CREATE USER 'ownclouduser'@'localhost' IDENTIFIED BY '[PASSWORD]';Copy

4. Our next step is to give access permissions to our new user.

We can grant these privileges by running the following command.

GRANT ALL PRIVILEGES ON ownclouddb.* TO 'ownclouduser'@'localhost';Copy

5. The final task is to flush the privileges. If we don’t do this, then our changes won’t be utilized by the server.

To flush the privileges, all we need to do is run the following command.

FLUSH PRIVILEGES;Copy

Once the privilege table has been flushed, we can proceed to install and set up the Owncloud software.

Downloading & Extracting Owncloud

Now in this section, we will be installing the actual Owncloud software on to our Raspberry Pi. Installing Owncloud requires a couple of straightforward steps.

1. Once the Pi has restarted, you will need to install Owncloud onto the Raspberry Pi.

Let us change to the directory where we will be running the script from.

cd /var/www/Copy

2. Now that we are in the right directory we can now download the latest version of Owncloud.

To do this we will make use of wget by running the command below.

sudo wget https://download.owncloud.org/community/owncloud-latest.tar.bz2Copy

3. Now extract the archive we downloaded by using the tar command.

sudo tar -xvf owncloud-latest.tar.bz2Copy

4. With everything extracted we need to make sure that the www-data owns the files.

We can recursively modify the permissions of the file by using the chown command.

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

5. Now we need to open up the .user.ini file to enforce some of the changes we made earlier in the tutorial

sudo nano /var/www/owncloud/.user.iniCopy

6. In here update the following values, so they are 2000M:

upload_max_filesize=2000M
post_max_size=2000M
memory_limit=2000MCopy

7. Now that is done, we should be able to connect to Owncloud at your PI’s IP address.

Before you set up the admin account, you might want to mount an external drive, so you have lots of disk space for your Raspberry Pi Owncloud server. Just follow the instructions in the next section.

Mounting & Setting up a Drive

Setting up an external drive while should be relatively straightforward but sometimes things don’t work as correctly as they should.

These instructions are for mounting and allowing Owncloud to store files onto an external hard drive.

1. Firstly if you have an NTFS drive we will need to install an NTFS package by entering the following:

sudo apt-get install ntfs-3gCopy

2. Now let’s make a directory we can mount.

sudo mkdir /media/ownclouddriveCopy

3. Now we need to get the GID, UID, and the UUID as we will need to use these soon. Enter the following command for the GID:

id -g www-dataCopy

4. Now for the UID enter the following command:

id -u www-dataCopy

5. Also if we get the UUID of the hard drive, the Pi will remember this drive even if you plug it into a different USB port.

ls -l /dev/disk/by-uuidCopy

UUID Hard Drive

Copy the light blue letters and numbers of the last entry (Should have something like -> ../../sda1 at the end of it).

6. Now let’s add your drive into the fstab file so that it will boot with the correct permissions.

sudo nano /etc/fstabCopy

7. Now add the following line to the bottom of the file, updating UID, GUID and the UUID with the values we got above. (The following should all be on a single line)

UUID=DC72-0315 /media/ownclouddrive auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0Copy

8. Reboot the Raspberry Pi, and the drives should automatically be mounted. If they are mounted, we’re all good to go.

Note: If you get an error stating the Pi is in emergency mode at boot up then this likely means a problem with the fstab entry. Just edit the fstab file (sudo nano /etc/fstab) and remove the added line or look for a mistake and fix it.

Setting up Owncloud

I will briefly go through the basics of setting up Owncloud Raspberry Pi here. If you want more information, I highly recommend checkout out the manuals on their website. You can find them at the Owncloud manual site here.

1. In your favorite web browser, you need to go to your Raspberry Pi’s IP address.

If you don’t know your Pi’s local IP, you can run the hostname command.

hostname -ICopy

2. Once you go to the IP you’re like to get a certificate error, add this to your exception list as it will be safe to proceed.

On Chrome, you click the Show advanced button (1.).

Then click “Proceed to [YOURPISIPADDRESS] (unsafe)” (2.).

Raspberry Pi Owncloud Server Chrome Security Warning

3. When you first open up Owncloud, you will need to do some initial setup steps.

The first thing you need to do is specify a username and password for your Owncloud admin account. (1.)

Next, we need to bring up the storage and database settings. You can do this by clicking the “Storage & database” dropdown (2.).

If you are using a different data folder, you can specify it now by using the Data folder textbox (3.)

We then need to bring up the MySQL database options. You can find these by clicking the MySQL/MariaDB toggle (4.).

Next, we need to fill out three bits of information, the database user, the password for that user, and the database name.

  1. First, you need to specify the “Database user” (A.). If you are following this guide, this should be ownclouduser.
  2. The second option you will need to specify the password you set for the above user. (B.)
  3. Finally, we need to set the database name. (C.) If you have used the ones from this tutorial, you should set this to ownclouddb.

Once you have finished with all the settings, click the Finish setup button (4.).

Owncloud Server Setup Configuration Screen

If you ever need to update and you find the internal updater is not working, this likely means you will need to do it manually.

You can find a detailed process on how to update over at Owncloud’s update manual page.

The next two sections will show you how to improve your Owncloud software even further.

Setting up Memory Caching for Owncloud

In this section, we will be showing you how to configure Owncloud to make use of APCu and Redis. APCu is used as an object memory cache, and Redis is used to deal with transactional file locking.

Using both of these will help improve the performance of Owncloud on your Raspberry Pi.

1. To be able to enable these, we ill need to make a change to the Owncloud configuration file.

Begin editing this file by running the following command.

sudo nano /var/www/owncloud/config/config.phpCopy

2. Within this file, find the following line and add the block of text below it.

Find

'installed' => true,Copy

Add Below

  'memcache.local' => '\OC\Memcache\APCu',
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => [
    'host' => 'localhost',
    'port' => 6379,
  ],
Copy

3. Once done, save the file by pressing CTRL + X, then Y, followed by ENTER.

Using System Cron with Owncloud

The Owncloud team recommends that you should set it up so that the operating system runs the scripts cron jobs instead of Ajax.

1. To be able to set up a cron job for Owncloud, we will need to make use of the www-data user’s crontab.

Begin modifying the user’s cron by running the following command.

sudo crontab -u www-data -eCopy

If you are asked what editor you should use to modify the crontab, we highly recommend that you use nano.

2. Add the following line to the bottom of this file.

*  *  *  *  * /usr/bin/php /var/www/owncloud/occ system:cronCopy

This line will run Owncloud’s cron job every minute.

3. Once done, save the file by pressing CTRL + X, followed by Y, then ENTER.

You should now have Owncloud set up correctly on your Raspberry Pi.

Port Forwarding & External Access

If you want to have access to your cloud drive outside your local network, then you will need to setup port forwarding and make a few changes to our config files.

You can get your external IP address at what is my IP.

If you have a dynamic IP you may want to set up a dynamic DNS and use that as your address. You can find information on this in my guide to port forwarding.

To do this open up the Owncloud config file by using the following command.

sudo nano /var/www/owncloud/config/config.phpCopy

In here add a new item to the trusted domains array (This will be your external IP address). Your new entry should look something like this (x are just placeholders).

1 => 'xxx.xxx.xxx.xxx',Copy

Finally update the URL of the overwrite.cli.url line to your IP Address. It should look something like this.

'overwrite.cli.url' => 'https://xxx.xxx.xxx.xxx',Copy

Below is an example of the completed config.txt file.

External IP Change Example

Be sure to check out my guide on port forwarding and use the following port 443 for internal, and I recommended a random port for the external port. Make sure when setting up the external port that it isn’t already reserved for a specific program.

When connecting to the Owncloud server externally, you will need to make sure you use https otherwise you will get an invalid request in your browser.

Setting up port forwarding is super easy to do and allows you to have access to your personal cloud on the go. Also after you have done this, you can still connect via your local IP as well.

I hope this tutorial has helped you make your very own Raspberry Pi OwnCloud. If you have any troubles, want to leave feedback or if I have missed anything feel free to drop us a comment below.

 

NextCloud

 

As time goes on the protection of your own privacy with 3rd party companies becomes harder and harder. This is where software like Nextcloud comes in hand, as it gives you full control over your files with no 3rd party controller.

It is important to remember that since your data will be stored on your local network you will end up using a lot of bandwidth when uploading and downloading files from outside your local network. If your internet connection is not great then you may not get the best experience if you plan on using it outside your local network.

If this looks familiar then that’s because it likely is, Nextcloud is an actively maintained fork of the owncloud software that I have previously covered. The longer it’s in development the more different these two software packages will likely become, I suggest looking into both and then deciding on which one to go with.

If you want to learn more about Nextcloud, you can check out the nextcloud website.

Note: The USB ports on a Raspberry Pi are typically unable to power an external hard drive. If you find this the case and your hard drive doesn’t use an external power supply then I recommend looking into buying a powered USB hub for the Pi.

List

You can find all the bits and pieces that I used/recommend for this Raspberry Pi Nextcloud tutorial right below.

Optional

Installing Apache and PHP

To run Nextcloud on the Raspberry Pi we will first need to install and setup Apache and PHP.

We won’t be going too in-depth into installing these as they are a minor components to this tutorial.

If you want to learn more about setting up a Web Server, then be sure to follow our tutorial on how to do this.

For the best performance I recommend using Raspbian lite but just normal Raspbian will also work just as well.

If you need information on how to set this all up check out the guide in the Pi operating systems section.

For this tutorial, we will make use of the latest available version of PHP 8.

1. To get started let’s first update our package repositories with the following command:

sudo apt update
sudo apt upgradeCopy

2. With that done, let’s now install apache with the following command:

sudo apt install apache2Copy

You can check to make sure Apache2 is successfully up and running by going to your Pi’s IP address, this should load a default Apache Page.

If you are unsure on what your Raspberry Pi’s local IP address is then type in hostname -I into the terminal.

3. With Apache2 now installed onto the Raspberry Pi, we just need to install PHP and several of its packages.

For this tutorial, we will be using PHP 8.0. This version of PHP is available on Raspberry Pi OS Bullseye. You can either upgrade to Raspberry Pi OS Bullseye or add a third-party PHP repository.

To install PHP and the packages we need, run the following command.

sudo apt install php8.0 php8.0-gd php8.0-sqlite3 php8.0-curl php8.0-zip php8.0-xml php8.0-mbstring php8.0-mysql php8.0-bz2 php8.0-intl php-smbclient php8.0-imap php8.0-gmp libapache2-mod-php8.0Copy

4. With Apache and PHP now installed there is one final thing we need to do, and that is to restart Apache.

You can do this now making use of the following command:

sudo service apache2 restart Copy

Setting up a MySQL Database and User for Nextcloud

In this section we will be showing you how to set up a user and database for Nextcloud to use to store its data.

Before beginning this section you must have set up a MySQL server on your Raspberry Pi already.

1. The first thing we need to do is open the MySQL command line tool by running the following command.

We will be using this command line tool to create a user and database for MySQL.

sudo mysql -u root -pCopy

2. Once you have logged in to the tool, we can start by creating a database.

We will be creating this database called nextclouddb by running the following command.

CREATE DATABASE nextclouddb;Copy

3. Our next step is to create a user that we will be using to interact with our new database.

We will be creating a user called nextclouduser by running the command below. Make sure that you replace [PASSWORD] with a secure password and make note of it for later.

CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY '[PASSWORD]';Copy

4. With our user created we need to now give it permissions to interact with our database.

We can do that by running the following command.

GRANT ALL PRIVILEGES ON nextclouddb.* TO 'nextclouduser'@'localhost';Copy

This command grants the user nextclouduser all privileges on the nextclouddb database and all of its tables.

5. Our final task is to flush the privilege table.

To flush the privileges all we need to do is run the following command.

FLUSH PRIVILEGES;Copy

With this done, we can now proceed to install Nextcloud on our Raspberry Pi.

Downloading Nextcloud on your Raspberry Pi

Getting Nextcloud on your the Raspberry Pi is quite simple, it mainly involves downloading the zip file from their website, extracting it and then making some .

1. To get started let’s first move to our html directory with the following change directory command.

cd /var/www/Copy

2. Now we can download the latest version of Nextcloud to our device.

To do this we will use wget to download the latest release to the current folder.

sudo wget https://download.nextcloud.com/server/releases/latest.tar.bz2Copy

3. With Nextcloud now downloaded to our Raspberry Pi, let us extract the archive.

To extract the archive using tar we need to use the command below.

sudo tar -xvf latest.tar.bz2Copy

4. We now need to create a data directory for Nextcloud to operate in, for the initial setup of Nextcloud we must make this folder in our html/nextcloud directory.

Create the directory by using the following command:

sudo mkdir -p /var/www/nextcloud/dataCopy

5. Now let’s give the correct user and group control over the entire Nextcloud folder and everything inside it by running the following chown command.

sudo chown -R www-data:www-data /var/www/nextcloud/Copy

6. Finally we need to give it the right permissions, again run the following chmod command.

sudo chmod 750 /var/www/nextcloud/dataCopy

Configuring Apache for Nextcloud

Next, we need to deal with the .htaccess file for Nextcloud.

Since we installed Nextcloud into the default Apache2 directory /var/www/, we will need to change some settings in Apache2 to allow the .htaccess file to override settings.

To handle this just for the Nextcloud directory we will be creating a new configuration file.

1. To get started let’s create a file which will store our configuration changes for Nextcloud:

sudo nano /etc/apache2/sites-available/nextcloud.confCopy

2. Within this file enter the following lines.

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off
  </IfModule>

</Directory>Copy

These lines basically tell Apache2 how to handle itself within the /var/www/nextcloud/ folder.

These changes will allow Apache2 to read and utilize the .htaccess files within the Nextcloud directory.

3. Now we can save and quit out of the file by pressing CTRL + X then pressing Y and then ENTER.

4. With the file created we now need to tell Apache to make use of it.

We can do this by utilizing the a2ensite command followed by nextcloud.conf.

sudo a2ensite nextcloud.confCopy

5. Now we need to restart Apache2 to force it to read in the updated configuration file. We can do that easily with the following command:

sudo systemctl reload apache2Copy

With that done you can now move on to setting up the Nextcloud software within its web interface.

Nextcloud Initial Setup

1. Now that we have finished with that we can now finally go to Nextcloud itself and begin its installation process.

To begin go to your Raspberry Pi’s IP address plus /nextcloud.

If you don’t know your Raspberry Pi’s IP address you can make use of the command hostname -I.

Remember to replace [IPADDRESS] with that of your Raspberry Pi’s.

[IPADDRESS]/nextcloudCopy

2. You will now be greeted with the following screen.

Here you will need to type in the Username and Password (1.) that you intend to use for your admin account.

If you plan on allowing your Nextcloud file service to be accessible from outside your network, make sure that you use a long and secure password.

Next, we need to specify the details for our database server. To get to these options you will need to click the “Storage & Datbase” option (2.).

Now you need to slect the type of database we want to use. As we are using an SQL server click the “MySQL/MariaDB” (3.) option.

Finally we need to enter the details for our database server. There are three bits of information that we will need to enter.

  1. The username for the user that will interact with our database server. (A.) If you are using the same information we used, this setting should be set to nextclouduser.
  2. The password that you set for the above user. (B.)
  3. The final option you will need to set is the database name. (C.) If you have been following our guide this will be nextclouddb.

Once you are happy with this, press the “Finish Setup” button (4.), please note this can take some time to complete as it finalises your setup.

Raspberry Pi Nextcloud Set up Screen

3. After this you should now be greeted with the following welcome screen, this just lays out the various programs you can use to connect with your Nextcloud installation.

Just click the X button in the top right corner to continue.

Nextcloud Welcome Screen

4. Now you can finally see the interface of the Raspberry Pi Nextcloud, you should take some time to familiarize yourself with all the functionality of Nextcloud’s interface.

We won’t go too in depth on how to use the Nextcloud interface, if you need more information then I recommend checking out the support section on nextcloud.

We have however highlighted some of the key areas to check out in the screenshot below.

Nextcloud Files Screen

Moving Nextcloud’s Data Folder

With Nextcloud now safely installed we can now tweak the setup to both be more secure and a bit more useable. One of the first things we should do is move the data directory so it does not sit in our web accessible directory.

This is also the same way you would move your Nextcloud data directory onto a larger external hard drive rather than putting increased load onto the Raspberry Pi’s SD Card.

1. To get started let’s make our new directory for where we will store our data files.

To make it easy we will make a new folder at /var/nextcloud and move our data folder into there.

Create the folder by running the following command:

sudo mkdir -p /var/nextcloudCopy

2. With our new folder we created we will now move our data directory into it, this is easy to do thanks to the mv command.

Please note that your Nextcloud system will be out of action while we move the file then adjust the configuration file.

To begin the move type in the following command:

sudo mv -v /var/www/nextcloud/data /var/nextcloud/dataCopy

3. Now with the files moved over we can now modify the datadirectory configuration to point to our new directory.

First, let’s change to the config directory for Nextcloud with the following command.

cd /var/www/nextcloud/configCopy

4. We can now copy the config file to make a backup of the file, we can do this with the following command:

sudo cp -p config.php config.php.bkCopy

5. Finally let’s open up the config.php file for editing using nano.

sudo nano config.phpCopy

6. Within this file we need to change the following line:

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

To

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

7. Now we can save and quit out of the file by pressing CTRL + X then Y and then ENTER.

8. As one last precuation we should make sure that the www-data user still has ownerships over our new folder.

sudo chown -R www-data:www-data /var/nextcloud/dataCopy

You should be able to now refresh your web browser and all your files should be showing exactly as they were previously.

Increasing Nextcloud’s Max Upload Size

By default, PHP has a very low upload limit, so low it’s only 2 MB. To change this, we need to modify the php.ini file and increase the limit. A cloud storage system wouldn’t be very useful if you could only ever upload 2mb files.

1. To get started we need to begin editing the configuration file with the following command:

sudo nano /etc/php/8.0/apache2/php.iniCopy

2. Now we need to find and replace the following two lines.

post_max_size = 8M
upload_max_filesize = 2MCopy

To

post_max_size = 1024M
upload_max_filesize = 1024MCopy

Of course, you can set the file size limits to something that is much higher than 20M, so feel free to change that number to whatever you think is the maximum size file you will upload to your Nextcloud.

3. Now we can save and quit out of the file by pressing CTRL + X then pressing Y and then ENTER.

Now we need to restart Apache2 to force it to read in the updated configuration file. We can do that easily with the following command:

sudo service apache2 restartCopy

4. You should now be able to restart your web browser and begin a new upload to see that the maximum upload size has been increased successfully.

Setting up SSL for Nextcloud

Now we should really work on setting up your Raspberry Pi Nextcloud server so that it runs through HTTPS and not plain HTTP.

For this tutorial, we will assume that you do not have a domain name, so we will be generating our own self signed certificate and not utilizing one from a free service such as Letsencrypt.

1. Before we go modifying our Apache2 configuration we will first generate the self-signed certificate, luckily, we can do this all in one command thanks to OpenSSL.

Remember that a self-signed certificate will throw errors in your web browser and is not as secure as a properly signed certificate but it is better than nothing. It is also the only option if you’re not utilizing a domain name.

Before we generate the certificate, let’s first make a directory to store it.

sudo mkdir -p /etc/apache2/sslCopy

2. Now let’s generate the certificate itself by running the following command in the terminal:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crtCopy

If you want to know exactly what these command arguments do, then read our little description below.

req: This specifies a subcommand for X.509 certificate signing request (CSR) management.

-x509: This option specifies that we want to make a self-signed certificate file instead of generating a certificate request.

-nodes: This tells the openssl application that we don’t want to specify a passphrase, a passphrase will require us to enter it every time Apache is restarted which is painful to deal with.

-days 365: This specifies the amount of days we want the certificate to remain valid for, after this amount of days you will have to generate a new certificate.

-newkey rsa:4096: This will create the certificate request and a new private key at the same time. You will need to do this since we didn’t create a private key in advance. The rsa:2048 tells OpenSSL to generate an RSA key that is 2048 bits long.

-keyout: This parameter names the output file for the private key file that is being created.

-out: This option names the output file for the certificate that we are generating.

After pressing enter you will be presented with the following options to fill out.

Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

3. Once you have filled out all that information we can then proceed on with setting up Apache2 to run SSL and to also utilize our newly generated certificate. This is a simple process but an important one.

First let’s enable the SSL module for Apache with the following command:

sudo a2enmod sslCopy

4. Now we need to modify the default-ssl.conf file so it will utilize our new certificates and not the default ones that are generated by OpenSSL on installation.

To begin modifying this file run the following command:

sudo nano /etc/apache2/sites-available/default-ssl.confCopy

5. Within this file we need to change the two lines below to point to our new certificates we generated into our /etc/apache2/ssl folder.

Change

SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.keyCopy

To

SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.keyCopy

6. Now we can save and quit out of the file by pressing CTRL + X then pressing Y and then Enter.

7. We can now enable the default-ssl configuration and restart Apache to load in our new configuration. We can do this with the following two commands.

sudo a2ensite default-ssl.conf
sudo service apache2 restart
Copy

8. You can test to make sure this is working by going to your Raspberry Pi’s IP address with https:// in front of it. It will give you a warning about it potentially being an invalid certificate. This is normal as it is an unsigned certificate.

For instance to make sure my own copy of Nextcloud is now running behind SSL I would go to the following.

https://192.168.1.105/nextcloudCopy

Steps 9, 10, 11 and 12 are all optional and don’t need to be completed.

9. An optional extra step to ensure that you have the best security for your Nextcloud setup is to enforce SSL so no connection can be made over HTTP, if a connection is made it will redirect you to HTTPS.

We can do this by making some changes to our apache configuration, to begin let’s edit the default file with the following command:

sudo nano /etc/apache2/sites-available/000-default.confCopy

10. Replace all the text in this file with the code below. This will basically redirect all HTTP traffic to its HTTPs equivalent.

<VirtualHost *:80>
   ServerAdmin example@example

   RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>Copy

11. Now we can save and quit out of the file by pressing CTRL + X then pressing Y and then ENTER.

12. Now before this will work we need to enable the redirect module and restart apache. We can easily achieve this by running the following two commands:

sudo a2enmod rewrite
sudo service apache2 restart
Copy

Now going to your Raspberry Pi on HTTP should automatically redirect to the HTTPS version. For example, if I go to http://192.168.1.105 it will redirect to https://192.168.1.105

Port Forwarding Nextcloud

Finally, onto the section about port forwarding Nextcloud. We won’t go into too much depth on the ins and outs of port forwarding for your router but we will tell you what ports need forwarding. We will also mention what changes need to be made to Nextcloud for this to work.

Before we get started with this section you need to know that Nextcloud will only operate under specifically specified trusted domains. Which means you will need to either specify a domain name that you want to use for your connection or use your public IP address.

Since most home public IP addresses are dynamic you will need to look into setting up a dynamic DNS service, you will find our tutorial on how to setup a dynamic DNS service for your Raspberry Pi very handy.

1. To add your domain/IP we need to modify NextCloud’s configuration file, we can do that by running the following command:

sudo nano /var/www/nextcloud/config/config.phpCopy

2. Within this file you will see a block of text like below. This is an array of all trusted domains that you allow Nextcloud to operate through.

For now, it should only include your Raspberry Pi’s local IP address. We will add our new domain/IP onto the end of this array.

'trusted_domains' =>
array (
    0 => '192.168.1.105',
),

For our example, we will be adding nextcloud.pimylifeup.com to the array. This means we need to increment the array ID and add the domain name. Once you have added a new one it should look something like below. Repeat this procedure for any new IP’s or domains you want Nextcloud to be able to operate through.

'trusted_domains' =>
array (
    0 => '192.168.1.105',
    1 => 'nextcloud.pimylifeup.com',
),

3. Now we can save and quit out of the file by pressing CTRL + X then pressing Y and then ENTER.

4. Finally you will need to port forward two ports to finally have Nextcloud up and running. These two ports being Port 80 and Port 443. The protocol required for these is TCP.

Hopefully by now you should have a fully operational Raspberry Pi Nextcloud Server.

If you come across any issues or have some feedback related to this tutorial, then please don’t hesitate to leave a comment below.

 

Scroll to Top