新手搭建 nginx + php (LNMP)

配置源

纯净的Centos 6.5系统

配置163yum源 (这个比较简单,百度能解决很多问题)

开始

安装  开发软件包:yum  -y groupinstall  "Development Tools"

安装  mysql     : yum  -y install mysql mysql-server mysql-devel

下载  php-5.6.2   wgethttp://cn2.php.net/distributions/php-5.6.2.tar.gz

解压  tar -zxvf php-5.6.2.tar.gz

cd php-5.6.2
./configure \
 --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=mysqlnd \                  //这里mysqlnd 是内部查找命令
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl

出现未安装的错误,直接用yum 进行安装即可,不要忘了装上 -devel (libcurl libpng libcrul12等等)

make
make install

 

修改配置文件

cd php-5.6.2
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf

保存配置文件后,检验配置是否正确的方法为

/usr/local/php/sbin/php-fpm -t

如果出现诸如 “test is successful” 字样,说明配置没有问题

 

启动php-fpm

service php-fpm start

如果想让它开机启动,执行

chkconfig php-fpm on

检测是否启动

ps aux |grep php-fpm
netstat -ant |grep 9000

 

安装nginx

wget http://nginx.org/download/nginx-1.6.2.tar.gz                   //最新稳定版哦
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module  \
--with-pcre=/root/pcre-8.35        //很多人没讲这里,这里为pcre的解压目录。不过得先安装pcre

如果出错了,yum安装pcre-devel。如果yum安装不了,就到官网上自行下载源码包,然后解压安装。

make
make install

添加一个nginx主程序的符号链接

ln -sf /usr/local/nginx/sbin/nginx /usr/sbin/nginx
nginx -t      //测试一下吧

 

nginx配置

把原来的配置文件清空

> /usr/local/nginx/conf/nginx.conf

“>”这个符号为重定向的意思,单独用它,可以把一个文本文档快速清空。

编辑nginx.conf

vi /usr/local/nginx/conf/nginx.conf

插入以下内容

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
 
events
{
    use epoll;
    worker_connections 6000;
}
 
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;
 
server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;
 
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.19000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}

 

测试是否解析php文件

创建测试文件

vi /usr/local/nginx/html/1.php

插入以下内容

<?php
    echo "测试php解析";
?>

测试

curl localhost/1.php

 

posted @ 2015-01-21 10:26  Ev_zhk  阅读(379)  评论(0编辑  收藏  举报