Claudio Ɯǝıs Mulas
Claudio Ɯǝıs Mulas

Reputation: 1113

Can't execute a php script without using "php" command before

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?

Upvotes: 6

Views: 5000

Answers (2)

Erik Sundberg
Erik Sundberg

Reputation: 91

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!!!!

Upvotes: 1

jsherk
jsherk

Reputation: 6472

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.

Upvotes: 11

Related Questions