seblucas / cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
1.43k stars 229 forks source link

Can't get COPS for Calibre working on Ubuntu 16.04 with PHP 7.1 #382

Closed Irv007 closed 6 years ago

Irv007 commented 6 years ago

Hello,

On my Unbuntu 16.04, I installed calibre, nginx, PHP and COPS to use calibre with COPS.

If I call http://mydomain.eu:55555, i would like to get my calibre-infos.

But I get errors:

I have tried to install several versions of PHP. Maybe there is a mess.

At the moment, i would prefer to get the whole thing running with PHP version 7.1.

  1. How can I fix the errors?
  1. why is the system ist asking for php5, when the PHP-Version is 7.1.12? is this normal? is this "correct"?

with best regards, Irv

my system

my files (~/disk1/Calbib1)

ubuntu@ip-172-31-19-142:~/disk1/Calbib1$ ls -ld meta* -rwxrwxr-- 1 ubuntu ubuntu 64000000 Jan 1 18:43 metadata.db -rwxrwxr-- 1 ubuntu ubuntu 12948 Dec 31 09:18 metadata_db_prefs_backup.json

ubuntu@ip-172-31-19-142:~/disk1/Calbib1$ ls -ld Westall//* -rwxrwx--- 1 ubuntu ubuntu 557019 Dec 27 13:43 Westall, Robert/Funf Faden tief (5754)/cover.jpg -rwxrwx--- 1 ubuntu ubuntu 801446 Dec 27 13:43 Westall, Robert/Funf Faden tief (5754)/Funf Faden tief - Westall, Robert.epub -rwxrwx--- 1 ubuntu ubuntu 5414 Dec 27 13:43 Westall, Robert/Funf Faden tief (5754)/metadata.opf

ubuntu@ip-172-31-19-142:/etc/nginx/sites-available$ ls -ld * -rw-r--r-- 1 root root 587 Jan 4 06:01 cops -rw-r--r-- 1 root root 2080 Jan 4 05:47 default

ubuntu@ip-172-31-19-142:/etc/nginx/sites-enabled$ ls -ld * lrwxrwxrwx 1 root root 31 Jan 4 05:58 cops -> /etc/nginx/sites-available/cops

my nginx-file with name cops in /etc/nginx/sites-available

server {
        listen 55555;
        server_name <myip>:55555;
        root /var/www/cops;
        index index.php;

        fastcgi_pass_header Authorization;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~ /\.ht {
                deny all;
        }

        location /Calbib1 {
              root /home/ubuntu/disk1;
               internal;
        }
}

my config_local.php in /var/www/cops

<?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'] = '/home/ubuntu/disk1/Calbib1/';

   /*
     * The URL to the calibre internal directory you specified in your nginx site
     * config file.
     */
    $config['calibre_internal_directory'] = '/Calbib1/';

    /*
     * Catalog's title
     */
    $config['cops_title_default'] = "COPS";

    /*
     * use URL rewriting for downloading of ebook in HTML catalog
     * See README for more information
     *  1 : enable
     *  0 : disable
     */
    $config['cops_use_url_rewriting'] = "0";

     /*
     * Wich header to use when downloading books outside the web directory
     * Possible values are :
     *   X-Accel-Redirect   : For Nginx
     *   X-Sendfile         : For Lightttpd or Apache (with mod_xsendfile)
     *   No value (default) : Let PHP handle the download
     */
    $config['cops_x_accel_redirect'] = "X-Accel-Redirect";

    /*
     * URL to access the COPS page
     */
    $config['cops_full_url'] = '<mydomain>.eu:55555';

    /*
     * Default timezone
     * Check following link for other timezones :
     * http://www.php.net/manual/en/timezones.php
     */
    $config['default_timezone'] = "America/Denver";

    $config['cops_basic_authentication'] = array('username' => 'xxx', 'password' => 'xxx');
ubuntu@ip-172-31-19-142:~$

status nginx.service

ubuntu@ip-172-31-19-142:/etc/systemd/system/nginx.service.d$ sudo systemctl status nginx.service
? nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/nginx.service.d
           +-override.conf
   Active: active (running) since Thu 2018-01-04 07:30:42 CET; 3min 34s ago
  Process: 1324 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
  Process: 1318 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 1296 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 1323 (nginx)
    Tasks: 2
   Memory: 7.3M
      CPU: 22ms
   CGroup: /system.slice/nginx.service
           +-1323 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           +-1326 nginx: worker process

Jan 04 07:30:41 ip-172-31-19-142 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 04 07:30:42 ip-172-31-19-142 systemd[1]: Started A high performance web server and a reverse proxy server.
ubuntu@ip-172-31-19-142:/etc/systemd/system/nginx.service.d$

status PHP

ubuntu@ip-172-31-19-142:/etc/systemd/system/nginx.service.d$ sudo systemctl status php7.1-fpm.service
? php7.1-fpm.service - The PHP 7.1 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.1-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-01-04 07:30:42 CET; 3min 11s ago
     Docs: man:php-fpm7.1(8)
 Main PID: 1298 (php-fpm7.1)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3
   Memory: 37.9M
      CPU: 45ms
   CGroup: /system.slice/php7.1-fpm.service
           +-1298 php-fpm: master process (/etc/php/7.1/fpm/php-fpm.conf)
           +-1330 php-fpm: pool www
           +-1331 php-fpm: pool www

Jan 04 07:30:41 ip-172-31-19-142 systemd[1]: Starting The PHP 7.1 FastCGI Process Manager...
Jan 04 07:30:42 ip-172-31-19-142 systemd[1]: Started The PHP 7.1 FastCGI Process Manager.
ubuntu@ip-172-31-19-142:/etc/systemd/system/nginx.service.d$

netstat

ubuntu@ip-172-31-19-142:~$ sudo netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      1291/calibre-server
tcp        0      0 127.0.0.1:3350          0.0.0.0:*               LISTEN      1460/xrdp-sesman
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1337/sshd
tcp        0      0 0.0.0.0:3389            0.0.0.0:*               LISTEN      1452/xrdp
tcp        0      0 0.0.0.0:55555           0.0.0.0:*               LISTEN      1323/nginx -g daemo
tcp6       0      0 :::80                   :::*                    LISTEN      1488/apache2
tcp6       0      0 :::22                   :::*                    LISTEN      1337/sshd
ubuntu@ip-172-31-19-142:~$

/var/log/nginx/error.log

  thrown in /var/www/cops/base.php on line 1257" while reading response header from upstream, client: 5.159.0.139, server: myip:55555, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php5.6-fpm.sock:", host: "mydomain.eu:55555"
2018/01/04 12:12:42 [error] 7097#7097: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Exception: Database <> not found. in /var/www/cops/base.php:1257
Stack trace:
#0 /var/www/cops/base.php(1272): Base::error(NULL)
#1 /var/www/cops/base.php(1285): Base::getDb()
#2 /var/www/cops/index.php(37): Base::checkDatabaseAvailability()
#3 {main}
  thrown in /var/www/cops/base.php on line 1257" while reading response header from upstream, client: 5.159.0.139, server: myip:55555, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "mydomain.eu:55555"
2018/01/04 12:12:42 [error] 7097#7097: *1 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: cops_server_side_render in /var/www/cops/base.php on line 18" while reading response header from upstream, client: 5.159.0.139, server: myip:55555, request: "GET /checkconfig.php?err=1 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "mydomain.eu:55555"
2018/01/04 12:12:43 [error] 7097#7097: *3 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: cops_server_side_render in /var/www/cops/base.php on line 18" while reading response header from upstream, client: 5.159.0.139, server: myip:55555, request: "GET /checkconfig.php?err=1 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "mydomain.eu:55555"
2018/01/04 12:23:15 [error] 7420#7420: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Exception: Database <> not found. in /var/www/cops/lib/Base.php:109
Stack trace:
#0 /var/www/cops/lib/Base.php(124): Base::error(NULL)
#1 /var/www/cops/lib/Base.php(137): Base::getDb()
#2 /var/www/cops/index.php(28): Base::checkDatabaseAvailability()
#3 {main}
  thrown in /var/www/cops/lib/Base.php on line 109" while reading response header from upstream, client: 5.159.0.139, server: myip:55555, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "mydomain.eu:55555"
2018/01/04 12:38:11 [error] 7420#7420: *12 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Exception: Database <> not found. in /var/www/cops/lib/Base.php:109
Stack trace:
#0 /var/www/cops/lib/Base.php(124): Base::error(NULL)
#1 /var/www/cops/lib/Base.php(137): Base::getDb()
#2 /var/www/cops/index.php(28): Base::checkDatabaseAvailability()
#3 {main}
  thrown in /var/www/cops/lib/Base.php on line 109" while reading response header from upstream, client: 5.159.0.139, server: myip:55555, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "mydomain.eu:55555"
ubuntu@ip-172-31-19-142:~$

Screenshot of Error messages:

screenshot

marioscube commented 6 years ago

You should start with installing the relevant extensions for your system/PHP-version.

So try to install php7.1-GD, php7.1-sqlite, php7.1-intl

apt-get install php7.1-GD php7.1-sqlite php7.1-intl

Then restart php (or just reboot) ant try cops again.

Irv007 commented 6 years ago

Damn. This solved the Problem with all that PHP-stuff. Thank you.

Irv007 commented 6 years ago

Now, I have to check, why the following message appears:

Check if Calibre database file exists and is readable File /home/ubuntu/disk1/Calbib1/metadata.db not found, Please check

Irv007 commented 6 years ago

The file is there, everybody can read it. I don't know yet, why COPS can't read it:

ubuntu@ip-172-31-19-142:~$ ls -lrt /home/ubuntu/disk1/Calbib1/metadata.db
-rwxrwxr-- 1 ubuntu ubuntu 64000000 Jan  1 18:43 /home/ubuntu/disk1/Calbib1/metadata.db
marioscube commented 6 years ago

1 - I use apache, so if it's a NGINX "problem" (don't expect it to) I will have trouble to help.

2 - in my config_local.php file the lines:

 /*
   * URL to access the COPS page
   */
   $config['cops_full_url'] = '<mydomain>.eu:55555';

are more like:

 /*
   * URL to access the COPS page
   */
   $config['cops_full_url'] = 'http://<LAN-IP>';

I assume you are behind a router that can convert your WAN address to a LAN-address. Perhaps first try it without the address:55555. Your router can do the conversion from port:55555 to port:80.

Also, if you are in Germany(? books in German and .eu address) why use a USA time zone? I'm told it sometimes can cause a problem.

3- if this does not help then just for the sake of testing put your calibre database inside the cops directory structure and give 777 atrributes to the directory where the ebooks are in. then in config_local.php: $config['calibre_directory'] = './Calbib1/';

seblucas commented 6 years ago

Storing your Calibre directory inside /home will be more difficult. Try to move you Calibre directory to /var/www/Calbib1 and update it's group / access rights :

chown -R :www-data /var/www/Calbib1
chown g+r /var/www/Calbib1

Assuming Ubuntu use www-data like Debian, never used Ubuntu in my life.

marioscube commented 6 years ago

@seblucas

In my opinion Ubuntu is just like Debian with a newer kernel and packages, more eye candy for the desktop and some newly introduced bugs. ;-)

seblucas commented 6 years ago

Sorry for the off topic

@marioscube

Now with Stretch, packages are more or less the same ..... but I agree that won't last long ;)

Irv007 commented 6 years ago

I moved the directory with the E-Books and the metadata-files (Calbib1) into /var/www/cops.

Now it works.

Thank you!

Irv007 commented 6 years ago

It work's: (1) install PHP correctly and (2) move E-Books-directory to the /var/www/cops-directory.

seblucas commented 6 years ago

I'm not sure to fully understand you, I proposed to move your calibre directory besides your cops installation directory (/var/www/cops / /var/www/Calbib1) not inside (/var/www/cops / /var/www/cops/Calbib1)

As stated here, if you put your Calibre database inside the cops directory then it's not safe anymore.

Of course if your COPS installation is only available on LAN with trusted computers then you can forget my comment ;).

Irv007 commented 6 years ago

Thank your for this good hint. At the moment, it just a test, to get the whole thing running. Now, as it is running, next step is, to do all the things the right way.

Thank you!

Irv007 commented 6 years ago
  1. My Calbib1 is on a different, much bigger disk than the disk with /var/www.
  2. Now, I made a mountpoint at /var/www, mounted the disk with Calbib1 and adjusted the path in the config-file.
  3. Now, everything works, as I wanted.