In this project, we will be showing you how to set up your very own Raspberry Pi eBook server by utilizing the COPS (Calibre OPDS (and HTML) PHP Server) software.
This software acts as a web interface on your Raspberry Pi where you can access all your eBooks either through its web interface or by downloading them directly from your Raspberry Pi to your devices.
This software works as a fantastic middleman for your eBooks especially if you often share your eBooks among a wide number of devices. It’s also a nice interface to sort your eBooks by author and other things.
You would find that this is a pretty handy tutorial if you wanted to the host an eBook on a server so you can access it anywhere in your house.
Below are all the bits and pieces that I used for this Raspberry Pi eBook Server tutorial.
Setting up your eBook Server with COPS
Before you begin this tutorial, please make sure that you have followed our “Setting up NGINX” guide and installed PHP. We will be using that as a base for our Raspberry Pi eBook server, due to its speed and memory efficiency.
Preparing your Raspberry Pi for COPS
1. Before we begin, let’s bring all our packages on Raspberry PI OS are up to date by running the following command in the terminal.
sudo apt update
sudo apt upgrade
2. With our Raspberry Pi now up to date, we can now install the extra PHP packages that we need to run the COPS PHP software. We will be assuming you have already installed PHP before you follow this guide.
Run the following command on your Raspberry Pi to install the extra packages.
sudo apt-get install git php8.2-gd php8.2-cli php8.2-sqlite3 php8.2-intl php8.2-xml php8.2-mbstring php8.2-zip composer
On older versions of Raspberry Pi OS, you may run into an error indicating that APT did not find a package. This issue can be worked around by adding a third-party PHP repository that contains these missing packages.
3. With our new PHP packages installed we will first have to restart NGINX for it to load in the new modules.
Simply type the following command into the terminal on your Raspberry Pi to restart NGINX.
sudo systemctl reload nginx
Setting up the eBook Server on your Raspberry Pi
4. With the PHP modules, we need now installed and NGINX restarted we can move onto setting up COPS (Calibre OPDS (and HTML) PHP Server). COPS is the PHP software that we will be using as our library maintainer, and this serves your eBooks to any device that connects to it.
Before we clone the latest versions of COPS to our Raspberry Pi, let use create a directory to store it on our Raspberry Pi.
You can create this directory by using the mkdir command within the terminal.
sudo mkdir -p /var/www/html/ebooks
5. After creating the directory we must change into it by using the cd command.
6. Now that we are in our new “
ebooks” folder, we can use the following command to clone the COPS repository. We are using a fork by Mike’s Pub as it offers better support for modern versions of PHP and Composer.
Make sure you type in the dot (
.) after the git clone command as this makes it clone to the current directory and not create a new one. If you would like to know more about COPS you can visit their website by going to the COPS GitHub page.
sudo git clone https://github.com/mikespub-org/seblucas-cops.git .
7. We now need to use Composer to install any of the PHP libraries that COPS relies on to work.
Luckily, this is as easy as running the following command within the terminal.
sudo composer install --no-dev -o
You will get a warning about running Composer as a root/super user, type “
yes” to proceed.
Creating a Storage Location for your eBooks
8. Now before we go configuring our Raspberry Pi eBook server, we must first create one more folder. This folder is where you will keep your eBook library itself and its where COPS will read the files from once we configure it.
Let’s create a folder called “
/storage/eBooks/” in your home directory by running the command below.
mkdir -p ~/storage/eBooks
By starting the path with the tilde (
~) symbol, we are referencing the current users home directory.
Configuring the COPS eBook Server for your Raspberry Pi
9. With our folder now created let’s work on setting up the configuration file of COPS.
Our first task is to copy over the example configuration file, so we have something to start with.
sudo cp config_local.php.example config_local.php
10. After copy over the example configuration, we can begin editing the config file by using
sudo nano config_local.php
11. Within this file make the following changes.
a. The first option we must configure is the location of your eBooks
First look for the following line within the config file.
$config['calibre_directory'] = './';
Once you find the above line, change it so that it looks a bit like what we have shown here.
Ensure that you replace “
<USERNAME>” with your own username.
$config['calibre_directory'] = '/home/<USERNAME>/storage/eBooks/';
b. The next thing you will want to do is give your new Raspberry Pi eBook server a beter name. At the moment it is set to “COPS”.
Within this file, look for the following line.
$config['cops_title_default'] = "COPS";
Once you have found the above line, replace “COPS” with the title you want assigned to your server.
$config['cops_title_default'] = "My Raspberry Pi eBook Server";
12. Once you have made the changes, save the file by pressing CTRL + X then Y and lastly press ENTER.
Copying your library from Calibre to COPS
1. In this segment of the tutorial, we will be explaining what you must do to be able to get your Calibre library to show up through COPS.
Begin by opening Calibre on your computer, once it has opened up right click on any book (1.) and click “Open containing folder” (2.).
2. This process should open the file explorer in the location of where that book is, in the address bar you should see “Calibre Library” click it to skip to that directory.
3. Now you have found the location of all your Calibre Library files, copy these files and folders to your /home/<USERNAME>/storage/eBooks/ folder.
COPS will automatically find all these files and be displayed on the web interface. If you are unsure of how to get these files to your Raspberry Pi continue with this tutorial.
4. Now to get all of our Calibre files and folders to our Raspberry Pi, we will be making use of the piece of software called MobaXterm. It is a great piece of software that offers support for a wide variety of protocols, one of these being SFTP.
You can grab MobaXterm for free from the MobaXterm’s official website. Begin by downloading, installing and then running MobaXterm.
5. Open running MobaXterm you should be greeted with the following screen. Begin by clicking the button in the top right-hand corner labeled “Session“.
6. On this next screen, first, click the SFTP tab (1.).
Then type in both your Raspberry Pi’s local IP Address and type in your Pi users username, pi is the username of the default user (2.)
Finally, press the “Ok” button to initiate the connection (3.).
7. On this next screen click on the address bar as shown below, and type in
/home/<USERNAME>/storage/eBooks/ and then press ENTER.
This process will allow us to jump directly to the folder we need.
8. Finally, we can copy the files from your computer to the Raspberry Pi by dragging them from the folder onto the MobaXterm SFTP window like that we have shown below.
It will immediately begin the transfer process, and when it’s complete, you can continue to our last step.
Checking out COPS
1. To check out the Pi’s eBook server, you will need to browse to your Raspberry Pi’s IP address with
/ebooks at the end of it.
To grab your Raspberry Pi’s local IP address, you can type the following hostname command into the terminal.
2. Once you have your Raspberry Pi’s local IP address, then go to it in your favorite web browser with
/ebooks tagged at the end of it.
You can also use this URL with various eBook readers so you can access all the data through there interface.
The URL you visit should look something like below, of course replacing
192.168.0.143 with your own IP Address.
You should be greeted with a web page like below when you browse to the URL.
We hope by the time you have gotten to this point you have successfully set up your very own Raspberry Pi eBook server and have learned how to copy your Calibre library over to it using SFTP.
If you have enjoyed this tutorial or have any feedback feel free to drop a comment below.