显示标签为“环境”的博文。显示所有博文
显示标签为“环境”的博文。显示所有博文

2011年12月12日星期一

Ubuntu 环境变量的设置


持久性的环境变量



到目前为止,我们只讨论临时设置一个环境变量的方式,当设置它时所在的shell会话被关闭时这个环境变量也就失效了。有人可能会问,是否有一种方法来永久设置一个环境变量为特定的值。

Note: 下面提到的Shell配置文件只为特定Shells和桌面环境所读取,不应该被以其他方式使用。

会话范围环境变量


只影响特定用户的环境变量 (而不是整个系统)应该在下面文件中设置:

  • ~/.pam_environment - 这个文件是特别为设置用户的环境变量.它并不是一个脚本文件,而是由每行一句声明表达式组成


Note:使用 .pam_environment 需要重新登录以便初始化环境变量. 仅仅重新打开 terminal 并不能够立即使用这些变量.

如果你正在使用 KDE, 请查看 the KDE User-base page on this topic.

不推荐在下面文件中设置:

  • ~/.profile - This is probably the best file for placing environment variable assignments, since it gets executed automatically by the Display Manager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console.

  • ~/.bash_profile or ~./bash_login - If one of these file exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.

  • ~/.bashrc - Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. However, performance-wise this may not be the best thing to do since it will cause values to be unnecessarily set many times.



系统范围环境变量


影响整个系统的环境变量设置 (而不是仅仅一个用户) 不应该放在任何系统或桌面会话加载时被执行的系统级别的脚本中,而应该在下面文件中设置:

  • /etc/environment - 这个文件是特别为设置系统范围的环境变量. 它并不是一个脚本文件,而是由每行一句声明表达式组成. 特别地,这个文件存储了系统范围的 locale 和 path 设置.


不推荐在以下文件中设置:

  • /etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the Display Manager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more then invoke the /etc/bash.bashrc file.

  • /etc/bash.bashrc - This is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.


Note: 当处理多用户桌面系统时,把设置放在上面提到的用户的~/.pam_environment 文件中是比较合适的,而不是系统范围的文件,因为这些文件不需要root权限来编辑,并且很容易在多个系统中移动。

原文链接:https://help.ubuntu.com/community/EnvironmentVariables

2011年8月9日星期二

在XP及Ubuntu上快速安装及配置LAMP(Linux+Apache+Mysql+Php/Perl/Python)环境

Ubuntu 快速安装LAMP环境及配置方法:




一、安装LAMP环境
在终端输入以下命令(是的,你没看错,只用一条命令即可)

sudo apt-get install apache2 mysql-server mysql-client php5 php5-gd php5-mysql

安装过程中会要求你设置MySQL的帐户root密码,暂时可以直接回车,不设置密码

二、配置LAMP环境
Apache2默认安装在/etc/apache2目录下
打开用户配置文件:

sudo gedit /etc/apache2/httpd.conf


添加下面的一行来启用php文件类型支持:

AddType application/x-httpd-php .php .php5

至此LAMP已可以正常运行 网站目录默认在 /var/www

三、其他可选配置
1>apache 的配置文件路径 /etc/apache2/httpd.conf
2>php.ini 路径 /etc/php5/apache2/php.ini
3>mysql配置文件 路径 /etc/mysql/my.cnf
4>phpmyadmin配置文件路径 /etc/phpmyadmin/apache.conf
5>网站根目录配置文件路径 /etc/apache2/sites-enabled






XP 快速安装LAMP环境及配置方法:




一 安装及配置Apache

1.打开网页 选择合适的版本下载
http://httpd.apache.org/download.cgi

2.xp下双击安装包,直接安装
ubuntu下安装说明见 apache.org/docs/2.2/install.html

3.打开conf/httpd.conf 进行配置

#配置网站所在的文件夹
DocumentRoot "D:/webdocs"


#配置网站文件夹的属性


#当文件不存在时不要列出目录中的文件列表
Options -Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# 控制对此目录的访问权限
#
Order allow,deny
Allow from all




二 安装及配置Mysql
Ubuntu下安装过程见此文 ubuntu 10.04 MySQL 5.5.11 源代码编译安装
XP下可直接下载安装包

三 安装及配置PHP

1.下载 the PHP zip binary distribution from » PHP for Windows: Binaries and Sources.

选择 VC6 x86 Thread Safe 版本

2. 直接解压后放在softs文件夹下即可

3. 在安装目录中另存 php.ini-production 为 php.ini 并进行配置

a.设置模块目录并开启需要的模块

; Directory in which the loadable extensions (modules) reside.
; 此项设置模块所在的目录,注意如果path变量没有设置php安装目录时
; 此项一定要设置为绝对目录,否则Apache将无法正确加载php扩展模块
extension_dir = "D:/softs/php-5.2.17/ext/"

以上设置不正确时将会出现类似下述错误信息

PHP Warning: PHP Startup: Unable to load dynamic library './ext/php_bz2.dll' - \xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\xa3\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library './ext/php_curl.dll' - \xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\xa3\r\n in Unknown on line 0


b.设置可最大上传文件的大小和默认时区等选项

[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/Chongqing


4.打开apache 的 conf/httpd.conf 进行配置

# 让apache自动在每次启动时加载php模块. apache2.2 版本需要加载php5apache2_2.dll
LoadModule php5_module "D:/softs/php-5.2.17/php5apache2_2.dll"
AddHandler application/x-httpd-php .php

# 配置 php.ini 文件所在路径
PHPIniDir "D:/softs/php-5.2.17"


5.重启计算机

----------------------------------------------------
今天调试网页时发现apache服务器经常自动重启,打开error.log文件后发现下述信息

[Sat Aug 20 19:43:25 2011] [notice] Parent: child process exited with status 3221225477 -- Restarting

在网上查找一番后发现原因是php文件中包含了数据库查询语句,而apache调用了与当前版本不一致的libmysql.dll 所致。
由于安装的mysql 数据库是早期版本,在安装mysql后程序自动设定mysql安装目录为PATH环境变量。mysql安装目录下含有版本不一致的libmysql.dll 文件,apache调用了那个不合适的文件后产生错误。

而在安装php时并没有将php目录设定为PATH环境变量。

解决办法:删除mysql安装目录里面的libmysql.dll 文件,然后将php安装目录设置为PATH环境变量即可。

2011年1月10日星期一

大量动物的死亡:谁是环境中的凶手

原文链接:Mass Animal Deaths: An Environmental Whodunit

GORMAN-articleLarge
在星期一数百只死鸟躺在路易斯安那州的高速公路上

当5000只红翼黑鸟在新年前夕摔死在阿肯色州,同时500多死在路易斯安那州时,很多人立刻就想找出凶手是谁。有关于军事试验和农药的推测,以及很多这些鸟类死亡是否和其他事件比如大量鱼类的死亡有关联的疑问。