添加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 |
| 05 |
HOSTNAME=`/bin/hostname` |
| 08 |
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then |
| 11 |
############# 添加下面行 ################## |
| 12 |
PATH=/usr/local/php/bin:/usr/local/mysql/bin:$PATH |
| 13 |
############# 添加上面行 ################## |
| 14 |
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC |
| 16 |
for i in /etc/profile.d/*.sh ; do |
3.这种方法是针对用户起作用的,比如如果是在root权限操作,则root用户有效。
| 01 |
[root@hexuweb101 ~]$ vi ~/.bash_profile |
| 04 |
# Get the aliases and functions |
| 05 |
if [ -f ~/.bashrc ]; then |
| 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 |
注意:想改变PATH,必须重新登陆才能生效,以下方法可以简化工作:
如果修改了/etc/profile,那么编辑结束后执行source profile 或 执行点命令 ./profile,PATH的值就会立即生效了。
| 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的改变。
阅读(1676) | 评论(0) | 转发(0) |