rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 应用技术 » Web服务器

安装nginx、php和mysql

安装Nginx

Nginx版本是最新稳定版本0.7.61,我一般都从rashost.com上下载,地址是http://dl.rashost.com/centos5-i386/。

wget http://dl.rashost.com/centos5-i386/nginx-0.7.61-1.i386.rpm
rpm -ivh nginx-0.7*.rpm
chkconfig nginx on
/etc/init.d/nginx start

安装MySQL

yum install -y mysql-server
chkconfig –list mysqld
chkconfig mysqld on
/etc/init.d/mysqld start

安装好以后,可以使用mysqladmin -u root password ‘new-password’修改默认的空密码。

安装php & php-fpm

先安装php & php-fpm所依赖的一些库文件,然后到http://dl.rashost.com/centos5-i386/下载编译好的php-fpm,并安装:

yum install -y libmhash libmcrypt libtool-ltdl libpng libjpeg curl
wget http://dl.rashost.com/centos5-i386/php-fpm-5.2.10-i386.tar.gz
tar -zxf php-fpm-5.2.10-i386.tar.gz
mv php /opt/
/opt/php/sbin/php-fpm start

然后编辑/etc/rc.local,在其中加入

/opt/php/sbin/php-fpm start

自此,nginx、php和mysql的所有程序都安装好了。可以把上面所有命令都放到shell脚本里,就可以一键安装所有程序了。

博客导读网 一个让你随便看看的地方
nginx.conf - nginx配置文件说明 记录人生轨迹,寻找人生航向!
 

user www www;

#指令指定处理进程的数量。一般推荐为处理器的个数. 可以适当增加,以避免进程在堵塞在IO等待中。
worker_processes 8;

#错误日志
error_log logs/error.log;

#pid文件位置
pid logs/nginx.pid;

events {
#指定 nginx 处理进程的个数,其与总处理量的关系用公式表达如下:
#MaxClient = worker_processes * worker_connections
#因此这两个数的乘积若大于系统最大可用tcp/ip栈数是没有意义的.
worker_connections 1024;
}

#HTTP 请求设置
http {
#载入mime类型
include mime.types; default_type application/octet-stream;

#日志的格式,可能自定义,下面定义了一个格式的模板,名称叫httpslogs

log_format   httpslogs   '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
       '"$http_user_agent" $http_x_forwarded_for';

#记录访问日志,日志格式就使用上面定义的日志格式模板httpslogs,日志文件名为access.log
access_log logs/access.log   httpslogs;

#sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
#对于普通应用,必须设为 on。
#如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络IO处理速度,降低系统 uptime。
sendfile on;

tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

#服务器设置
server { listen 80;

#WEB服务主机名
server_name localhost;

#charset utf-8;

#访问日志
access_log logs/localhost.access.log main;

#请求规则 默认请求
location / {
#WEB根目录
root /home/www/www; index index.html index.htm index.php;
}

#页面不存在处理
error_page 404 /404.html;

#服务器错误定向
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/www/www; #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
location ~ \.php$ {
root /home/www/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
include fastcgi_params;
}

#禁止访问 .htxxx 文件
location ~ /\.ht {
deny all; }
}

顶一下
(0)
踩一下
(0)