yum -y update
yum -y install patch make gcc gcc-c++ gcc-g77 flex bison
yum -y install libtool libtool-libs kernel-devel autoconf
yum -y install libjpeg libjpeg-devel libpng libpng-devel
yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel
yum -y install glib2 glib2-devel bzip2 diff*
yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
64位替换i386为x86_64
yum -y install mysql mysql-server mysql-devel
yum -y install php php-mysql php-cgi php-mbstring php-gd php-fastcgi php-pear php-pear-DB php-fpm php-cli php-pdo php-mcrypt php-tidy php-xml php-xmlrpc php-pecl-memcache php-eaccelerator
yum -y install nginx
所有的配置文件都在 /etc 目录
chkconfig mysqld on
chkconfig php-fpm on
chkconfig nginx on
service mysqld start
mysqladmin -u root password rootpassword
创建www用户和组,以及主机需要的目录,日志目录
groupadd www
useradd -g www www
mkdir -p /home/www
chmod +w /home/www
mkdir -p /home/www/logs
chmod 777 /home/www/logs
chown -R www:www /home/www vi /etc/nginx/nginx.conf
user www www; worker_processes 2; #这里根据你的CPU和内存配置, 设置2到10都OK
error_log /home/www/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
#charse gb2312; # 默认编码,可以不设置
server_names_hash_bucket_size 128;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_types text/plain text/javascript application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server {
listen 80;
server_name localhost;
root /home/www;
location /status {
stub_status on;
access_log off;
}
location / {
# 这里是把所有不存在的文件和目录,全都转到 index.php 处理
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# 这里分开放到 server.conf 是为了再开 server 的时候方便,统一调用,放到/etc/nginx/ 目录下
include server.conf;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /home/www/logs/access.log access;
}
server {
listen 80;
server_name yourdomain.com;
root /home/www/yourdomain;
if ($host !~* yourdomain.com$) {
return 444;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
include server.conf; # 这里复用了,这段就省了
access_log /home/www/logs/yourdomain.com_access.log access;
}
}
vi /etc/nginx/server.conf
index index.html index.htm index.php;
#limit_conn crawler 20;
location ~ /.ht {
deny all;
}
location ~ .*.(sqlite|sq3)$ {
deny all;
}
location ~ .*.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
expires 30d;
access_log off;
}
location ~ .*.(js|css)?$ {
expires 30d;
access_log off;
}
service php-fpm start
service nginx start
OK!
nginx测试
/usr/local/nginx/sbin/nginx -t
nginx平滑重启命令
/usr/local/nginx/sbin/nginx -s reload
Tags: mysql, nginx, php, yum