Synology DSM - How to install extensions in php.ini (PDFlib)

Questions about HTTP Access/Mods may go here
Forum rules
Please note the disclaimer before modifying your Synology Product.
reconx86
I'm New!
I'm New!
Posts: 5
Joined: Fri Feb 07, 2014 2:59 pm

Synology DSM - How to install extensions in php.ini (PDFlib)

Postby reconx86 » Thu Jul 17, 2014 12:51 am

I summarize my experience and research-methods for adding (PDFlib) extension thru Putty to my php configuration. It may save you time if you want to do something alike.

1. Locate your php.ini file
The following command is handy when you are clueless about where to find a specific file in your DSM without wasting time going thru the tons of personal files, this is how I found php.ini:

Code: Select all

find / -path "/volume*" -prune -o -iname "php.ini" -print


Result on DSM 5.0: /etc/php/php.ini

Code: Select all

vi /etc/php/php.ini


2. Open php.ini
Type vi command:

Code: Select all

/extension


Result on DSM 5.0: extension_dir = /usr/lib/php/modules
this is the module directory which is where we will place our php_pdflib.so

press n, a couple of times until you see a range of "extension =" lines. press i, to insert extenstion = php_pdflib.so after these hit ESC and :wq to save your entry

Code: Select all

cd /usr/lib/php/modules #path derived from previous result


3. Determine what processor you have
uname -m
Result on my DSM: i686 (which is a 32 bit intel proccessor), if nothing appears use uname -a

4. Download pdflib
surf to http://www.pdflib.com/download/pdflib-family/pdflib-9/
Based on the result of uname -m, i right-clicked: "Linux/FreeBSD" > "Linux x86" > "PHP" and selected "Copy Link Location" in google chrome

Which I copied back to PuTTy, preceded with the command wget:

Code: Select all

#Download tarball
wget http://www.pdflib.com/binaries/PDFlib/903/PDFlib-9.0.3-Linux-php.tar.gz

#Extract tarball
tar -zxvf PDFlib-9.0.3-Linux-php.tar.gz

#Get PHP version (result for me PHP 5.5.13):
/usr/bin/php -v

#list all sub-folders if your version is not the same, mt suffix means "multi-threaded"
ls PDFlib-9.0.3-Linux-php/bind/php/

#copy extension to the extension directory
cp PDFlib-9.0.3-Linux-php/bind/php/php-550/php_pdflib.so php_pdflib.so

#Apache restart for DSM 5.0
/usr/syno/sbin/synoservicecfg -restart httpd-user

#check if lib is correctly installed
php -i | grep "PDFlib GmbH"


If succesfull remove tarballs and extracted directory:

Code: Select all

rm PDFlib-9.0.3-Linux-php.tar.gz
rm -r PDFlib-9.0.3-Linux-php


======================================
You may stumble upon errors, like:

Code: Select all

PHP Warning:  PHP Startup: PDFlib: Unable to initialize module
Module compiled with build ID=API20121212,[b]TS[/b]
PHP    compiled with build ID=API20121212,[b]NTS[/b]
These options need to match
 in Unknown on line 0

TS basically means the module is Thread Safe (Multi Threaded) and your PHP binary is NTS (Single threaded)

Code: Select all

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/          php_pdflib.so' - /usr/lib/php/modules/php_pdflib.so: wrong ELF class: ELFCLASS64           in Unknown on line 0

wrong ELF class: ELFCLASS64: Means you are running the module on the wrong processor (ISA) (in this case a 64-bit module on a 32 bit processor)

Remove the php_pdflib.so file, if errors like these occur and replace with the proper extension.

Code: Select all

rm php_pdflib.so
Last edited by reconx86 on Fri Jul 18, 2014 3:04 pm, edited 7 times in total.
reconx86
I'm New!
I'm New!
Posts: 5
Joined: Fri Feb 07, 2014 2:59 pm

Re: Synology DSM - How to install extensions in php.ini (PDF

Postby reconx86 » Fri Jul 18, 2014 2:39 pm

Quick PDF test script

Code: Select all

<?php
//Creating a basic PDF (A4) document with PHP
try {

   // create new instance of the ‘PDFlib’ class
   $pdf=new PDFlib();

   // open new PDF file
   if(!$pdf->begin_document("", "")){
      throw new PDFlibException("Error creating PDF document. ".$pdf->get_errmsg());
   }

   $pdf->set_info("Creator","pdf_example.php");
   $pdf->set_info("Author", "John Doe");
   $pdf->set_info("Title", "My PDF title");
   
   $pdf->begin_page_ext(595,842,"");
   $font=$pdf->load_font("Helvetica-Bold","winansi","");
   
   $pdf->setfont($font,24.0);
   $pdf->set_text_pos(50,800);
   $pdf->show("PHP is great for creating PDF documents!");

   // end page
   $pdf->end_page_ext("");
 
   // end document
   $pdf->end_document("");
 
   // get buffer contents
   $buffer=$pdf->get_buffer();

   // get length of buffer
   $len=strlen($buffer);
   
   // display PDF document
   header("Content-type: application/pdf");
   header("Content-Length: $len");
   header("Content-Disposition: inline; filename=example.pdf");
   echo $buffer;
}
catch (PDFlibException $e) {
   echo "Error Number:".$e->get_errnum()."n";
   echo "Error Message:".$e->get_errmsg();
   exit();
}
?>


If you want to save the PDF document to disc, comment out the $buffer=$pdf->get_buffer(); and set a filename as the first parameter of begin_document() (eg: $pdf->begin_document("/uploads/test.pdf", ""))

Also very important, make sure you set the upload folder to 777, at least for me it didnt seem to work with any less permissions
hsc123
I'm New!
I'm New!
Posts: 1
Joined: Mon Aug 03, 2015 8:14 am

Re: Synology DSM - How to install extensions in php.ini (PDF

Postby hsc123 » Mon Aug 03, 2015 8:26 am

Hi

I followed your Installation - steps, but I have the Problem that the library can't be loaded:

php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/php_pdflib.so' - /usr/lib/php/modules/php_pdflib.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.5.26 (cli) (built: Jun 29 2015 17:43:23)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
DiskStation>

as you see the lib is at the correct place:

pwd
/usr/lib/php/modules
DiskStation> ls -l php*
-rwxr-xr-x 1 root root 7101294 Aug 3 08:58 php_pdflib.so
DiskStation>

can you please help me? What's the Problem?
Regards
Jürgen Bertsche
pik
I'm New!
I'm New!
Posts: 1
Joined: Wed Oct 26, 2016 7:38 am

Re: Synology DSM - How to install extensions in php.ini (PDFlib)

Postby pik » Wed Oct 26, 2016 7:43 am

Hello all. I know it's an old post but I have the same problem as hsc123 and I can not fix it. Does anyone know the solution?

Return to “HTTP/Apache Mods”

Who is online

Users browsing this forum: No registered users and 1 guest