Nginx  +PHP部署一

Alvin.zeng

目录

一、安装PHP

1、Yum安装需要的包

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers mysql-devel libevent-devel

2、编译gd和libiconv

官方网站GD

http://www.libgd.org/releases/gd-2.0.35.tar.bz2

#:tar–xvfgd-2.0.35.tar.bz2–C /opt/

#:cd /opt/gd-2.0.35

#:./configure  --prefix=/usr/local/gd2

#: make && make install

需要make两次,第一次会出错,

编译libiconv

#: tar–xvflibiconv-1.13.1.tar.gz

#: cdlibiconv-1.13.1

#:./configure --prefix=/usr/local/libiconv

#: make && make install

3、编译PHP5.3.3

官方网站

http://cn.php.net/distributions/php-5.3.3.tar.gz

#:rpm -vih libmcrypt-2.5.8-4.el5.centos.x86_64.rpm

#:rpm -vih libmcrypt-devel-2.5.8-4.el5.centos.x86_64.rpm

#: tar–xvfphp-5.3.3.tar.gz–C /opt/

#:cd /opt/php-5.3.3

#:./configure --prefix=/usr/local/php5.3 --enable-fpm --with-mysql --with-iconv=/usr/local/libiconv/ --with-pdo-mysql --with-mysqli --with-fpm-user --with-config-file-path=/etc --disable-sqlite3 --enable-soap --with-zlib --enable-xml --with-gd=/usr/local/gd2  --enable-mbstring --enable-mcrypt --enable-mbstring --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --with-mcrypt

#: make && make install

错误:configure: error: mysql configure failed. Please check config.log for more information.

解决:export LDFLAGS=-L/usr/lib64/mysql/指定一下64位环境变量,默认是找32位的。

4、编译eaccelerator和编译xhprof和Client-phpredis

官方网站

http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2

#:tar–xvfeaccelerator-0.9.6.1.tar.bz2–C /opt/

#: cd /opt/eaccelerator-0.9.6.1

#:/usr/local/php5.3/bin/phpize运此命令生成configure文件

#:./configure --prefix=/usr/local/eaccelerator --with-php-config=/usr/local/php5.3/bin/php-config --enable-eaccelerator

#: make && make install

官方网站

http://pecl.php.net/get/xhprof

#:tar–xvfxhprof-0.9.2.tar.gz–C /opt/

#:cd/opt/xhprof-0.9.2/extension

#:/usr/local/php5.3/bin/phpize运此命令生成configure文件

#: ./configure--with-php-config=/usr/local/php5.3/bin/php-config

#: make && make install

官方网站,

http://download.github.com/owlient-phpredis-2.0.8-0-g0c0409a.tar.gz

#:tar–xvfowlient-phpredis-2.0.8-0-g0c0409a.tar.gz/opt/

#: cdowlient-phpredis-2.0.8-0-g0c0409

#:/usr/local/php5.3/bin/phpize运此命令生成configure文件

#: ./configure--with-php-config=/usr/local/php5.3/bin/php-config

#: make && make install

5、配置PHP

(1)、拷贝库

#:cd /usr/local/php5.3/lib/php/extensions/no-debug-non-zts-20090626/

#:cp eaccelerator.soxhprof.so  /usr/local/php5.3/lib/php/extensions/

(2)、创建PHP用户

#:groupadd php

#:useradd–g php php

#:chgrp–R php /usr/local/php5.3

(3)、拷贝PHP.ini

#:cp php.ini /etc/

将PHP这两个功能打开

extension = "xhprof.so"

extension = "eaccelerator.so"

[xhprof]

xhprof.output_dir=/tmp/xhprof

[eAccelerator]

;extension="eaccelerator.so"

eaccelerator.shm_size="16"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

(4)、拷贝fpm配置文件

#:cp /usr/local/php5.3/etc/php-fpm.conf.default/usr/local/php5.3/etc/php-fpm.conf

(5)、修改fpm配置文件

# cat /usr/local/php5.3/etc/php-fpm.conf | grep -v ";"

[global]

[www]

listen = 127.0.0.1:9000

user = php

group = php

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

6、启动PHP

#:cd /usr/local/php5.3/sbin/

# ./php-fpm

#: ps–ef | grep php

# ps -ef | grep php

root     14104 24282  0 22:43 pts/1    00:00:00 grep php

root     27635     1  0 20:54 ?        00:00:00 ./php-fpm

php      27636 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27637 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27638 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27639 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27640 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27641 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27642 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27643 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27644 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27645 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27646 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27647 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27648 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27649 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27650 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27651 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27652 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27653 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27654 27635  0 20:54 ?        00:00:00 ./php-fpm

php      27655 27635  0 20:54 ?        00:00:00 ./php-fpm

二、安装Nginx

1、创建用户,建立网站数据目录

#:groupadd  www

#:useradd–g www www

#:mkdir–p /data/htdocs/zeng

#:mkdir–p /data/htdocs/yong

#:chown + w /data/htdocs/zeng

#:chwon +w /data/htdocs/yong

#:chown–R www:www /data/htdocs/zeng

#:chwon–R www:www /data/htdocs/yong

2、编译pcre-8.10稳定版

官方网站

下载ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz

#:tar–xvf pcre-8.10–C /opt/

#:cd /opt/pcre-8.10

#:./configure     注意不要指定路经,否则下面Nginx会编译出错

#:make && make install

3、编译nginx-0.8.51稳定版

官方网站下载

下载http://nginx.org/download/nginx-0.8.52.tar.gz

#:tar–xvf nginx-0.8.52.tar.gz–C /opt/

#:cd /opt/ nginx-0.8.52

#:./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

#:make && make install

4、创建日志目录

#:mkdir–p /nginxlog/logs

#:chmod +w /nginxlog/logs

#:chown–R www:www /nginxlog/logs

5、编辑Nginx配置文件

#:vi/usr/local/nginx/confuser  www www;

worker_processes8;#:启动8个进程

error_log  /nginxlog/logs/nginx_error.log  crit;#:日志文件路径

pid        /usr/local/nginx/nginx.pid;#:pid文件路经

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 65535;#:连接数量65535

events

{

use epoll;

worker_connections 65535;#:连接数量65535

}

http

{

include       mime.types;

default_type  application/octet-stream;

#charset  gb2312;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

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 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

#limit_zone  crawler  $binary_remote_addr  10m;

server

{

listen       80;#:监听端口80

server_name  www.yong.com;#:网站域名

index index.html index.htm index.php;

root  /data0/htdocs/blog;#:网站数据聚路径

#limit_conn   crawler  20;

location ~ .*\.(php|php5)?$

{

#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)$

{

expires      30d;

}

location ~ .*\.(js|css)?$

{

expires      1h;

}

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  /data1/logs/access.log  access;

}

server

{

listen       80;#:监听端口

server_name  www.zeng.com;#:网站域名

index index.html index.htm index.php;#:主页格式

root  /data0/htdocs/www;#:网站数据存放路径

location ~ .*\.(php|php5)?$

{

#fastcgi_pass  unix:/tmp/php-cgi.sock;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';

access_log  /data1/logs/wwwlogs.log  wwwlogs;#:数据日志存放路径

}

server

{

listen  80;

server_name  status.blog.s135.com;

location / {

stub_status on;

access_log   off;

}

}

}

6、新建fcgi配置文件

#vi/usr/local/nginx/conf/fcgi.conf

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;

7、优化Linux内核参数

#:vi /etc/sysctl.conf 在文件末尾增加

#:/sbin/sysctl –p可立即生效

# Add

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog =  32768

net.core.somaxconn = 32768

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1

#net.ipv4.tcp_tw_len = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024  65535

8、启动Nginx

检查配置文件是否正确,

#:/usr/local/nginx/sbin/nginx –t

启动

#:/usr/local/nginx/sbin/nginx

8.0X版本,重起

#:/usr/local/nginx/sbin/nginx–sreload

9、每写每天定时切割Nginx日志的脚本

#:vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

#!/bin/bash

# This script run at 00:00

# The Nginx logs path

logs_path="/usr/local/webserver/nginx/logs/"

Cutlog(){

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log

kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

}

Main()

{

Cutlog

}

#:Main

Main

设置crontab,每天凌晨00:00切割nginx访问日志

crontab -e

00 00 * * * /bin/bash  /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

nginx php iconv,Nginx +PHP部署一相关推荐

  1. windows下nginx+tomcat分布式集群部署

    首先官网下载  http://nginx.org/en/download.html,我的本地环境为 实现的架构: 从图上可以看出,nginx作为负载均衡请求分发器,当请求A应用时候,分发到A集群,同理 ...

  2. uwsgi模式_nginx+uwsgi 和nginx+gunicorn区别、如何部署

    [线上环境部署Django,nginx+uwsgi 和nginx+gunicorn,这两种方案,应该如何选择?] 大家是采用的何种部署方式? 第一种,高并发稳定一点 我们公司使用的是nginx+gun ...

  3. 若依前后端分离版本,Windows下使用Nginx代理的方式进行部署(全流程,图文教程)

    场景 若依官网: http://doc.ruoyi.vip/ 前提: 服务器上安装Mysql,并将数据库导入,在SpringBoot中的application-druid.yml配置mysql数据库连 ...

  4. docker启动nginx后挂了_Docker容器部署 Nginx服务

    1.查找 Docker Hub 上的 nginx 镜像 [root@localhost ~]# docker search nginx 2.拉取官方的Nginx镜像 [root@localhost ~ ...

  5. 容器化单页面应用中Nginx反向代理与Kubernetes部署

    在<容器化单页面应用中RESTful API的访问>一文中,我介绍了一个在容器化环境中单页面应用访问后端服务的完整案例.这里我将继续使用这个案例,介绍一下容器化单页面应用部署的另一个场景: ...

  6. Django 部署基础【使用 Nginx + uWSGI 的方式来部署来 Django】

    本文主要讲解在 Linux 平台下,使用 Nginx + uWSGI 的方式来部署来 Django,这是目前比较主流的方式.当然你也可以使用 Gunicorn 代替 uWSGI,不过原理都是类似的,弄 ...

  7. Jenkins+Github+Nginx实现前端项目自动部署

    Jenkins+Github+Nginx实现前端项目自动部署 前言 最近在搭建一个自己的网站,网站框架搭好了要把项目放到服务器运行,但是每次更新网站内容就要手动部署一次,实在很麻烦,于是就想搭建一套自 ...

  8. flask+uwsgi+supervisor+nginx在局域网服务器上部署实践

    flask可以快速的搭建http服务,但是为了搭建网站还是需要web服务器和相关监控管理操作,一套flask.uwsgi.supervisor.nginx是较好的完整解决方案. 本文对自己学习做一个记 ...

  9. 架构系列三:使用Keepalived+Nginx+tomcat实现集群部署

    架构系列三:使用Keepalived+Nginx+tomcat实现集群部署 介绍了通过Nginx配置Tomct集群,当其中一个Tomcat服务停止后,Nginx可自动识别并选择另一个服务器响应用户请求 ...

最新文章

  1. 你解决的问题比你编写的代码更重要!
  2. 快速排序的难点_数据结构考研重难点解析:快速排序
  3. 计算机算法设计与分析一
  4. [拓扑排序/强联通分量] [NOIP201402] 信息传递
  5. go mysql教学_Go语言之对Mysql简单操作
  6. php打印模板插件,smarty的插件功能是smarty模板的精华
  7. yii2 html编辑器,浅析Yii2集成富文本编辑器redactor实例教程
  8. Visual Studio 重新生成解决方案 无反映
  9. Ubuntu 下的根目录为
  10. jdk unsafe类源码解析
  11. 【BZOJ】【1010】【HNOI2008】玩具装箱Toy
  12. python逐行调试_python调试:pdb基本用法(转)
  13. python总结与思考_Python小结 – pip 升级包总结
  14. JVisualVM初步使用
  15. 太阳能发电与蓄电池研究(Matlab代码实现)
  16. 如果你觉得累,这三个“高内耗”行为,一定要戒掉!
  17. 传奇引擎注册服务器,GeeM2引擎架设传奇不能注册账号 进不去游戏
  18. js 详解es6 let TDZ(暂时性死区)
  19. 电脑连不上5GWiFi解决办法:更新驱动
  20. 安装及配置 Mac 上的 Rime 输入法——鼠鬚管 (Squirrel)(也适用于小狼豪)

热门文章

  1. Android之FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
  2. php gearmanclient addoptions,gearman PHP7扩展安装
  3. python mssql github_GitHub上最热门的开源项目都在这里了
  4. 仅凭借一本薄薄的时间简史,征服了全球读者...
  5. 一招教你舍友学会尤克里里 | 今日最佳
  6. java 注册驱动失败_java – JDBC驱动程序注册死锁?
  7. python string length_如何使用python获取字符串长度?哪些方法?
  8. java获取整点与凌晨的时间戳
  9. 班尼机器人维修方法_梅州市ABB机器人控制器维修中心
  10. hilbert曲线序编码matlab,Hilbert曲线扫描矩阵的生成算法及其MATLAB程序代码