Problems running Exiftool on a web-server

Started by gnomeplanet, April 17, 2015, 05:12:40 AM

Previous topic - Next topic

gnomeplanet

Hi - I am having problems running ExifTool 9.92 on a Debian webserver.

I uploaded the entire contents of the Exiftool distribution to my online cgi-bin, then changed the name of 'exiftool' to 'exiftool.pl'.

I tried running exiftool using a script that works fine on my local computer, but got the error in my online CGI Error Log:

    sh: 1: /PRIVATE_PATH/cgi-bin/exiftool.pl: Permission denied

I then changed the permissions of both 'exiftool.pl' and the 'lib' directory to '777' but I still get the same 'Permission' denied error.

I would like to know:

a/ how to fix this.
b/ a suggestion for a really simple 'hello world' test that people can use to check if exiftool is working on their webserver.

Thanks, Tim.



Phil Harvey

Hi Tim,

There are a number of steps involved with configuring the web server to be able to run cgi-bin scripts.  Do other scripts work?  I suggest actually finding a "hello world" cgi example and get that working first before starting with ExifTool.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gnomeplanet

Hi Phil - thanks for replying to this.

I have another script in my cgi-bin to check it out: test.pl

    #!/usr/bin/perl
    print "content-type: text/html \n\n";
    print "Hello, Perl!";

This works OK. My webserver info page tells me that cgi scripts are enabled. I don't understand that permission is denied, when I have set the permissions on the 'exiftool.pl' script to '777', which I thought was as high as it gets. Obviously, then, permission for my 'test.pl' script is being granted, and for 'exiftool.pl' is being denied. I just can't think why that might be, or how to check just what extra permission is required for 'exiftool.pl' that isn't required for 'test.pl'.

Regards, Tim


Phil Harvey

#3
Check the user and group ownership of the files.  It is possible that there are security features in the web server that checks these.

- Phil

Edit:  Also check your web server error logs for any errors.  (/var/log/apache2/error_log if you are running apache2)
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gnomeplanet

Hi Phil - thanks for your answer. I suspect that what ever is going on is not due to Exiftool, as so many other people are using it without problem: nevertheless, it is probably useful to document this issue here, in the hope that it may help others who run up against similar events. I can't believe this is unique.

So, in answer to your  suggestion, I contacted my hosting company and forwarded your suggestions. They replied:

"We are sorry for the issue that you are going through with Perl script. I was able to replicate your issue with accessing Perl script at: http://www.gnomeplanet.com/cgi-bin/exiftool.pl . I have enabled print in the script and now your Perl script 'exiftool.pl' is throwing some sort of error. This appears to be a scripting issue on your end since the sample Perl script which I've uploaded for the testing purposes, is working fine at: http://www.gnomeplanet.com/cgi-bin/test.pl . It is not server sided issue. Where as, there is no server side issue or permission issue found. Therefore, I suggest that you please debug the script on your end and correct the issue."

Phil - Whilst I am a reasonable programmer in some languages, I am at a loss as to how to proceed with this, so would be grateful if you, or anyone else, can shed further light on this problem.

Regards, Tim

Phil Harvey

Hi Tim,

If he could have told you what the error was it would have been useful.

But one potential pitfall of cgi-bin scripts is that they run in a different environment from the command line.  Maybe it would be worthwhile to change your test script to this:

    #!/usr/bin/perl
    print "content-type: text/html \n\n";
    print "path: @INC";


and check to be sure that the ExifTool libraries are in the include path.

Sorry I can't be more help with this, but I don't have a web server with cgi-bin enabled that I can easily test this on.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gnomeplanet

I tried that, and received the information:

     path: /usr/local/lib/perl5/5.8.8/i686-linux /usr/local/lib/perl5/5.8.8 /usr/local/lib/perl5/site_perl/5.8.8/i686-linux /usr/local/lib/perl5/site_perl/5.8.8 /usr/local/lib/perl5/site_perl /usr/local/lib/perl/5.8.4 /usr/local/lib/site_perl

None of these are the paths to my cgi-bin, where your 'lib' folder is located. I therefore have to make some changes to include your 'lib' directory, but as I am just a 'user' on my web-server, I am not in a position to make any configuration changes to the 'include path'. So, what might my options be? I guess the line that's causing the problem is line 32 in v9.92:

    use Image::ExifTool qw{:Public};

After some newbie-Perl research, it seems that I need to add this line above line 32:

    require "lib/Image/";

Alternatively, this:

    BEGIN {
        push ( @INC,"lib/Image/");
    }

or:

use lib "lib/Image/";

Are one of these what you would recommend?

Phil Harvey

Ah.  I hadn't clued in that you were trying to do this without having Image::ExifTool installed.  I would suggest you do what the exiftool application script does:

BEGIN {
    # get exe directory
    my $exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.';
    # add lib directory at start of include path
    unshift @INC, "$exeDir/lib";
}
use Image::ExifTool qw{:Public};


Then make sure the 'lib' directory is in the same directory as your cgi script.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gnomeplanet

Phil - Sorry, I don't understand what you are saying. If that code is already in 'exiftool.pl', and the 'lib' directory is already in the same directory as 'exiftool.pl', then surely it is already adding the  'lib' directory path to the include path?

If this is not correct, then what extra code is required to get this to work, and where should the extra code go?

Just to recap: In my web server's cgi-bin I have uploaded 'exiftool.pl' and the full 'lib' directory.

From a php page I am calling:

$exif = shell_exec("PRIVATEPATH/cgi-bin/exiftool.pl -j -D -f -g -s $my_image_file");

This command works fine on my local server when using exiftool.exe

Regards, Tim

PS - if anyone else has already done this and got it working, please let us all know how you did it!!

Phil Harvey

Hi Tim,

I'm confused.

From your example script, it appears that you want a script that handles the http protocol (since it returned "content-type: text/html \n\n...").

But exiftool(.pl) doesn't do this, so you can't call it directly from the web server like your test script.  You would have to write a Perl CGI script and add the BEGIN line that I suggested (or install Image::ExifTool properly).

However, now you're telling me that you are calling this from a PHP script, and not from the web server directly?

Then I don't understand why your test script returned the content-type.  Surely your want to run your test script the same way as whatever exiftool script you want to run.

Your PHP snippet shows you want to receive JSON-formatted input.  Does it work when you do this with your test script?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gnomeplanet

Hi Phil - My 'test.pl' script was there purely to show that Perl scripts in my cgi-bin are actually running. It was put there by the web-hosting company, just so their clients can see that all the settings have been adjusted correctly and that Perl scripts will run in this environment. That is the end of its usefulness. We can forget about it now.

As regards exiftool, here's what I am doing:

a/ Local development - desktop windows 7 with xampp server providing php/mysql etc for local development). I use the windows version of exiftool, located at 'c:\windows\exiftool.exe'. The php page, which lives in the 'htdocs' folder of my xampp installation, is accessed by a web-browser on my local computer, pointing to 'http://localhost/PATH_TO/testing_page.php'. That page lets me browse to an image file on my local computer via a form on that page, which is then submitted to exiftool.exe with the line:

$exif = shell_exec("c:\windows\exiftool.exe -j -D -f -g -s $my_image_file");

The resulting output, stored in the php variable '$exif', is then processed. This is all working very well. OK, so I now want everyone to be able to access this page, so we move to my remote server...


b/ Remote development - my web hosting company runs a Debian webserver providing php/mysql/Perl etc. as they do for all their accounts. On their webserver, I have exiftool.pl + the lib directory in my cgi-bin, then in the html part of my section of the webserver, I have all my normal files that are accessed by people looking at my web site, including the 'testing_page.php'. To access this page, I open a web-browser on my local computer and navigate to the hosting server, and the 'http://www.gnomeplanet.com/PATH_TO/testing_page.php'. That page, knowing that it is on the remote server, attempts to call 'exiftool.pl', the file that is in my cgi-bin, rather than 'exiftool.exe'. It uses almost the same line:

$exif = shell_exec("PRIVATEPATH/cgi-bin/exiftool.pl -j -D -f -g -s $my_image_file");

As before, the line uses an image file: '$my_image_file' that the visitor to 'testing_page.php' has uploaded via a form on that page, that uses the <input type="file"> feature.

I hope this has explained exactly what I am trying to do.

Regards, Tim.

Phil Harvey

Hi Tim,

Yes, I think I understand now, but have you tried to run any other (simple) perl script in the same way (remotely).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gnomeplanet

Hi Phil - no, I haven't tried any other Perl scripts apart from the afore-mentioned test script, which works. What kind of scripts did you have in mind?

By the way, I emailed Jeffrey Friedl, who seems to be the ?only? person with an online exiftool installation - he tells me:

"The 'exiftool' program is designed to be run from the command line... I don't think it
can run as a CGI, unless there's some kind of special mode that I don't know about.
I don't use it with my online stuff... I use the underlying Image::ExifTool library directly."

which was very interesting to hear. He's not giving any other clues away as to how he does it, though!

I'm not a Perl programmer at all so have quickly got out of my depth here. Its interesting, though, that the Windows version 'exiftool.exe' works fine in this scenario. Wish I had a windows webserver! As far as I understand, the Windows version of exiftool has all the required libraries already built in to it. I wonder if there is some clue there as to why it works and the other doesn't?

Regards, Tim Makins

Phil Harvey

Hi Tim,

I think we have a communication problem here.  (And I didn't help things because I misunderstood the original problem so some of my suggestions were off the mark.)

You aren't running exiftool as a CGI script, you are trying to run it as an executable from within a PHP script.

You have successfully run a test CGI script on your server, but this is irrelevant.

You have not yet successfully run a Perl executable from a PHP script.  Correct?  This is what I said you should test with a simple Perl script.

Note that the exiftool application script does not handle http protocol as I already mentioned.  So it can't be used as a CGI script directly.  Jeffrey is correct.

- Phil

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).