0

I have installed LAMP in my ubuntu environment (16.04) which has apache, php (7.0.9), mysql...

Although the php functionality is there, when i type 'php -v' in the terminal, i get the message

The program 'php' can be found in the following packages
* php7.0-cli
* hhvm

which as i understand means that ubuntu does not recognise the php installation from LAMP .


Is there a way to tell ubuntu that there is a php installation in opt/lamp... in order to recognise it?

4

The message you see is triggered by a shell function called command_not_found_handle defined in your system wide bashrc (/etc/bash.bashrc). This function is called by the bash when you enter the name of a binary which is not found in the current PATH. On Ubuntu, this uses a tool called command-not-found to search your input against a package database and suggest a package that might contain the command you entered.

Depending on how you installed your LAMP stack - by using apt-get a lot or unblobbing a big tar file - there are two answers to your question.

In case you did apt-get all the stack applications you just did not install the php-cli package. In that case you can do sudo apt-get install php7.0-cli and you are fine.

In your question you mention /opt/lamp which suggests that you did the unblob-a-tar thing. This means that you should have a php cli binary somewhere in a bin directory under your /opt/lamp. What you can do is

  1. Call it using an absolute path, i.e. /opt/lamp/bin/php -v: this is perfect if you call it only now and then
  2. You can add a symlink into your bin folder, i.e ln -s /opt/lamp/bin/php /usr/bin/php: helpful if the LAMP version is the only version in your system and you use it regulary
  3. Add the path of the bin folder to your PATH environment: you might use this if the LAMP is an integral part of your system

bin/php is just an example here - your actual binary might be in a different directory under a different name. Replace it with the correct path once you found it.

If you install a full binary package in /opt it might be a good idea to check if it and if so how it uses libraries that exist in your core system. You can do this by issuing ldd /opt/lamp/bin/php and check the paths of the libs that are printed. Sometimes you get into trouble when those binaries still use your system libs but expect different versions.

  • Thank you @FredFoo your answer solved it. Very good explanation! – Mario Sep 21 '16 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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