1

I have a script (file1.php)in php in linux

#!/usr/bin/php -q
<?php
 echo "hello world" ?> 

when i run in linux (redhat @ bash shell)

>  php file1.php

it works. my php is in /usr/bin/php and its version is 5.3.3)

but when i run

./file1.php

it says

'./file1.php' not present.

my application requires this ('./file1.php') model to work

on my other machine this file works with ('./file1.php') model

why is it so , is there any way to fix this ..

  • **/usr/bin/php -v works well
  • file permission (file1.php): -rwxr-xr-x 1 root root**
6
  • is the file executable, e.g. chmod 755? to use ./file.php, it must be executable. Commented Jul 12, 2013 at 19:40
  • are you in the same directory as file1.php when you do this? Commented Jul 12, 2013 at 19:42
  • @Orangepill yes sure on the same directory Commented Jul 12, 2013 at 19:44
  • what did /usr/bin/php -v return Commented Jul 12, 2013 at 19:53
  • @Orangepill : PHP 5.3.3 (cli) (built: Feb 22 2013 02:51:11) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies Commented Jul 12, 2013 at 19:54

1 Answer 1

2

You should indicate how your file should be executed. In bash, it's done using a shebang Try adding this line add the very top of your php script:

#!/usr/bin/php
<?php echo 'Hello world!';

This would tell bash to run ./file.php as php /fullpath/file.php More info http://en.wikipedia.org/wiki/Shebang_(Unix)

Sign up to request clarification or add additional context in comments.

6 Comments

removed -q from the shebang now it says -bash: ./file1.php: /usr/bin/php^M: bad interpreter: No such file or directory , ## am on the same directory
I don't understand your comment. Try creating a file with the exact content I wrote above, make sure you set executing permissions chmod +x file.php, and run it as ./file.php Edit: That's bash indicating it can't find the php interpreter. Run whereis php, it will thell you where your php interpreter is. You should use that path. You said yours was on /usr/bin/php so running /usr/bin/php --version should work, and the code above should work.
created , it says Extension './file1.php' not present.
it's trying to load ./file1.php as an extension not as a script file. It's acting like it's calling /usr/bin/php -z file.php
type alias on the command line... see if there is any php alias set
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.