Linux下修改PATH(添加PHP/Mysql到PATH)的三种方法
添加PHP /usr/local/php/bin”到PATH
1.使用这种方法,每当登出PATH就会恢复
1export PATH=$PATH:/usr/local/php/bin2.这种方法最好,除非你强制手动修改PATH的值,否则将不会被改变
在适当位置添加”/usr/local/php/bin”
01[root@hexuweb101 ~]$ vi /etc/profile02.......03.......04.......05HOSTNAME=`/bin/hostname`06HISTSIZE=100007?08if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then09????INPUTRC=/etc/inputrc10fi11############# 添加下面行 ##################12PATH=/usr/local/php/bin:/usr/local/mysql/bin:$PATH13############# 添加上面行 ##################14export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC15?16for i in /etc/profile.d/*.sh ; do17????if [ -r "$i" ]; then18????????. $i19????fi20done3.这种方法是针对用户起作用的,比如如果是在root权限操作,则root用户有效。
01[root@hexuweb101 ~]$ vi ~/.bash_profile02# .bash_profile03?04# Get the aliases and functions05if [ -f ~/.bashrc ]; then06????????. ~/.bashrc07fi08?09# User specific environment and startup programs10######修改 PATH行,把/usr/local/php/bin添加进去11######PATH=$PATH:$HOME/bin12PATH=/usr/local/php/bin:$PATH:$HOME/bin13?14export PATH15unset USERNAME16~??????????????? 注意:想改变PATH,必须重新登陆才能生效,以下方法可以简化工作:
如果修改了/etc/profile,那么编辑结束后执行source profile 或 执行点命令 ./profile,PATH的值就会立即生效了。
01#添加完成保存后,测试如下:02[root@hexuweb101 ~]$ php -v03#-bash: php: command not found04#上面原因是因为添加完成后还没有生效,使用下面方法即可:05[root@hexuweb101 ~]$ cd /etc06[root@hexuweb101 etc]$ source profile07[root@hexuweb101 etc]$ php -v08PHP 5.3.2 (cli) (built: Jun 16 2010 11:45:47)09Copyright (c) 1997-2010 The PHP Group10Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies11????with XCache v1.3.0, Copyright (c) 2005-2009, by mOo12[root@hexuweb101 etc]#这个方法的原理就是再执行一次/etc/profile shell脚本,注意如果用sh /etc/profile是不行的,因为sh是在子shell进程中执行的,即使PATH改变了也不会反应到当前环境中,但是source是在当前 shell进程中执行的,所以我们能看到PATH的改变。
http://blog.hexu.org/archives/647.shtml