Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It has been a while since I did any scripting with php. Now that I'm back at it, I find I'm missing something simple. Currently, the only way I am able to run my scripts is with the php command in front of them:

> php script.php

What do I need to do to enable running them directly? For reference, I am on kubuntu 10.0.4, and the php executable is located in /usr/bin/

share|improve this question
up vote 2 down vote accepted

PHP is most often interpreted (it can be compiled but that's often more work than it's worth). So the way your running PHP is the best and most straight forward way to run PHP via commandline. If you really dislike including php every time your can include #!/usr/bin/php at the beginning of the file and then run them directly. Before you can run them make sure to set the execute flag > chmod +x helloworld.php.

echo "hello world";

> helloworld.php

share|improve this answer
I suppose that makes sense. Would you say the same thing is true for python scripts? (e.g. that they are best run by > python ) – Jeffrey Blake Jul 15 '10 at 0:03
Probably the easiest way to find out the answer is to try it. Post up your findings. – Kendall Hopkins Jul 15 '10 at 0:11
I used to do this when all I knew was PHP. Then I learned Perl. Don't forget to chmod +x the PHP file before trying to run it as a command. – amphetamachine Jul 15 '10 at 0:49
@amphetamachine good catch – Kendall Hopkins Jul 15 '10 at 1:43
@SoftwareElves I wasn't asking if the same command would make python scripts executable. I was asking if the same best practice applied. That is, if it better to run python scripts via > pythong than to add a similar line and run them as executable. I don't see how "testing to find out" applies when weighing on which option is better. – Jeffrey Blake Jul 16 '10 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .