Ubuntu 11.04 安装 Nginx+PHP 5+MySQL的Web服务器
Nginx是一款有俄罗斯人开发的轻量级的web 服务器软件,现在很多网站都在使用这款软件,包括国内的互联网巨头腾讯网站都在使用Nginx。这款软件优点,免费、开源、高性能,而且稳定、功能强大、配置简单、资源消耗小。通过 PHP-FPM在Ubuntu 11.04中支持 php5和mysql。
好了,不多说了,现在开始安装。
1.初步说明
首先所有的步骤使用root,先切换到root用户,终端输入命令:
sudo su
2.安装MySQL 5.0,在终端输入:
apt-get install mysql-server mysql-client
安装过程中会让你输入根用户密码两次。
3.安装Nginxapt-get install nginx
启动nginx命令:/etc/init.d/nginx start
如果你的IP是192.168.0.100在终端输入查看nginx是否正常运行.
提示:在Ubuntu 11.04中Nginx 默认网站目录为
/usr/share/nginx/www
4.安装PHP5apt-get install php5-fpm
PHP – FPM是一个守护进程(与初始化脚本 / etc/init.d/php5-fpm )运行FastCGI服务器上的端口 9000 。
5.nginx的配置
配置文件/etc/nginx/nginx.conf<font face="Courier New">vi /etc/nginx/nginx.conf</font>
增加工作进程,可选,可以不修改
worker_processes 5;
keepalive_timeout 2;
默认虚拟主机配置文件地址/etc/nginx/sites-available/default<font face="Courier New">vi /etc/nginx/sites-available/default</font>
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6root /usr/share/nginx/www;
index index.php index.html index.htm;# Make site accessible from http://localhost/
server_name _;location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
}location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}location /images {
root /usr/share;
autoindex off;
}#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 /usr/share/nginx/www;
}# 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;
include fastcgi_params;
}# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}
}