本来想在Ubuntu Server 10.04用LAMP的,但是服务器配置较低,前辈推荐用nginx, 下篇再写LAMP吧。
之所以用nginx没用apache,是因为nginx的效率更高一些,尤其是对一些低配置的服务器
1、安装ubuntu server 10.04,其中安装语言选的en,时区chongqing,服务只安装ssh,其他全部用默认就行。
提示:以上安装过程完成后,建议用其他计算机登录服务器,windows系统可以用putty,linux系统直接在终端用命令就可以:
代码:ssh 登录名@服务器ip
因为以下过程得输入大量命令和代码,在客户机上直接粘贴即可(在windows下的putty中单击右键即可把剪贴板中的内容粘贴到终端)。
2、添加源:
代码:sudo vi /etc/apt/sources.list
添加如下:
代码:deb lucid main restricted universe multiverse
deb lucid-security main restricted universe multiverse
deb lucid-updates main restricted universe multiverse
deb lucid-backports main restricted universe multiverse
deb-src lucid main restricted universe multiverse
deb-src lucid-security main restricted universe multiverse
deb-src lucid-updates main restricted universe multiverse
deb-src lucid-backports main restricted universe multiverse
deb hardy main
注:最后一行是最新版nginx的源(目前是0.8.36)。
3、更新
代码:sudo apt-get update
4、安装网站系统
代码:sudo apt-get install MySQL-server mysql-client nginx php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-common php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl spawn-fcgi
5、设置开机启动fastcgi进程
代码:sudo vi /etc/rc.local
在exit 0这一行前面添加下一行
代码:/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -C 4 -P /var/run/fastcgi-php.pid
6、创建网站、日志目录(我的网站个人目录是ubuntu,以下命令用你的个人目录替换其中的ubuntu即可)
代码:mkdir /home/ubuntu/www -p
mkdir /home/ubuntu/log -p
ln -s /usr/share/phpmyadmin /home/ubuntu/www/phpmyadmin
7、配置nginx
代码:sudo vi /etc/nginx/nginx.conf
具体配置网上可以搜到,我的配置:
代码:user www-data;
worker_processes 2;
error_log /dev/null crit;
pid /var/run/nginx.pid;
events {
worker_connections 3000;
}
http {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/css text/xml text/plain application/x-Javascript application/xml application/pdf application/x-perl application/x-tcl application/msword application/rtf application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.wap.xhtml+xml image/x-ms-bmp;
gzip_disable "MSIE [1-6] \.";
gzip_vary on;
output_buffers 4 32k;
client_max_body_size 20m;
server {
listen 80;
server_name localhost;
charset utf-8,gb2312;
access_log /home/ubuntu/log/access.log;
location / {
root /home/ubuntu/www;
index index.html index.htm index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
set $path_info "/";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|ico)$ {
root /home/ubuntu/www;
access_log off;
expires 30d;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/ubuntu/www;
}
fastcgi_param SCRIPT_FILENAME /home/ubuntu/www/$real_script_name;
fastcgi_param path_info $path_info;
include /etc/nginx/fastcgi_params;
}
}