View Full Version : [ubuntu] run php from commandline

April 11th, 2012, 08:54 PM
What do I need to do to my server to allow a user to run a php script from console?

ie $ php myfile.php -- options

found the answer

sudo apt-get install php5-cli :)

Jonathan L
April 12th, 2012, 10:43 AM

If this is your first go at command-line PHP, there might a couple of other things you need which can be tricky to find out.

If you want to run the command like this:

$ mything optionsYou need

The file to be findable: call your file 'mything' and put it in a place in your path: typically ~/bin/mything or more rarely /usr/local/bin/mything
The file to be executable: chmod 775 ~/bin/mything
File must begin with special 'hash-bang' line: #!/usr/bin/php
Your options are accessible in the array $argv

Example file in ~/bin/showargv

?>And this is it running

$ showargv one two three
[0] => /home/username/bin/showargv
[1] => one
[2] => two
[3] => three
)Hope this helps someone.

Kind regards,