Changing the default PHP Command Path

11,685

Solution 1

You can edit your .bash_profile file to change your default search path. Or update it using PATH=/usr/local/php/bin:$PATH or somesuch.

Solution 2

The below code worked for the specific circumstance in my earlier question:

printf "\nexport PATH=/usr/local/php/bin:\${PATH}\n" >> /etc/profile
source /etc/profile

Hope it helps.

Share:
11,685
ObiHill
Author by

ObiHill

Updated on June 14, 2022

Comments

  • ObiHill
    ObiHill almost 2 years

    I'm running Ubuntu Natty.

    I recently installed PHP 5.3.8 from Source and it works ok. However, as part of my installation, I had to install php5-dev so I guess this has installed another PHP on the server (I needed to do this for phpize).

    My main PHP binary is at /usr/local/php/bin. However, when I run php from the command line with something like this php --ini I get the following:

    $ php --ini
    Configuration File (php.ini) Path: /etc/php5/cli
    Loaded Configuration File:         /etc/php5/cli/php.ini
    Scan for additional .ini files in: /etc/php5/cli/conf.d
    Additional .ini files parsed:      /etc/php5/cli/conf.d/pdo.ini
    

    I can still run PHP from /usr/local/php/bin, but that would mean me having to type the whole path out for all my command line scripts.

    Is there a way I can change this behaviour so that when I use the php command, it points to the php binary inside /usr/local/php/bin instead?!

    Thanks in advance

  • ObiHill
    ObiHill over 12 years
    Not familiar with this. Where can I find that file?
  • Matt H
    Matt H over 12 years
    It's a usually hidden file, should be in your home ~ folder. Might also be ~/.bashrc
  • ObiHill
    ObiHill over 12 years
    There's a file in my /etc directory called bash.bashrc, I'm thinking this is the one?! But I have no idea what to do here, can you link me to a tutorial or something?
  • Matt H
    Matt H over 12 years
    An easier way: #] echo $PATH to see what's the first entry. That's where your computer will search first. In that folder, type: #] sudo ln -s /usr/local/php/bin/php ./php That will create a "simlink" to the version of PHP you really want to use, so using #] php in your folders will execute the one you want.
  • ObiHill
    ObiHill over 12 years
    Thanks a lot. I'll try that out.