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.
Equipment List
Below are all the bits and pieces that I used for this Raspberry Pi eBook Server tutorial.
Recommended
- Raspberry Pi 2 or Newer
- Micro SD Card
- Power Supply
- Ethernet Cable or Wi-Fi
Optional
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.
1. Before we begin, let’s bring all our packages on Raspbian up to date by running the following command in the terminal.
sudo apt-get update
sudo apt-get 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 php7.4-gd php7.4-cli php7.4-sqlite3 php7.4-json php7.4-intl php7.4-xml php7.4-mbstring php7.4-zip
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
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.
Let’s clone the software from its Github page to our Raspberry Pi by running the following commands. The first command makes a folder in your www folder to store the eBook library.
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 mkdir -p /var/www/html/ebooks
cd /var/www/html/ebooks
sudo git clone https://github.com/seblucas/cops.git .
5. Now that we have cloned the COPS software into our eBooks directory we will need to make use of composer to grab all its dependencies and set up the software for use.
To do this, we will be running the following commands on our Raspberry Pi.
sudo wget https://getcomposer.org/download/1.9.0/composer.phar
sudo php composer-stable.phar global require "fxp/composer-asset-plugin:~1.1"
sudo php composer-stable.phar install --no-dev --optimize-autoloader
6. 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 the folder by running the following command on our Raspberry Pi.
mkdir -p /home/pi/storage/eBooks
7. With our folder now created let’s work on setting up the configuration file of COPS. We will do this by copying the example file and immediately start to edit it by running a command for nano.
Type the following two commands in terminal to begin editing the file
sudo cp config_local.php.example config_local.php
sudo nano config_local.php
8. Within this file make the following changes.
Find
$config['calibre_directory'] = './';
Replace With
$config['calibre_directory'] = '/home/pi/storage/eBooks/';
Find
$config['cops_title_default'] = "COPS";
Replace With
$config['cops_title_default'] = "My Raspberry Pi eBook Server";
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.
While in this tutorial we will be utilizing SFTP through Mobaxterm you can use multiple other methods of getting your eBooks to your Raspberry Pi. Such as using FTP, or a SAMBA share.
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/pi/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/pi/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.
hostname -I
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.
http://192.168.0.143/ebooks
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.
Just FYI, to get it to work I used the following commands instead of the ones listed on step 5 of “Setting up your eBook Server with COPS”
After installing the php packages from step 2, I attempted to run the “sudo /etc/init.d/nginx reload” from step 3 and received the following error “sudo: /etc/init.d/nginx: command not found” — After checking, I see nginx hasn’t installed to that directory. Any idea why nginx hasn’t installed to there and where it may have installed to?
Hi Eddie,
Just verifying, did you follow our installing NGINX On a Raspberry Pi guide before following this tutorial?
If you have, can you please try using the following command instead. This uses the more modern systemctl to reload the service rather than the old “
init.d
” file call.Cheers,
Emmet
When I run:
sudo php composer.phar global require “fxp/composer-asset-plugin:~1.1”
I get:
[InvalidArgumentException]
Package fxp/composer-asset-plugin at version ~1.1 has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version
Any help would be appreciated!
Thanks!
Hi Thomas,
I have now fixed up the issue that was occuring here.
Within the tutorial we were downloading the latest non stable release of Composer that the required packages did not support.
We have updated the tutorial to download the latest stable release.
Let me know if that fixes the issue for you.
Cheers,
Emmet
I ran the php script…
sudo apt-get install php7.3-gd php7.3-sqlite3 php7.3-json php7.3-intl php7.3-xml php7.3-mbstring php7.3-zip
Server down???
Reading state information… Done
E: Unable to locate package php7.3-gd
E: Couldn’t find any package by glob ‘php7.3-gd’
E: Couldn’t find any package by regex ‘php7.3-gd’
[SNIPPED]
Hi Schuyler,
Are you running Raspbian Buster? These packages should be available on Raspbian Buster and later.
If you are then try running
sudo apt update
again.Cheers,
Emmet
That may have been the issue. I upgraded to Buster and I’ll let you know how it goes.
Thanks!
I am receiving the following error
MESSAGE pi@raspberrypi:/var/www/html/ebooks $ sudo php composer.phar install –no-dev –optimize-autoloader
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Composer could not find a composer.json file in /var/www/html/ebooks
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ “Getting Started” section
When I run sudo php composer.phar install –no-dev –optimize-autoloader from step 5
Please let me know what I am missing, Thanks
Hey Kevin,
Make sure that you are running the command in the correct directory and that you actually cloned the repository into /ebook/ folder and not /ebook/cops/ folder.
Cheers
Make sure when you do the git clone, you include the “.” at the end. Otherwise, you will be copying everything into another subdirectory called “cops,” and as mentioned below, that will cause this scenario.
I keep getting configuration errors telling me to check if all the packages are installed which they are. Mainly database error. I’m just wandering if it’s because the books are in a SAMBA directory on the pi and the permissions are incorrect?
Hey Brendan,
Seeing the actual errors would help us work out what the actual problem is.
Cheers