Chinaunix首页 | 论坛 | 博客
  • 博客访问: 262504
  • 博文数量: 28
  • 博客积分: 688
  • 博客等级: 上士
  • 技术积分: 365
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-16 10:25
文章分类

全部博文(28)

文章存档

2012年(28)

我的朋友

分类: LINUX

2012-03-19 19:08:26

添加PHP /usr/local/php/bin”到PATH
1.使用这种方法,每当登出PATH就会恢复

1 export PATH=$PATH:/usr/local/php/bin

2.这种方法最好,除非你强制手动修改PATH的值,否则将不会被改变
在适当位置添加”/usr/local/php/bin”

01 [root@hexuweb101 ~]$ vi /etc/profile
02 .......
03 .......
04 .......
05 HOSTNAME=`/bin/hostname`
06 HISTSIZE=1000
07   
08 if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
09     INPUTRC=/etc/inputrc
10 fi
11 ############# 添加下面行 ##################
12 PATH=/usr/local/php/bin:/usr/local/mysql/bin:$PATH
13 ############# 添加上面行 ##################
14 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
15   
16 for i in /etc/profile.d/*.sh ; do
17     if [ -r "$i" ]; then
18         . $i
19     fi
20 done

3.这种方法是针对用户起作用的,比如如果是在root权限操作,则root用户有效。

01 [root@hexuweb101 ~]$ vi ~/.bash_profile
02 # .bash_profile
03   
04 # Get the aliases and functions
05 if [ -f ~/.bashrc ]; then
06         . ~/.bashrc
07 fi
08   
09 # User specific environment and startup programs
10 ######修改 PATH行,把/usr/local/php/bin添加进去
11 ######PATH=$PATH:$HOME/bin
12 PATH=/usr/local/php/bin:$PATH:$HOME/bin
13   
14 export PATH
15 unset USERNAME
16 ~

注意:想改变PATH,必须重新登陆才能生效,以下方法可以简化工作:

如果修改了/etc/profile,那么编辑结束后执行source profile 或 执行点命令 ./profile,PATH的值就会立即生效了。

01 #添加完成保存后,测试如下:
02 [root@hexuweb101 ~]$ php -v
03 #-bash: php: command not found
04 #上面原因是因为添加完成后还没有生效,使用下面方法即可:
05 [root@hexuweb101 ~]$ cd /etc
06 [root@hexuweb101 etc]$ source profile
07 [root@hexuweb101 etc]$ php -v
08 PHP 5.3.2 (cli) (built: Jun 16 2010 11:45:47)
09 Copyright (c) 1997-2010 The PHP Group
10 Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
11     with XCache v1.3.0, Copyright (c) 2005-2009, by mOo
12 [root@hexuweb101 etc]#

这个方法的原理就是再执行一次/etc/profile shell脚本,注意如果用sh /etc/profile是不行的,因为sh是在子shell进程中执行的,即使PATH改变了也不会反应到当前环境中,但是source是在当前 shell进程中执行的,所以我们能看到PATH的改变。

阅读(1585) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~