Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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.

#!/usr/bin/php
<?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 script.py ) –  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
1  
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 script.py 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.