Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 919
Claudio Ɯǝıs Mulas Avatar asked Mar 05 '17 23:03

Claudio Ɯǝıs Mulas


People also ask

What do you need before running PHP files?

If you want to run a PHP file in the browser on your own computer, you'll need to set up a PHP development stack. You'll need at least PHP, MySQL, and a server like Apache or Nginx. MySQL is used to set up databases your PHP applications can work with.

Why PHP script is not running in browser?

PHP is not intended for execution in a browser. It is for web servers to execute, or other preprocessing on the PHP-installed computer. PHP runs in several incarnations when installed on a computer: from the command line.

Can I run PHP script from command line?

A PHP script can be executed from the command line even without having any web server software installed. To run the PHP script from the command line you should just have a PHP CLI (PHP Command Line Interface) installed on your system.


1 Answers

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.

like image 75
jsherk Avatar answered Oct 09 '22 08:10

jsherk