3

Normally when I want to run a php script from the command line I just create a php page, add a shebang pointing to the php binary, then ./file.php to run it. Since I have php installed as an apache module, I'm not even sure what my shebang should look like. Any ideas?

2 Answers 2

12

The CLI version of PHP had been part of the default installation since 4.3 and has to be explicitly turned off when PHP is being built. If you have access to the command line try

$ php -v

If you don't get a command not found error then you should be ready to go.

To actually run a php file from the command line do this:

$ php -f file.php
Sign up to request clarification or add additional context in comments.

2 Comments

then I think you are out of luck, they must have compiled PHP without the CLI support
what do you do if the system does not recognize PHP but you have PHP running?
3

If it's just an Apache module, I don't think you can do it… At least, not without using a script like this:

$ cat run_php_with_apache
#!/bin/sh
cp "$1" /var/www/
curl "http://localhost/`basename "$1"`"
rm "/var/www/`basename "$1"`"

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.