PDFTk works on local, but doesn't work on private server

I have a private CentOS 6 server and have installed a program pdftk

to create PDF files. When I connect to the SSH client, I can successfully launch the pdftk program. But I couldn't be in php

with the function exec()

.

I have a very simple php file as shown below. This is just to test whether pdftk is working or not. When I ran this file on my localhost using xampp it generates a file, but when I tried on my personal server it didn’t give an error or generate a file. I am not an expert and do not expect any help from you. Thanks in advance.

PHP CODE:

<?php
exec("pdftk form.pdf output private.pdf");

      

The error looks like this:

Array ( [0] => Error: Failed to open output file:
  [1] => collated.pdf [2] => No output created.) 

      

Note. I tried this code for putty ssh client and it works fine.

+3


source to share


1 answer


Error: Array ([0] => Error: Could not open output file: [1] => collated.pdf [2] => No output generated ... same exec code on spacker works fine.

The difference you might find is with the user executing the code. In the case of PuTTY, you are logged in as the user who is using your script when accessing the web. Since you are creating a new file, the user needs write access to the directory where you are. It is generally a bad idea to write this user to the directory where your scripts are - it's a good idea to create a new directory (for example export

) where the apache user will have write access:

mkdir export
chown apache:apache export
chmod 755 export

      



and change your script to write the file to that directory:

exec("pdftk form.pdf output export/private.pdf");

      

+1


source







All Articles