3

I am attempting to run pdftk as user www-data with the following command (as root):

sudo -u www-data /snap/bin/pdftk

But I am getting this error:

cannot create user data directory: /var/www/snap/pdftk/9: Read-only file system

(Ubuntu 18.04, PDFTK installed with SNAP).

The /var/www/snap/pdftk and /var/www/snap/pdftk/9 directories have rw permissions for the www-data user:

drwxr-xr-x 3 www-data www-data 4096 Jan 23 15:44 ./
drwxrwxrwx 4 root     root     4096 Jan 23 15:44 ../
drwxrwxr-x 4 www-data www-data 4096 Jan 23 15:44 pdftk/

drwxrwxr-x 4 www-data www-data 4096 Jan 23 15:44 ./
drwxr-xr-x 3 www-data www-data 4096 Jan 23 15:44 ../
drwxrwxr-x 2 www-data www-data 4096 Jan 23 15:44 9/
drwxr-xr-x 2 www-data www-data 4096 Jan 23 15:44 common/
lrwxrwxrwx 1 www-data www-data    1 Jan 23 15:44 current -> 9/

I need to be able to run PDFTK as www-data user because I want to call PDFTK from a PHP script served by apache2, as in:

<?php
`/snap/bin/pdftk file1.pdf file2.pdf cat output file3.pdf`;

NOTE: the pdftk wrapper for PHP, mikehaertl/php-pdftk, doesn't seem to want to save files either. I tried the ->saveAs() function but no file is generated, even when attempting to write to /tmp, which should have full write permissions. No errors in apache2 error log, so I'm betting it's the same issue.

Ryan Griggs
  • 2,457
  • 2
  • 35
  • 58

1 Answers1

0

I encountered exactly the same problem! In particular, I didn't face this problem when using pdftk in Ubuntu 18.10 with pdftk already included back, but faced this problem on a server with Ubuntu 18.04.

My workaround is NOT to install pdftk via snap. I installed pdftk with debian packages, following the instruction at https://www.webdesign101.net/install-pdftk-on-ubuntu-18-04-bionic/.

Everything then just works fine.

Vee Hua Zhi
  • 109
  • 3
  • This is outdated and apparently does not work anymore. That link now also suggests to install pdftk using snap, which also not works for me. As it currently stands, there is no solution to this problem. – Gerrit Addiks May 25 '22 at 12:45