nginx-1.8.1+php-5.6.20 安装部署

1.安装依赖文件

yum install pcre pcre-devel openssl openssl-devel -y

 2.安装nginx及健康检测模块

useradd -s /sbin/nologin -M nginx
cd /usr/local/src
wget http://nginx.org/download/nginx-1.8.1.tar.gz
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
tar -zxvf nginx-1.8.1.tar.gz
unzip master
cd nginx-1.8.1
patch -p1 < ../nginx_upstream_check_module-master/check_1.7.5+.patch 
./configure --prefix=/usr/local/nginx-1.8.1 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx_upstream_check_module-master/
make
make install
ln -s /usr/local/nginx-1.8.1/ /usr/local/nginx
/usr/local/nginx/sbin/nginx

 3.安装阿里云里epel源

cd /usr/local/src/
wget http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm

 4.安装php依赖软件

yum install zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel libmcrypt-devel mhash mhash-devel mcrypt openssl-devel libcurl-devel libjpeg-turbo-devel libtool-ltdl-devel -y

 5.安装libiconv软件

cd /usr/local/src
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install

 6.下载php软件

cd /usr/local/src
wget http://mirrors.sohu.com/php/php-5.6.20.tar.gz
tar -zxvf php-5.6.20.tar.gz
cd php-5.6.20

7.1编译php方式一: (本地安装了MySQL)

本地安装了mysql需要让及动态库生效

echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
./configure --prefix=/usr/local/php-5.6.20 \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mysql=/usr/local/mysql \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--with-curl \
--enable-fpm \
--enable-xml \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-static \
--with-xsl \
--enable-ftp \
--with-gettext \
--enable-bcmath \
--enable-opcache

make && make install

7.2编译php方式二:(MySQL分离)

./configure --prefix=/usr/local/php-5.6.20 \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--with-curl \
--enable-fpm \
--enable-xml \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-static \
--with-xsl \
--enable-ftp \
--with-gettext \
--enable-bcmath \
--enable-opcache

make && make install

 8.配置文件

ln -s /usr/local/php-5.6.20/ /usr/local/php 
cp /usr/local/src/php-5.6.20/php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 9.配置nginx.conf

[root@web-node01 vhost]# vim ../nginx.conf

user nginx nginx;
worker_processes  4;
#worker_cpu_affinity 0101 1010;
worker_cpu_affinity 0001 0010 0100 1000;

#error_log  logs/error.log error;
#error_log  logs/info.log info;
pid        logs/nginx.pid;

worker_rlimit_nofile 51200;

#事件模型及最大连接数=worker*worker_processes
events {
        use epoll;
        worker_connections  5120;
}

http {

        include       mime.types;
        default_type  application/octet-stream;
        charset       utf-8;

        #关闭nginx版本号 
        server_tokens off;

        #日志格式--ok
        log_format access '$remote_addr - $remote_user [$time_local] "$request"'
                          '$status $bytes_sent "$http_referer"'
                          '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"'
                          #'"addr:$upstream_addr-status:$upstream_status- cachestatus:$upstream_cache_status"'
                          #'"KEY:$host$uri$is_args$args"';
        #access_log  logs/access.log  main;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 64k;
        client_max_body_size 300m;
        client_body_buffer_size 512;

        #提高网络传输效率--ok
        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     on;

        keepalive_timeout       65;
        client_header_timeout   60;
        client_body_timeout     60;
        send_timeout            60;

        #定义请求并发数
        #limit_conn_zone $binary_remote_addr zone=addr:10m;

        #定义请求频率,1M约能存储16000个ip,限制每秒请求为10个,
        #limit_req_zone $binary_remote_addr zone=one:10m rate=20r/s; 


        #反向代理缓存参数--ok
        #proxy_temp_path /tmp/cache/proxy_temp_dir;
        #proxy_cache_path /tmp/cache/proxy_cache_dir levels=1:2 keys_zone=pinhui_cache:200m inactive=3d max_size=10g;
        #proxy_cache_key "$scheme$request_method$host$request_uri";

        #反向代理参数
        proxy_ignore_client_abort  on;
        proxy_connect_timeout      60;
        proxy_read_timeout         60;
        proxy_send_timeout         60;
        proxy_buffer_size          64k;
        proxy_buffers              32 128k;
        proxy_busy_buffers_size    256k;
        proxy_temp_file_write_size 256k;
        proxy_next_upstream error timeout invalid_header http_502 http_504 http_404;

        #压缩参数--ok
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types text/css text/plain text/xml application/javascript;
        gzip_vary on;

        #fastcgi配置参数
        #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;
        #fastcgi_cache pinhui_cache;
        #fastcgi_cache_valid 200 302 1h;
        #fastcgi_cache_valid 301 1d;
        #fastcgi_cache_valid any 1m;
        #fastcgi_cache_min_uses 1;

        #配置文件包含--ok
        include vhost/*.conf;

                #禁止IP地址直接访问--ok
                #server {
                #listen 80 default_server;
                #server_name _;
                #return 403;
                #}
}

10.配置虚拟主机

[root@web-node01 vhost]# vim web.conf 


# web
server {
        listen 80;
        #charset utf-8;
        #charset GB2312;
        server_name 172.16.1.12:18201;

        root   html/web;
        index  index.php index.html;

        #PHP support                 # 关键部分
        location ~ .*\.(php|php5)?$ {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }

        #proxy ip
        location / {
                #proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #status
        location /status {
                stub_status on;
                access_log off;
                auth_basic "Nginx Status";
                #auth_basic_user_file /usr/local/nginx/conf/pinhui001.htpasswd;
        }

        #log file
         access_log  logs/web_access.log access;
}

 11.创建PHP环境

[root@web-node01 php-5.6.20]# cd /usr/local/nginx/html/
[root@web-node01 html]# mv index.html index.html.bak
[root@web-node01 html]# ll
total 8
-rw-r--r--. 1 root root 537 Aug 18 14:38 50x.html
-rw-r--r--. 1 root root 612 Aug 18 14:38 index.html.bak
[root@web-node01 html]# vim index.php
<?php
phpinfo();
?>

 12.测试PHP解析访问

13.测试PHP解析及MySQL连接

<?php
        date_default_timezone_set('PRC'); 
        $link = mysql_connect('172.16.1.33:32959','root','123456');
        if ($link)
          echo "Success...";
        else
          echo "Failure...";

        mysql_close();

        phpinfo();
?>

posted @ 2016-08-10 19:24  sunmmi  阅读(521)  评论(0编辑  收藏  举报