Exec PHP from PHP

Hi there,

Running into a strange problem. I have setup my Custom PHP.ini using the instructions in the wiki. I’ve got the php5.cgi installed in cgi-bin/php.cgi. Apache is using this CGI, confirmed by phpinfo().

The script I am using, phpMotion, tries to execute a php script to convert video files.

I can get other things to execute, such as “ls -la”, but I cannot get php to run, using even a very simple script, like echo “hi”;

eg> domain.com/test.php tries to exec domain.com/test2.php using php cgi in cgi-bin/php.cgi

I can run php scripts from the shell using this CGI

$: /home/user/domain/cgi-bin/php.cgi -v
php 5.xx

when I run just php from the shell, it tells me version 4. However, my hosting is setup as version 5

Thank you very much for any help




The “secret” is all in HOW you run it. For instance in your example:


That running using php cgi in cgi-bin/php.cgi is to be expected, as is the output below:

$: /home/user/domain/cgi-bin/php.cgi -v
php 5.xx"

In each case, the PHP version run is the one in your cgi bin.

The secret is to run PHP with the correct full path to the desired version of PHP. The paths for the default DreamHost PHP-CLI installed binaries are as follows:

  • PHP 4 - /usr/local/bin/php
  • PHP 5 - /usr/local/php5/bin/php

You can confirm the exact version numbers in use by executing the binary from within the shell using the “-v” option, which will run the binary and return the version information. For example, you can check the version of the PHP5 CLI binary as shown below:

usernamer@server:~$ /usr/local/php5/bin/php -v
PHP 5.2.3 (cli) (built: Aug 21 2007 17:24:23)
Copyright © 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright © 1998-2007 Zend Technologies
with Zend Extension Manager v1.2.0, Copyright © 2003-2006, by Zend Technologies
with Zend Optimizer v3.2.2, Copyright © 1998-2006, by Zend Technologies

From the DH Wiki article on PHP

–DreamHost Tech Support

Thanks a lot rlparker.

I was able to get it working using the full path you gave me. I also needed to append “-c cgi-bin” so that it would look for the php.ini in the cgi-bin (which is the reason why I have a custom php.cgi).

This is for a phpMotion setup so it may help someone else down the line.

rlparker, could you please let me know why it would not work calling the version of php in the cgi-bin? I can use this version from the shell with no problem… Thanks a lot

You are welcome, and I’m glad you got it to work. :slight_smile:

Not authoritatively, I can’t, but I suspect that it is related to the fact the the PHP in your cgi-bin is a PHP-CGI binary, and the others are PHP-CLI binaries.

I’m betting the PHP manual discussion of the differences between the two hold the answer to your question. :wink:

–DreamHost Tech Support

That sounds right, thanks for pointing me in this direction.