2009年3月18日星期三

D编程语言基本环境配置

我记录的是我自己的本机的配置,其它配置请看官网文档。
我用了一晚上的时间大概看了一些D的资料,开始时是手式编译,但因为版本较混乱,最终没有成功,最后找到一个已经编译好的DEB包,为了方便就直接下载到本地,使用dpkg安装。以下是我安装配置过程:

安装包和依赖关系:
mkdir ~/d/archive/ && cd ~/d/archive/
wget http://url/dmd_1.035-1_i386.deb
wget http://url/dsss_0.75-6_i386.deb
wget http://url/tango-dmd_099.7-1_i386.deb
wget http://url/dwt-linux-3.4-1.zip

说明:因为我要使用dwt,而它对dmd和tango的版本要求较为严格,所以我挑了两个较稳定的版本使用,dwt还需要以下几种依赖包:
  • XULRunner 1.8+ (for runtime embedded components)
  • XULRunner SDK 1.8+ (for linktime libraries)
  • libgtk2.0-dev
  • libxtst-dev
  • libgnomeui-dev
  • libstdc++5
XulRunner firefox安装时就已经装上了,此处只需安装XURRunner-dev.dmd需要libstdc++5版本支持,所以这个也要装上.

安装依赖关系:
apt-get install xulrunner-dev libgtk2.0-dev libxtst-dev libgnomeui-dev libstdc++5

安装包:
1.首先安装dmd:
dpkg -i dmd_1.035-1_i386.deb

2.接着安装Tango
dpkg -i tango-dmd_099.7-1_i386.deb

3.然后安装DSSS
dpkg -i dsss_0.75-6_i386.deb

4.解压缩dwt的zip包并利用dsss编译它,
dsss的默认配置时编译需要很长时间,所以需要修改一下配置文件中的一个参数:
修改/etc/rebuild/dmd-posix-tango,将oneatatime=yes全部改成no,速度会很快

unzip dwt-linux-3.4-1.zip
dsss build
dsss install

到此,D的基本配置就结束了,现在可以到网上找到示例,运行,试试看。
#!d
module main;

import dwt.widgets.Display;
import dwt.widgets.Shell;

void main ()
{
Display display = new Display;
Shell shell = new Shell(display);

shell.setText = "Hello DWT World";

shell.open;

while (!shell.isDisposed)
if (!display.readAndDispatch)
display.sleep;

display.dispose;
}

保存成为main.d,并在其同级目录下新建一个dsss配置文件"dsss.conf",内容为:"[main.d]"
运行dsss build,如果成功,会得到一个可执行的main二进制文件,运行它:
./main

2009年3月6日星期五

选定RasHost VPS服务

我的今年的计划是做一个网站,需要买空间,因为信用卡还在申请中,所以不能购买国外的很便宜的虚拟主机了,国内的又不行,已经用了三个了,都不满意。今天在看张宴的博客时,浏览服务器架构时一篇文章是讲他现在的服务器是买的国内的VPS,只是服务器在美国,我通过PING和nslookup 然后又whois终于得到他的购买的那家公司,RasHost VPS -瑞豪开源VPS,号称国内首家Linux/Xen VPS,服务器有河北,北京,美国三处机房。VPS,可以完全管理服务器,价钱也合适,支持多种支付方式,所以我决定了就选它了。注册完毕。
在这里作个广告,嘿嘿,如果你也想买的话,它的地址是:http://rashost.com

2009年3月3日星期二

使用Nginx以fastcgi方式跑cakephp

今天想试试nginx,就关掉apache,安装配置了一下nginx, 记录到此。我使用的系统是debian lenny,所以这些软件没有手动编译,直接使用apt安装nginx,php5的cgi版本、php5的mysql连接库、mysql数据库。

安装所需软件
apt-get install php5 php5-cgi php5-mysql nginx mysql-server-5.0
安装后,nginx的配置文件在/etc/nginx下,php的配置文件在/etc/php5/下。

安装cakephp
从cakephp网站下载最新版本,并解压到/var/www/cakephp/下,目录结构树像以下那样:
/var/www/cakephp/
app/
cake/
...
运行php-cgi
这些在网上都能找到教程,我就不说了。我使用的是lighttpd的spawn-fcgi,我的方法是:
apt-get install lighttpd
然后把/usr/bin/spawn-fcgi作个备份, cp /usr/bin/spawn-fcgi /usr/bin/spawn-fcgi.back
再删除lighttpd,因为我只是用它的spawn-fcgi
再把备份改会来: mv /usr/bin/spawn-fcgi.back /usr/bin/spawn-fcgi
运行以下命令,功能是:以www-data组的www-data用户运行php5-cgi,并绑定地址到127.0.0.1,端口绑定到9000,进程开5个。更详细的使用帮助请自行搜索网络上的教程:
spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi

配置nginx
复制/etc/nginx/sites-available/default到/etc/nginx/sites-available/cakephp
细节不在详述,请看我自己的配置文件:
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/cakephp.access.log;

location / {
root /var/www/cakephp/app/webroot;
index index.php index.html index.htm;

#If the file exists as a static file serve it
# directly without running all
# the other rewite tests on it
if (-f $request_filename) {
break;
}
if (!-f $request_filename){
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/cakephp/app/webroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
然后将其作个软连接到/etc/nginx/sites-enabled/中
ln -s /etc/nginx/sites-available/cakephp /etc/nginx/sites-enabled/
重新启动nginx: /etc/init.d/nginx restart


注:
"fastcgi_param SCRIPT_FILENAME /var/www/cakephp/app/webroot$fastcgi_script_name;"
这个地址是和虚拟地址一样的,如果使用$document_root,在我的机器上不能运行。
还要在/etc/php5/cgi/php.ini中开启cgi.fix_pathinfo=1,默认为注释掉的或是cgi.fix_pathinfo=0,要改过来。

配置文件中的那些重写是为了支持 cakephp的路由,在apache上可以使用.htaccess,而在nginx中重写就是上面配置文件中的那样,我在最后的地方配置成禁止读取.htaccess.

想了解nginx+php更详细的安装请看张宴的博客:http://blog.s135.com/read.php/314.htm

2008年12月17日星期三

War3 Online(网页版魔兽争霸3)

我喜欢玩游戏,其中玩的次数比较多的是War3,前段时间在家没有事做时,就看了一些竞赛视频,看完后也想自己演练一番,但因为使用的系统是linux, 所以就不能玩了,后来睡觉时觉得我可以利用web技术制作一个在线版,说干就干,当晚就做了一个很简单的页面demo。后期的工作量会很大,代码变动也会 很大,所以我刚才把它放到google code上了,地址是http://war3online.googlecode.com/。喜欢玩游戏的朋友,如果会写代码请一起来写吧!