I installed the Lighttpd server with php according to this tutorial: http://www.penguintutor.com/linux/light-webserver

the command to install php was this:

sudo apt-get install php5-common php5-cgi php5

What i would like to do is to run the php commands from the prompt, and not only via lighttpd, and i thought i heard somebody say that you could also do this:

php testme.php

now i get an invalid command error, and I think that is because the php executable can not be found?

Then I've looked where the PHP package was installed, but I can not find it I don't know how to find it.

For Python it was easy because i could call that from every path, but I can not do that for PHP.

What do I have to do?

1 Answer 1


You need to install "php5-cli":

sudo apt-get install php5-cli

After that, you will have a php binary to run in your path. You can see where it is with:

which php
  • Thanks, will try that. Can you explain me what you mean by 'php binary to run in your path'? Does the install of 'php5-cli' only set the path correct, or does it install an extra binary for running PHP from the prompt, or.....
    – Michel
    Mar 7, 2013 at 15:43
  • 1
    When you type "php" (or "ls" or anything), it checks the variable $PATH to see the folders where to look for the "php"/"ls"/... binary. (you can see this by typing "echo $PATH") After installing php5-cli, the "php" will be in one of the folders inside $PATH, so you can just run it by typing "php <somescript.php>", and do not need to know a full path for that binary.
    – mulaz
    Mar 7, 2013 at 15:45
  • So it's more a settings kind of install than an extra program installed? If I would know the location of the installed PHP libs, then i could run php from the prompt also without installing the php5-cli? (Not that I don't want to install the php5-cli, just trying to understand)
    – Michel
    Mar 7, 2013 at 16:14
  • No, you still need php5-cli (since the binary is in that package). If you install a custom package ("mybin"), you can install the binary to /some/random/path/, but if you wish to run it, you must run it with full path ("$ /some/random/path/mybin"). If "/some/random/path" is in the $PATH variable, you can run it just with "$ mybin". Since php5-cli installs itself in a folder which is inside the default $PATH variable, you can run it just via "php5" or "php" (not sure), without thinking about where the binary is ("/usr/bin" or "/usr/local/bin" or wherever)
    – mulaz
    Mar 7, 2013 at 16:17
  • 1
    That is a library for apache/lighthttpd/etc. You need a standalone binary to run php scripts from cli.
    – mulaz
    Mar 7, 2013 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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