Take the 2-minute tour ×

I am trying to convert a pdf file into text file. When I run the command through terminal its working fine but when try to execute it through PHP it's not working.

I am stuck in this situation from last four hour spend lots of time in google but no solution available. Can any body resolve this issue?

File owner - nobody

shell_exec('/usr/bin/pdftotext /opt/lampp/htdocs/foldername/filename.pdf');

Can anyone provide any helpful solution?

I also tried to change usr folder ownership from root to nobody and provide 777 permission on folder and its context.

share|improve this question
when you do shell_exec from PHP file you're under apache user, maybe apache has no permission in /usr/bin/pdftotext? –  Alexandru Calin Jan 25 '13 at 12:37
if you run it through exec and view the $output, what do you get? Should look something like: exec('/usr/bin/pdftotext /opt/lampp/htdocs/foldername/filename.pdf',$output = array()); var_dump($output); –  Prisoner Jan 25 '13 at 12:37
NULL returns after execution –  Ajay Kadyan Jan 25 '13 at 12:42
Maybe is permission denied. –  Kai Jan 25 '13 at 12:43
you could chown apache /usr/bin/pdftotext/ But before this, stop apache, server httpd stop then 'su apache` and check the command –  Alexandru Calin Jan 25 '13 at 12:44
show 19 more comments

5 Answers

up vote 3 down vote accepted

Your command to run pdftotext is not correct.

There should be a second argument telling pdftotext to write to a specific file or just use a dash "-" to write to stdout, unless you actually want the program to create a text-file with the filename as the pdf (this would require write permissions in the /opt/lampp/.../ folder)

This is at least true for pdftotext version 0.12.4

"Pdftotext reads the PDF file, PDF-file, and writes a text file, text-file. If text-file is not specified, pdftotext converts file.pdf to file.txt. If text-file is ´-', the text is sent to stdout."

So, the solution to your question would simply be add a dash after the filename, like so:

$pdftext = shell_exec('/usr/bin/pdftotext /opt/lampp/htdocs/foldername/filename.pdf -');
echo $pdftext;

Provided that the binary exists and PHP is allowed to use shell_exec and you have permissions and that the pdf-file exists and you have permissions.

share|improve this answer
add comment

from how to test if PHP system() function is allowed? and not turned off for security reasons

function isAvailable($func) {
    if (ini_get('safe_mode')) return false;
    $disabled = ini_get('disable_functions');
    if ($disabled) {
        $disabled = explode(',', $disabled);
        $disabled = array_map('trim', $disabled);
        return !in_array($func, $disabled);
    return true;

You may need to check if isAvailable('shell_exec') On shared hosting this function might be disabled.

If it's not disabled, check the Apache log, it's all you can do.

share|improve this answer
he has access to terminal, i don't think it's shared hosting –  Alexandru Calin Jan 25 '13 at 12:43
For my Dreamhost account I also have console access. And, it's not a shared hosting. It depends... however, even if it's a private server, he needs to check "what can php do?". The terminal functionality is not relevant. –  vectorialpx Jan 25 '13 at 12:46
add comment

try exec and also make sure safe mode off in your php.ini file like this safe_mode = Off


also run this cmd in terminal to check if software is working

share|improve this answer
add comment

This is usually a function disabled by many webserver, you can check:

var_dump(ini_get('disable_functions')); // not available if shell_exec disabled
var_dump(ini_get('safe_mode')); // not available if true
share|improve this answer
add comment

Since You are running Linux you may have a rights Problem

  1. Check your file is owned by apache.

    chown apache apache file.php

  2. Check youir file has rights

    chmod 644 file.php

  3. Maybe check your sudoers file aswell
    Sudoers ManPage

share|improve this answer
add comment

Your Answer


