$ sudo apt-get -y samba nginx php5-fpm php5-gd php5-sqlite php5-json php5-intl git
Samba is needed for sharing the Calibre library directory with the library administrator. Alternatively you could use NFS or even OwnCloud.
Note
It is a security risk to expose Samba on a public server. Restrict it through firewall or use OwnCloud instead.
# unix password sync = yes
unix password sync = no
# pam password change = yes
pam password change = no
[calibre$]
path = /srv/calibre
valid users = calibre
write list = calibre
read only = no
$ sudo service smbd restart ; sudo service nmbd restart
$ useradd -m -d /srv/calibre -s /usr/sbin/nologin calibre
$ smbpasswd -a calibre
$ sudo apt-get -y install calibre
Windows users can download it from here:
http://calibre-ebook.com/download_windows
Configure Calibre to use the calibre share as its catalog:
$ mkdir /var/www
$ cd /var/www
$ git clone https://github.com/seblucas/cops.git
Under the /var/www/cops/ directory, copy the config_default.php.example to config_default.php:
$ cp config_local.php.example config_local.php
Make the following changes in config_default.php:
< ?php
if (!isset($config))
$config = array();
/*
* The directory containing calibre's metadata.db file, with sub-directories
* containing all the formats.
* BEWARE : it has to end with a /
*/
$config['calibre_directory'] = '/srv/calibre/ebooks/';
/*
* Catalog's title
*/
$config['cops_title_default'] = 'My Ebook Portal';
$config['calibre_internal_directory'] = '/ebooks/';
$config['cops_full_url'] = 'cops.example.com';
$config['cops_x_accel_redirect'] = 'X-Accel-Redirect';
/*
* use URL rewriting for downloading of ebook in HTML catalog
* See README for more information
* 1 : enable
* 0 : disable
*/
$config['cops_use_url_rewriting'] = '1';
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name cops.example.com;
access_log /var/log/nginx/cops.access.log;
error_log /var/log/nginx/cops.error.log;
root /var/www/cops;
#index feed.php;
index index.php;
#Useful only for Kobo reader
location /download/ {
rewrite ^/download/(\d+)/(\d+)/.*\.(.*)$ /fetch.php?data=$1&db=$2&type=$3 last;
rewrite ^/download/(\d+)/.*\.(.*)$ /fetch.php?data=$1&type=$2 last;
break;
}
#Can break loading the images - if you don't see anything, comment
location ~ ^/images.*\.(gif|png|ico|jpg)$ {
expires 31d;
}
#Can also break loading the images, comment if it happens
location ~ .(js|css|eot|svg|woff|ttf)$ {
expires 31d;
}
#Not necessarily correct, it depends on distro.
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php5-fpm.sock;
}
location /ebooks {
root /srv/calibre;
internal;
}
}
Note:
The feed.php setting was redirecting me to an XML site with this error: This XML file does not appear to have any style information associated with it. The document tree is shown below. So I am using index.php instead, as the index file.
$ cd /etc/nginx/sites-enabled/
$ sudo ln -s /etc/nginx/sites-available/cops.example.com
$ sudo unlink default
$ sudo service php5-fpm restart ; sudo service nginx restart
$ usermod -a -G calibre www-data
$ chmod -R g+w /srv/calibre/ebooks/
Now you can navigate to http://cops.example.com and enjoy your newly created ebook library!