ade19
ade19

Reputation: 1200

Run php file via command line on an ubuntu linux server

I am trying to run a php file on a ubuntu linux server but get a 'command not found' error when i run "php file_name.php"

Searching online, i found an article that suggested I run "sudo aptitude install php5-cli" which I did and restarted apache afterwards but I still get this error.

How do I fix this?

Upvotes: 3

Views: 32156

Answers (3)

nitin
nitin

Reputation: 1

  • Try the following step :
  • Open your cmd/console or press ctr+alt+t.
  • php5 /your/path/to/php_file_name.

Upvotes: 0

Learner
Learner

Reputation: 714

Try this once,

Go to terminal.

whereis php

It will show where is php installed.

Export that path to environment variable using following command

export PATH=$PATH;/path/to/php's/bin directory

Then execute required file..

As follows,

php file_to_execute.php

Upvotes: 5

Ace
Ace

Reputation: 1477

first make sure that you've installed following packs:

  • php5
  • php5-cli
  • php-pear

like this:

sudo apt-get install php5 php5-cli php-pear

then make sure to configure php safely befor using it.

also make your php file executable ( chmod 700 )

Upvotes: 2

Related Questions