Is it possible to execute a cgi script from php?

710 Views Asked by At

I am trying to run a LaTeX parser from a dokuwiki website. The LaTeX parser relies on the mimetex cgi module, it is executed from a PhP script using the following command:

shell_exec('/var/www/cgi-bin/mimetex.cgi -f /var/www/html/test1.tex -e /var/www/html/test1.gif');  

However, the command is not properly executed when running the PhP script. I ran a test command such as:

shell_exec('cp test1.tex test2.tex');  

and was able to check that the file test2.tex was indeed created. I also ran the command:

/var/www/cgi-bin/mimetex.cgi -f /var/www/html/test1.tex -e /var/www/html/test1.gif

from a terminal, and it was executed without error. I also made sure that my apache server is configured so that it can execute cgi scripts following https://www.ionos.com/community/server-cloud-infrastructure/apache/enable-cgi-scripts-on-apache/

I am missing something here... but I don't see what...

1

There are 1 best solutions below

0
Ho Zong On

You could try to execute the cgi script via a GET request, so it is executed by Apache. A simple way to do this AFAIK:

$response = http_get("http://localhost/cgi-bin/mimetex.cgi");

But you can find other ways also, like using curl.

You will need to pass the tex file as a query parameter, appending it like ?texfile=test1.tex, with proper param name.