6

I need to use a php script without "php" command.

For example:

$ ./test.php

Permissions are sets to 755.

This is the script

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

/usr/bin/php -v (so path exists)

returns

PHP 7.0.15-1+deb.sury.org~xenial+1 (cli) (built: Jan 20 2017 08:53:13) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-1+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies

This is the error I'll get everytime:

Exception: Zend Extension ./test.php does not exist

Also calling script with fullpath I'll get same error.

Calling this it works properly

$ php ./test.php

Any idea?

6
  • There must be something wrong with your php.ini, in my environment it works. Maybe you exported an environment variable for the search path php uses? Or it's the OPcache Commented Mar 6, 2017 at 0:09
  • Try dos2unix test.php then re-try. Mine works fine like @Psi so you may have windows style line endings. See here: askubuntu.com/questions/239927/… Commented Mar 6, 2017 at 0:13
  • 1
    In a linux server? rather not. And as far as I can see, Claudio uses a debian. And I typed that file manually in vi, no upload involved Commented Mar 6, 2017 at 0:14
  • I think is something related of how I've uploaded the file... I've used phpstorm but creating the file with vi it works. Maybe an encoding related issue. Commented Mar 6, 2017 at 0:19
  • 1
    Yes, found the problem. Not encoding but ending line format. Unix ok, windows not. Commented Mar 6, 2017 at 0:22

2 Answers 2

11

NOTE: The author found the solution and put it up in the comments but never posted an actual answer, so this answer is just clarifying what the author already said above so as to make the answer more obvious.

I was also getting the Exception: Zend Extension does not exist when I was trying to pipe an email via cpanel forwarder into a php script.

I opened the file in my editor (Komodo Edit on Windows) and went to EDIT > CURRENT FILE PREFERENCES and noticed that LINE ENCODINGS was set to DOS/Windows (\r\n)

I changed the LINE ENCODING to UNIX (\n) and saved it and re-uploded it and the error went away and all is good now.

Obviously the steps will vary depending on what editor you use, but the solution is to make sure your Line Encodings are UNIX and not DOS/Windows.

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

2 Comments

It worked like a charm. saved a lot time. used VsCode to convert Line-Encodings from win to unix
I had temporarily set autocrlf to true and forgot to reset it. it messed up all my PHP files. I removed the git setting, re-cloned and no more Zend error!
1

Just run dos2unix on the file

# ./database.php 
Exception: Zend Extension ./database.php does not exist


# apt install dos2unix


# dos2unix database.php 
dos2unix: converting file database.php to Unix format...

# ./database.php
Yeah!!! It work's!!!!

Comments

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.