ubuntu 使用纪要 -- 持续更新
上周四来weiyouxi入职,从那天开始 从 windows 转向 linux 了吧 先从ubuntu 12.4开始吧,如下是我配置环境中所记录的知识点,硬件: thinkpad e430c
mkdir -p /srv/www/www.example.com/public_html
mkdir /srv/www/www.example.com/logs
chown -R www-data:www-data /srv/www/www.example.com
UNIX Sockets Configuration Example
Next, you'll need to define the site's virtual host file. This example uses a UNIX socket to connect to fcgiwrap. Be sure to change all instances of "example.com" to your domain name.
File:/etc/nginx/sites-available/www.example.com
server {
server_name www.example.com example.com;
access_log /srv/www/www.example.com/logs/access.log;
error_log /srv/www/www.example.com/logs/error.log;
root /srv/www/www.example.com/public_html;
location / {
index index.html index.htm;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
}
}
Create a file named /usr/bin/php-fastcgi with the following contents:
File:/usr/bin/php-fastcgi
#!/bin/bash
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
SOCKET=/var/run/php-fastcgi/php-fastcgi.socket
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid
CHILDREN=6
PHP5=/usr/bin/php5-cgi
/usr/bin/spawn-fcgi -s $SOCKET -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5
Make it executable by issuing the following command:
chmod +x /usr/bin/php-fastcgi
TCP Sockets Configuration Example
Alternately, you may wish to use TCP sockets instead. If so, modify your nginx virtual host configuration file to resemble the following example. Again, make sure to replace all instances of "example.com" with your domain name.
File:/etc/nginx/sites-available/www.example.com
server {
server_name www.example.com example.com;
access_log /srv/www/www.example.com/logs/access.log;
error_log /srv/www/www.example.com/logs/error.log;
root /srv/www/www.example.com/public_html;
location / {
index index.html index.htm;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
}
}
Create a file named /usr/bin/php-fastcgi with the following contents:
File:/usr/bin/php-fastcgi
#!/bin/bash
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
ADDRESS=127.0.0.1
PORT=9000
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid
CHILDREN=6
PHP5=/usr/bin/php5-cgi
/usr/bin/spawn-fcgi -a $ADDRESS -p $PORT -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5
Make it executable by issuing the following command:
chmod +x /usr/bin/php-fastcgi
Important Security Considerations
If you're planning to run applications that support file uploads (images, for example), the above configurations may expose you to a security risk by allowing arbitrary code execution. The short explanation for this behavior is that a properly crafted URI which ends in ".php", in combination with a malicious image file that actually contains valid PHP, can result in the image being processed as PHP.
To mitigate this issue, you may wish to modify your configuration to include a try_files directive. Please note that this fix requires nginx and the php-fcgi workers to reside on the same server.
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
}
Additionally, it's a good idea to secure any upload directories your applications may use. The following configuration excerpt demonstrates securing an "/images" directory.
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/images/") {
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
}
Enable and Start Services
Issue the following commands to enable the site:
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/www.example.com
Create a file named /etc/init.d/php-fastcgi with the following contents:
File:/etc/init.d/php-fastcgi
#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
PID_DIR=/var/run/php-fastcgi
PID_FILE=/var/run/php-fastcgi/php-fastcgi.pid
RET_VAL=0
case "$1" in
start)
if [[ ! -d $PID_DIR ]]
then
mkdir $PID_DIR
chown $FASTCGI_USER:$FASTCGI_GROUP $PID_DIR
chmod 0770 $PID_DIR
fi
if [[ -r $PID_FILE ]]
then
echo "php-fastcgi already running with PID `cat $PID_FILE`"
RET_VAL=1
else
$PHP_SCRIPT
RET_VAL=$?
fi
;;
stop)
if [[ -r $PID_FILE ]]
then
kill `cat $PID_FILE`
rm $PID_FILE
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE"
RET_VAL=1
fi
;;
restart)
if [[ -r $PID_FILE ]]
then
kill `cat $PID_FILE`
rm $PID_FILE
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE"
fi
$PHP_SCRIPT
RET_VAL=$?
;;
status)
if [[ -r $PID_FILE ]]
then
echo "php-fastcgi running with PID `cat $PID_FILE`"
RET_VAL=$?
else
echo "Could not find PID file $PID_FILE, php-fastcgi does not appear to be running"
fi
;;
*)
echo "Usage: php-fastcgi {start|stop|restart|status}"
RET_VAL=1
;;
esac
exit $RET_VAL
Start php-fastcgi and nginx by issuing the following commands:
chmod +x /etc/init.d/php-fastcgi
update-rc.d php-fastcgi defaults
/etc/init.d/php-fastcgi start
/etc/init.d/nginx start
Test PHP with FastCGI
Create a file called "test.php" in your site's "public_html" directory with the following contents:
File:/srv/www/example.com/www/public_html/test.php
<?php phpinfo(); ?>
When you visit http://www.example.com/test.php in your browser, the standard "PHP info" output is shown. Congratulations, you've configured the nginx web server to use PHP-FastCGI for dynamic content!
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
The nginx Homepage
FastCGI Project Homepage
PHP Documentation
Basic Ngnix Configuration
在Ubuntu上配置使用memcached及PHP Memecache 客户端(apt-get方式)
memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视 频、文件以及数据库检索的结果等。
要开发使用memcache ,我们必须安装memcache服务端和PHP的memcache扩展
1、首先安装memcache服务端:
$ sudo apt-get install memcached
然后可以使用命令开启memcache:
$ memcached -l 127.0.0.1 -p 11211 -d -u nobody -P /var/run/memcached.pid -m 64M -c 1024 -vv
解释一下几个参数的意思:
-l 监听的ip地址,127.0.0.1是我本地服务器的IP地址,如果你需要多个服务器都能够读取这台memcached的缓存数据,那么就必须设定 这个ip
-p memcached监听的TCP端口
-d 以daemon方式运行,将程序放入后台
-u memcached的运行用户,我设定的是nobody,memcache默认不允许以root用户登录
-P memcached的pid文件路径
-m memcached可以使用的最大内存数量
-c memcached同时可以接受的最大的连接数
如果你希望以socket方式来访问memcached,那么在启动的时候就必须去掉 -l和-p参数,并加上-s参数:
-s memcached的socket文件路径
-vv显示debug信息
2、安装PHP Memecache 客户端
$ sudo apt-get install php5-memcache
完了重启fastcgi服务,然后用phpinfo()应该就能看见 memcache扩展了
ubuntu 下安装memcache
安装服务器
sudo apt-get install memcached
$ memcached -d -m 50 -p 11211 -u root
参数说明 -m 指定使用多少兆的缓存空间;-p 指定要监听的端口; -u 指定以哪个用户来运行
安装php 模块
sudo apt-get install php5-memcache
编辑配置文件
$ sudo vim /etc/php5/conf.d/memcache.ini
; uncomment the next line to enable the module
extension=memcache.so
[memcache]
memcache.dbpath="/var/lib/memcache"
memcache.maxreclevel=0
memcache.maxfiles=0
memcache.archivememlim=0
memcache.maxfilesize=0
memcache.maxratio=0
在apache中使用 memcache 来作 session 存储,用例子测试一下:
session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211"
使用多个 memcached server 时用逗号","隔开,并且和 Memcache::addServer() 文档中说明的一样,可以带额外的参数"persistent"、"weight"、"timeout"、"retry_interval" 等等,类似这样的:"tcp://host1:port1?persistent=1&weight=2,tcp://host2:port2" 。
<?php
session_start();
$_SESSION["UserID"]=123;
echo session_id();
?>
用 sessionid 去 memcached 里查询一下:
<?php
$memcache = memcache_connect('localhost', 11211);
var_dump($memcache->get('19216821213cxycedec65b0883238c278eeb573e077'));
?>
用 memcache 来存储 session 在读写速度上会比 files 时快很多,而且在多个服务器需要共用 session 时会比较方便,将这些服务器都配置成使用同一组 memcached 服务器就可以,减少了额外的工作量。缺点是 session 数据都保存在 memory 中,持久化方面有所欠缺,但对 session 数据来说也不是很大的问题。
memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视 频、文件以及数据库检索的结果等。
要开发使用memcache ,我们必须安装memcache服务端和PHP的memcache扩展
1、首先安装memcache服务端:
$ sudo apt-get install memcached
然后可以使用命令开启memcache:
$ memcached -l 127.0.0.1 -p 11211 -d -u nobody -P /var/run/memcached.pid -m 64M -c 1024 -vv
解释一下几个参数的意思:
-l 监听的ip地址,127.0.0.1是我本地服务器的IP地址,如果你需要多个服务器都能够读取这台memcached的缓存数据,那么就必须设定 这个ip
-p memcached监听的TCP端口
-d 以daemon方式运行,将程序放入后台
-u memcached的运行用户,我设定的是nobody,memcache默认不允许以root用户登录
-P memcached的pid文件路径
-m memcached可以使用的最大内存数量
-c memcached同时可以接受的最大的连接数
如果你希望以socket方式来访问memcached,那么在启动的时候就必须去掉 -l和-p参数,并加上-s参数:
-s memcached的socket文件路径
-vv显示debug信息
2、安装PHP Memecache 客户端
$ sudo apt-get install php5-memcache
完了重启fastcgi服务,然后用phpinfo()应该就能看见 memcache扩展了
Mplayer 是一个功能强大的媒体播放器。支持的编码方式有:MPEG 1/2/4、DivX 3/4/5、Windows Media 7/8/9、RealAudio/Video(9以下)、Quicktime 5/6 以及 Vivo 1/2。它支持很多针对MX/SSE (2)/3Dnow(Ex)优化的视频/音频编码……(以下略)
在Ubuntu 10.04 (Lucid) 里安装 Mplayer。
首先在软件源的设置里启用“社区维护的开源软件(universe)”和“有版权和合法性问题的软件(multiverse)”
然后刷新软件源:
sudo apt-get update
用下面这行命令安装:
sudo aptitude install mplayer-gui
或者点击下面的链接:
apt://mplayer
现在您可以在 应用程序?影音 里找到 Mplayer Movie Player
在Ubuntu 10.04 (Lucid)里安装 w32codecs 和 libdvdcss2
w32codecs 用于支持WMV、RealMedia和一些其他格式。但是由于版权和法律方面的原因,这个软件包没有包含在Ubuntu的软件仓库里。而libdvdcss2 软件包在播放加密的DVD的时候是必须的。
下面的命令将把 Medibuntu 的软件仓库添加到 Ubuntu,并同时把 Medibuntu 的 GPG 密钥添加到您的密码环,以便于验证 Medibuntu 软件包。
sudo wget http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list --output-document=/etc/apt/sources.list.d/medibuntu.list
sudo apt-get -q update
sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring
sudo apt-get -q update
i386 用户用下面这条命令安装 Codecs:
sudo apt-get install w32codecs libdvdcss2
amd64 用户用下面这条命令安装 Codecs:
sudo apt-get install w64codecs libdvdcss2
上面这个下载地址可用于安装大多数适用于 ubuntu 的解码器包。
给Firefox 安装 Mplayer 插件 //注:经验证,下面这段不管用,提示 mozilla-mplayer 不存在。
如果想给 Mplayer 安装 Mplayer 插件,请运行下面这行命令:
sudo apt-get install mozilla-mplayer
或点击下面的链接:
apt://mozilla-mplayer
在Ubuntu碰到CHM的乱码问题,那么直接“sudo apt-get install kchmviewer”吧!需要注意的是,默认这款软件不会集成在菜单里,你需要在终端下打“kchmviewer”或者自己做个启动器
ubuntu右键在当前目录执行终端terminal程序
直接安装一个软件包nautilus-open-terminal
sudo apt-get install nautilus-open-terminal
重启X(Ctrl+Alt+Backspace)!
gedit 支持windows下的中文txt文件的方法:
1. 安装 gconf-editor
2. 终端运行
gsettings set org.gnome.gedit.preferences.encodings auto-detected "['GB18030', 'UTF-8', 'GB2313', 'GBK', 'BIG5', 'CURRENT', 'UTF-16']"
关于Ubuntu中编码不能自动识别,打开GB2312或GBK编码的文件总是乱码的问题网上有很多相关的文章,多也好用。但对于vi中文乱码的问题,网上很多办法似乎都无效,其中《vim中编辑不同编码的文件时需要注意的一些地方》一文从原理上对编码的问题进行了解释。不过,最实际的还是CSDN Blog上的一篇文章,现转载如下:
Ubuntu 默认采用UTF8编码,可以方便global。但对中文支持,还不细致,即便默认采用中文安装,也并不会自动添加GB*等支持,致使在Ubuntu下访问部分Win文本文件时,出现乱码。
I. 配置系统环境
执行 sudo vi /var/lib/locales/supported.d/zh
加入以下配置参数
zh_CN.GB18030 GB18030 (最新汉字编码字符集,向下兼容GBK,GB2312)
zh_CN.GBK GBK (汉字扩展编码,向下兼容GB2312, 并包含BIG5全部汉字)
zh_CN.GB2312 GB2312 (简化汉字编码字符集, 最近有客户要我们改进GB2312,太看得起我们了,我只能说:”NO!”)
zh_CN.GB18031 GB18031 (数字键盘汉字编码输入,面向手持设备,我的Nokia3120从来就是发短信,接听电话,无法和PC通讯,就不用这个了。 maybe用Google Android SDK的大侠们需要这个)
zh_HK.BIG5 BIG5 (繁体)
zh_TW.BIG5 BIG5 (繁体)
然后执行 sudo locale-gen
提示以下信息,成功了
zh_CN.GB18030… done
zh_CN.GBK… done
……
II. 系统环境支持GB*内码了,但用vi, gedit等工具访问文件还会继续乱码,需要针对不同的工具分别配置,使之自己检测支持范围内的编码
e.g. vi
执行 sudo vi /etc/vim/vimrc
加入以下配置参数
let &termencoding=&encoding
set fileencodings=utf-8,gb18030,gbk,gb2312,big5
e.g. gedit
见上面的
ubuntu 安装 curl & php curl 模块
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
Install RabbitVCS on Ubuntu 12.04
Posted by richard on June 9, 2012
RabbitVCS is a set of graphical tools for accessing the version control software that you use. It supports Subversion and git and is similar to TortoiseVCS found on Windows.
Ubuntu 12.04 provides RabbitVCS in the standard repositories but this is version 0.13 which does not have support for GNOME 3 and so does not provide nautilus integration or gEdit integration.
In order to install the later 0.15 version of RabbitVCS you will need to add the RabbitVCS ppa. To do this add the following repositories:
deb http://ppa.launchpad.net/rabbitvcs/ppa/ubuntu precise main
deb-src http://ppa.launchpad.net/rabbitvcs/ppa/ubuntu precise main
Either by editing your /etc/apt/sources.list file directly or using a graphical tool such as Synaptic or Ubuntu Software Center.
Reload the changes and install packages rabbitvcs-core, rabbitvcs-cli, rabbitvcs-nautilus3 and rabbitvcs-gedit. You will need to log out and in again for the changes to take effect.sudo rm -rf /var/lib/dpkg/lock
删除flashplugin-installer之后,然后使用上面提供的方法重新安装。
--------------------
eclipse 定位到当前打开的文件
不知道为什么PDT 打开类之后,从文件中转向到其他的类文件中 package exploer不会自动定位到该文件,
Package Explorer的右上角有一个双向箭头图标,按下这个图标后,你在Editor打开任何文件,
Package Explorer就会自动定位到这个文件。
eclipse subclipse 插件禁用中文界面的方法,它的中文界面实在太烂了
打开eclipse\configuration\config.ini文件,在最后添加一句:osgi.nl=en_US
在Ubuntu 12.04 下, eclipse 安装 svn插件一般会遇到两个问题:
1)Failed to load JavaHL Library.
These are the errors that were encountered:
no libsvnjavahl-1 in java.library.path
no svnjavahl-1 in java.library.path
no svnjavahl in java.library.path
java.library.path = /usr/lib/jni
这里有官方的解决这个问题的指导:http://subclipse.tigris.org/wiki/JavaHL
按照以前的装法
1、sudo apt-get install libsvn-java
该命令会产生libsvnjavahl-1.so文件。
(64位操作系统该文件在/usr/lib/x86_64-linux-gnu/jni/目录下,如果是32位操作体系则在/usr/lib/i386-linux-gnu/jni/目录下。
2、eclipse.ini中增加参数(该文件在eclipse目录中)
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Djava.library.path=/usr/lib/jni
其实eclipse默认使用的library path就是/usr/lib/jni目录,该目录下还有其他java native的实现。所以不能为了解决subclipse的问题,而修改-Djava.library.path的值,应该把需要的文件软链接到默认的library path下(即/usr/lib/jni下)。所以请按照第三步来做。
3、把libsvnjavahl-1.so文件软链接到/usr/lib/jni下
64位操作系统请用这个命令:
sudo ln -s /usr/lib/x86_64-linux-gnu/jni/libsvnjavahl-1.so /usr/lib/jni/libsvnjavahl-1.so
32位操作系统请用这个命令:
sudo ln -s /usr/lib/i386-linux-gnu/jni/libsvnjavahl-1.so /usr/lib/jni/libsvnjavahl-1.so
4、重启eclipse
2) ubuntu Incompatible JavaHL library loaded.? 1.7.x or later required
JavaHL 版本过低错误,Ubuntu 12.04中,通过 $ apt-get install libsvn-java 命令安装的版本是1.6.x
如果你的eclipse是3.7.2 默认安装的subclipse 是 1.8.x 版本的,他要求 JavaHL 是 1.7 以上。
所以需要你卸载掉 subclipse? 换成 1.6.x 版本。
或者 按装 subclipse版本
sudo add-apt-repository ppa:dominik-stadler/subversion-1.7
sudo apt-get update
sudo apt-get install libsvn-java
不过这样一来,安装的就是 svn1.7了 与之前的1.6的svn格式不同,有问题 纠结了
只能 sudo add-apt-repository -r ppa:dominik-stadler/subversion-1.7 删除这个源再装了 汗
在 eclipse 中卸载subclipse1.8.x这个插件,然后按装 http://subclipse.tigris.org/update_1.6.x/
搞定这些之后又发现一个很纠结的问题,创建项目时使用 svn 项目类型创建的PHP项目无法解析项目中存在的类与方法,不知道原因,最后只能先创建php项目,再使用 team来检出代码,此时就可以解析项目中存在的类与方法,不知道这是subclipse的bug还是PDT的bug。
关于 rabbitvcs 有个要吐槽的地方,在合并代码时,其界面上明确标志 如果对比的版本框留空则合并到最新的版本,但此处留空却什么都不合并,必须指定一系列的版本号,真纠结啊 有高手能解决么
Gambas 是一个linux下类似于 Windows 的 VB 的可视化快捷开发工具.
Gambas 操作及语法几乎和win下的VB一样..在 IDE 上面功能也十分的强.代码编辑器是我十分喜欢的.让人感到清爽,友好.支持高 亮,代码自动提示,等delphi和vb上常见的功能..而且在我们手工输入代码后,保留关键词会自动转为大写,并高亮.
强大的组件扩展功能.
gambas支持linux下常见的几种数据库的连接(mysql/postgresql/sqllite...没讲甲骨文.),并带有一个专门的数据库管理工具.
这个工具很爽,
sudo add-apt-repository ppa:nemh/gambas3
sudo apt-get update
sudo apt-get install gambas3
1 楼 vb2005xu 2012-12-16 发现了一个问题 ubuntu 12.04 频繁假死 这个问题咋办??? 2 楼 vvvpig 2012-12-17 也是经常在Ubuntu12.04遇到假死,默认Unity桌面Bug一堆换个桌面环境试试,比如XUbuntu或者Kubuntu 3 楼 cxh116 2012-12-17 无力吐槽,一个ubuntu系统,RPM(Redhat Package Manager)都来了 4 楼 vb2005xu 昨天 打算使用 lxde http://www.lxde.org/zh-tw/lxde