Calling PHP from PERL CGI


#1

I’m trying to call a PHP script from a PERL CGI script, but the PHP interpreter behaves weirdly… actually even a simple call to the interpreter gives strange results :

#!/usr/bin/perl

print “Content-type: text/html\n\n”;
system("/usr/local/bin/php -v");

If you call this from shell, it works, but if you call it as a CGI through http, it displays the content of the perl script instead of the normal output of the /usr/local/bin/php -v

What am I doing wrong here ?


#2

What is the extension of the Perl script, and did you make it executable?

:cool: Perl / MySQL / HTML+CSS


#3

.pl of course, and yes it is executable (otherwise I wouldn’t be able to execute it under ssh either). Actually the Perl script is executing itself fine also in CGI mode, it’s the call to /usr/local/bin/php which has super weird effects :frowning:


#4

[quote]pl of course, and yes it is executable (otherwise I wouldn’t be able to execute it under ssh either). [/quote

That depends on whether your command is ‘perl filename.pl’ or simply ‘./filename.pl’; in the first case, perl is reading the script file as a data file, and execute permission is not necessary. In the latter, the OS ‘executes’ the file by looking for the magic number and passing the file path to the command following it.

Actually not weird at all. You forget that you are still executing PHP in a CGI environment, so it think it is supposed to generate a web page parsing something. The CGI environment will say the SCRIPT_FILENAME or some other variable will be ‘perl-script-filename’ and thus PHP will read that file and parse it.

:cool: Perl / MySQL / HTML+CSS


#5

mhhhh ok, but concretly how do I solve the problem ???


#6

As it was said earlier, you’ll have to set the domain to run PHP using the Apache mod.
Just go to Domains -> Web, Edit and UNCHECK Run PHP as CGI.

Either that or use redircts instead of rewrites.

:cool: Perl / MySQL / HTML+CSS