第一種方法:
打開用戶根目錄下的:
vi ~/.bash_profile
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH alias php=/usr/local/php/bin/php
修改后保存
然后執行
source ~/.bash_profile
測試一下 php -v

第二種方法:
設置環境變量 :修改/etc/profile文件使其永久性生效,並對所有系統用戶生效,在文件末尾加上如下兩行代碼
PATH=$PATH:/usr/local/php/bin export PATH
然后執行生效命令
source /etc/profile
查看PHP版本信息
php -v
