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) PHP 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 a Raspberry Pi project book 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.
Raspberry Pi 2 or 3
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 php7.3-gd php7.3-sqlite3 php7.3-json php7.3-intl php7.3-xml php7.3-mbstring php7.3-zip
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 /etc/init.d/nginx reload
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 . 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/composer.phar sudo php composer.phar global require "fxp/composer-asset-plugin:~1.1" sudo php composer.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.
$config['calibre_directory'] = './';
$config['calibre_directory'] = '/home/pi/storage/eBooks/';
$config['cops_title_default'] = "COPS";
$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” clickit 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 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.