0

I have one file with code

shell_exec (php test.php)

When I run this file from command prompt, It run successfully and when same file I am trying to run through web browser this will give error as

sh: php command not found.

what can be the issue?

2
  • 1
    Can you elaborate on how you do run this file through the web browser? What exactly are you trying to do?
    – MadMike
    May 30, 2016 at 11:33
  • The browser shouldn't be running anything through sh.
    – user423626
    May 30, 2016 at 11:44

1 Answer 1

3

Most likely the path for php isn't in the $PATH environment variable used for shell_exec when you are running it from the web server.

Use the full path for the php command, like

shell_exec (/usr/bin/php test.php)

You can use the which command on the command prompt to find the full path for php

which php
1
  • 1
    This is correct but my code is going to deploy on various server so can not hardcode the path. can you please tell me the way where I will get /user/bin/php path dynamically in php code.
    – Anuja P
    May 30, 2016 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .