When you run the php command on the server, it uses the system version (which changes over time). You can specify a version of PHP for your shell to use. This way, all PHP commands will use that specific version.
Which shell user's file to update?
The examples in this article use the bash shell. There are also other shells you can use at DreamHost. The profile file you update is different depending on the shell type you're using. For example, the current supported default shells are Bash, Korn, Tcsh, and Zsh. Below are the profile files for each shell type:
If you’re using tcsh, you must modify the command as shown below before they can be added to the .tcshrc profile:
alias php /usr/local/php71/bin/php set path=(/usr/local/php71/bin $path)
You can also modify this accordingly using the path to any of the PHP-CLI binaries.
Changing your shell user's PHP version
To change the default version of PHP under your Shell user:
- Log into your user via SSH.
- Make sure you’re in your user's directory by running the following:
[server]$ cd ~
- View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. Add the following line to force PHP 7.2.
- Save and close the file and return to your shell.
- Update that file by running the following command:
[server]$ . ~/.bash_profile
- If you now run php -v you’ll see the new version being used.
[server]$ php -v
Using an alias to change the PHP version
You can also use an alias instead. Add the following to your .bash_profile file.
This works the same as export PATH when added to your .bash_profile.