php cli not executing script but displaying file content

I’m trying to execute a php script via command line like:

"php -f test.php"

I first tried some serverside socket programming and now just tried a minimal example with test.php only containing the line

echo "test";

What I expect would be the output on the cli “test” but the php command only echos the file content on the command line, showing: ‘echo “test”;’ instead of executing the command echo. Same for my socket programming

I also tried using #!/usr/bin/php and make the script executable (chmod 755) giving the same result.

output of whereis php:

php: /usr/bin/php /usr/bin/php7.0 /usr/lib/php /etc/php
/usr/share/php7.0-json /usr/share/php7.0-opcache
/usr/share/php7.0-readline /usr/share/php7.0-common

I tried this independently on my server and my laptop (Ubuntu and Xubuntu, both have php7.0 and especially php7.0-cli installed). I must be doing something very basic wrong… however, in this tutorial nothing is stated what I could do differently:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s