Php_exec help


#1

trying to use php_exec () to run another php script

shell_exec(“php test.php”);

i get
Status: 404
X-Powered-By: PHP/4.4.2
Content-type: text/html

No input file specified.

but when i run “php test.php” in an ssh session the script runs properly

tried various abolute paths. still no joy. anyone know of a solution?


#2

shell_exec is disabled in Apache for security reasons. I believe that the only way around this is to install your own PHP.

-Scott


#3

I can use shell_exec for commands like ls and ls -al

some how the argument i.e. the filename is not being passed properly and its getting a file not found error.


#4

I must be remembering from the past when sites were run as the Apache user, and not as yourself.

‘ls’ is fairly harmless, but executing a php script is more of an include.

Here’s a wiki article that describes ways to get around a disabled PHP function:
http://wiki.dreamhost.com/index.php/Allow_url_fopen

Again, to gain complete PHP functionality, you’ll need to compile your own PHP.

-Scott


#5

already though of that. did a “whoami” command and the username came up as myself.

if I do “cat index.php” it works as expected. so the argument is being passed there

but if I do “php test.php” No input file specified.

tried various forms of absolut/relative paths… no joy


#6

Your initial post said that ‘php test.php’ worked as it should. Has something changed?

-Scott


#7

I have a strong feeling it is nothing more that a path problem. php is a different directory than your php script. Unless you uploaded php to your directory and placed the script in that same directory, which I highly doubt.
Silk

My website


#8

I believe silkrooster might be right - its probably a path problem.

In your SSH client, try typing “whereis php” (without the quotes) - that will tell you where PHP is located on the server.

Then in your shell_exec() function, replace php with the full PHP path.

If that doesn’t work - try putting the correct path before test.php - that’s usually /home/DHusername/domain/


#9

“php test.php” works in ssh
not as a shell_exec();

I also made a perl script to execute php test.php
launching from shell, no probs. launching from web. same “no input file.”


#10

whereis php in shell
php: /etc/php /usr/local/bin/php /usr/local/lib/php

whereis php in shell_exec ()
php: /etc/php /usr/local/bin/php /usr/local/lib/php

which php in shell
/usr/local/bin/php

which php in shell_exec ()
/usr/local/bin/php

tried shell_exec ("/usr/local/bin/php /home/username/something.dreamhosters.com/test.php")

still nothing :frowning:


#11

Just for the heck of it try your exec using single quotes instead of double. As there is a period in that string, it may be confusing php.
Silk

My website


#12

tried single quotes tried direct back ticks approach…

FYI: this is the code

<?php $foo= shell_exec("php test.php"); echo "
$foo
"; ?>

where test.php is - for testing purposes

<?php echo "boo"; ?>

#13

Please test this code:

<?php $foo= shell_exec("/absolute_path/php /absolute_path/test.php"); echo "<pre>$foo</pre>"; ?> :wink: [color=#CC0000]Here[/color] are my Hosting Plan Comparision and $97 off DreamHost Promo Code


#14

nothing :frowning:

can you someone please try on their webspace and tell me if it works.


#15

I tried it using “php absolutepath/test.php” and I got verification that php is indeed working, as it displayed the version of php and some header info multiple times in a row. However the actual text did not display.
Silk

My website


#16

do you get this?
Status: 404
X-Powered-By: PHP/4.4.2
Content-type: text/html

No input file specified.


#17

I don’t recall the status , but yes the rest of it is correct.
Silk

My website


#18

so you get

“No input file specified.”


#19

No I did not get that.
Just

X-Powered-By: PHP/4.4.2
Content-type: text/html

Over and over.
Silk

My website