3

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?

3
  • Please paste output of following commands: "dpkg -L php5-cli" and "update-alternatives --list php" Commented Aug 28, 2012 at 10:18
  • Package 'php5-cli' is not installed while the update-alternatives gave error no alternatives for php Commented Aug 28, 2012 at 10:25
  • 2
    That means you do not have PHP installed. What were you expecting to happen? Commented Aug 28, 2012 at 10:34

3 Answers 3

5

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
Sign up to request clarification or add additional context in comments.

Comments

2

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 )

Comments

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.