都说Nginx比Apache性能优越,一直没有时间装测试,今天终于有时间装上试试性能了,其实Nginx的安装非常简单,具体流水步骤记录如下:

1.系统环境:
==================================
CENTOS 5.4或5.5 bit64
NGINX 1.1.5
PHP 5.3.8
############################################
#yum 安装系统环境所需要的软件包

yum -y install yum-fastestmirror ntp

yum -y install patch make flex bison tar

yum -y install libtool libtool-libs kernel-devel 

yum -y install libjpeg libjpeg-devel libpng libpng-devel

yum -y install libtiff libtiff-devel gettext gettext-devel

yum -y install libxml2 libxml2-devel zlib-devel  net-snmp

yum -y install file glib2 glib2-devel bzip2 diff* openldap-devel

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 unzip

# 安装PHP支持GD库模块

yum -y install freetype freetype-devel png jpeg zlib gd php-gd*

# 安装PHP 5.* 组件

yum -y install libiconv libevent mhash mcrypt

# 安装MYDSQL所需要系统库相关库文件

yum install -y gcc gcc-c++ gcc-g77 autoconf automake  fiex* ncurses-devel libmcrypt* libtool-ltdl-devel*

# 安装NGINX 组件

yum -y install pcre*



2. 软件下载

======================

PHP: wget -c http://www.php.net/get/php-5.3.8.tar.bz2/from/ar.php.net/mirror

NGINX: wget -c http://nginx.org/download/nginx-1.1.5.tar.gz



3. 软件安装

======================

(1) PHP 安装

php和nginx的整合是通过php-FastCGI

FastCGI 是一个可伸缩、高速的在web server和脚本语言间通迅的接口。被许多脚本语言所支持,包括 php多数流行的web server都支持 FastCGI。

 正常情况下,nginx和php直接是完全不认识的,我们就是通过php-fastcgi将二者整合。

php5.3.0之前的版本,php-FastCGI 是需要单独安装的。但是在这之后,php-FastCGI 就整合在了php的源码包中,不必再去单独安装。在这里我用的就是php5.3.8的版本,内置了php-fpm ,编译时开启,并且编译后存在
php-cgi 文件了。

注意:PHP编译支持php-fpm功能就不能编译支持apache的apxs模块功能,不然报错。

# tar jxf php-5.3.8.tar.bz2 && cd php-5.3.8

# ./configure --prefix=/u/php5 --with-config-file-path=/u/php5/lib --with-oci8=instantclient,/usr/local/instantclient --with-mysql=mysqlnd --with-libxml-dir --enable-ftp --enable-sockets --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib-dir
--enable-gd-native-ttf --enable-magic-quotes --with-iconv --enable-mbstring=all --disable-cgi --with-openssl --with-mcrypt --enable-bcmath --enable-calendar --enable-exif --enable-libxml --with-bz2 --with-curl --with-xmlrpc --with-gettext --disable-cli  --disable-debug 
--enable-zend-multibyte --with-mhash --enable-pcntl --enable-sysvsem --enable-inline-optimization --enable-soap --disable-ipv6 --enable-fpm

# make

# make install

# cp php.ini-development /u/php5/lib/php.ini

编译完成后,在PHP的编译安装目录中,会看到如下目录结构:



etc目录:php-fpm.conf.default文件

sbin目录:php-fpm执行文件

# cd  /u/php5/etc/  # 切换到安装目录下的配置文件目录

# cp  php-fpm.conf.default  php-fpm.conf

# vi php-fpm.conf 

启用如下几行,即去掉前面的分号(;)

    pid = run/php-fpm.pid

    error_log = log/php-fpm.log

    log_level = notice

    listen = 127.0.0.1:9000

    listen.allowed_clients = 127.0.0.1

    pm = dynamic

    pm.max_children = 50

    pm.start_servers = 5

    pm.min_spare_servers = 5

    pm.max_spare_servers = 35

    pm.max_requests = 500

    env[HOSTNAME] = $HOSTNAME

    env[PATH] = /usr/local/bin:/usr/bin:/bin

    env[TMP] = /tmp

    env[TMPDIR] = /tmp

    env[TEMP] = /tmp



wq保存退出



# /u/php5/sbin/php-fpm (启动PHP)

# netstat -antpl (如果看到9000端口,PHP-FPM配置成功)



(2) NGINX 安装

==================================

# tar zxf nginx-1.1.5.tar.gz && cd nginx-1.1.5

# ./configure --prefix=/u/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --http-client-body-temp-path=/tmp/nginx_client --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi 
--http-uwsgi-temp-path=/tmp/nginx/uwsgi --http-scgi-temp-path=/tmp/nginx/scgi

或者根据官方网站提供的配置编译

# ./configure \

  --prefix=/u/nginx \

  --sbin-path=/u/nginx/sbin \

  --conf-path=/u/nginx/nginx.conf \

  --pid-path=/tmp/nginx/nginx.pid  \

  --lock-path=/tmp/nginx/nginx.lock \

  --user=nginx \

  --group=nginx \

  --with-pcre \

  --http_rewrite_module \ #支持路径重新,需要pcre模块支持

  --http_gzip_module \    #启用gzip压缩,需要zlib包支持

  --with-http_ssl_module \

  --with-http_flv_module \

  --with-http_stub_status_module \

  --with-http_gzip_static_module \

  --error-log-path=/u/nginx/logs/error.log \

  --http-log-path=/u/nginx/logs/access.log \

  --http-client-body-temp-path=/tmp/nginx/client/ \ #HTTP客户端请求的主体的临时文件的路径

  --http-proxy-temp-path=/tmp/nginx/proxy/ \        #HTTP代理临时文件的路径

  --http-fastcgi-temp-path=/tmp/nginx/fcgi/ \       #HTTP FastCGI的临时文件的路径

  --http-uwsgi-temp-path=/tmp/nginx/uwsgi/ \

  --http-scgi-temp-path=/tmp/nginx/scgi/

#make

# make install

+++++++++++++++++++++++++

NGINX 配置文件设置:这个配置只是让NGX和PHP关联起来,更多配置只好GG了。

+++++++++++++++++++++++++

user  nginx nginx ; (nginx 用户需要新建,注释掉也OK的)

worker_processes  8;



error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;



pid        logs/nginx.pid;



events {

    worker_connections  2048;

}



http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  127.0.0.1



        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

         #  include        fastcgi_params;

            include        fastcgi.conf;

        }



}

在/u/nginx/html 中编写Index.php文件

<?php

phpinfo();

?>

打开浏览器 http://IP/index.php,能浏览恭喜你,安装成功了。

CentOS+Nginx+PHP 前端部署的更多相关文章

  1. Centos+Nginx+NetCore3.1

    Centos+Nginx+NetCore3.1部署 1 先将vs2019升级到,16.4.0版本 2.新建一.netcore3.1的web程序 3.编译后将项目上传到centos服务器 4.配置ngi ...

  2. CentOS 下用 Nginx 和 uwsgi 部署 flask 项目

    前几天利用flask 写了几个调用salt-api 的接口,需要上线到正式环境,搜了一下 都是 用 nginx + uwsgi 来部署,这里记录下关键的配置项. 1.首先将代码上传到服务器上目录为: ...

  3. 前端部署: nginx配置

    前提:nginx 已安装 简介:nginx(engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Ram ...

  4. ubuntu下nginx+php5的部署

    ubuntu下nginx+php5环境的部署和centos系统下的部署稍有不同,废话不多说,以下为操作记录:1)nginx安装root@ubuntutest01-KVM:~# sudo apt-get ...

  5. linux下nginx负载均衡部署

    nginx负载均衡部署 Nginx("engine x") 是一个高性能的 HTTP 和 反向代理 server,也是一个 IMAP/POP3/SMTP 代理server. Ngi ...

  6. Keepalived+Nginx提供前端负载均衡+主从双机热备+自动切换

    原文链接:http://unun.in/linux/156.html 方案: 采用两台Nginx服务器作为前端,提供静态web内容,分发web请求,一主一从,Keepalived实现状态监测,保证 N ...

  7. CentOS 6.5安装部署Zabbix监控系统

    CentOS 6.5安装部署Zabbix监控系统 先说一点废话,我没有用centos7做实验,讲真,centos 7我也不常用,喜欢新版本的同学其实可以尝试下,注意一点的就是centos 6.5只支持 ...

  8. Nginx详细安装部署教程

    一.Nginx简介 Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,具体简介我就不介绍了百度一下有很多,下面直接进入安装步骤 二.Nginx安装 1.下载N ...

  9. .NET Core+MySql+Nginx 容器化部署

    .NET Core容器化@Docker .NET Core容器化之多容器应用部署@Docker-Compose .NET Core+MySql+Nginx 容器化部署 GitHub-Demo:Dock ...

随机推荐

  1. ruia笔记

    ruia笔记 loop = loop or asyncio.new_event_loop() get_event_loop()方法仅在同样的线程中生效,如果在一个新线程中,应该用new_event_l ...

  2. 读SRE Google运维解密有感(三)

    前言 这是读“SRE Google运维解密”有感第三篇,之前的文章可访问www.addops.cn来查看.我们今天来聊聊“on call”也就是运维值班制度, 本人到目前为止也还在参与一线运维的值班, ...

  3. 利用mycat实现基于mysql5.5主从复制的读写分离

    整体步骤: 1.准备好两台服务器,一台作为主数据库服务器,一台作为从服务器,并安装好mysql数据库,此处略 2.配置好主从同步 3.下载JDK配置mycat依赖的JAVA环境,mycat采用java ...

  4. CentOS 6.3下NFS安装配置

    CentOS 6.3下NFS安装配置 一.环境介绍   NFS服务器:CentOS6.3 192.168.8.20 NFS客户端:CentOS6.5 192.168.8.39 二.服务器端安装配置   ...

  5. Android通讯:通话

    Android通讯之通话功能的实现: 在Android中,android.telephony.TelephonyManager对象是开发者获取当前通话网络相关信息的窗口,通过TelephonyMana ...

  6. JOptionPane类提示框常用方法总结

    JOptionPane类封装了很多的方法,总结如下: 1.showMessageDialog 显示一个带有OK 按钮的模态对话框. 下面是几个使用showMessageDialog 的例子: Java ...

  7. Android动态控制状态栏显示和隐藏

    记得之前有朋友在留言里让我写一篇关于沉浸式状态栏的文章,正巧我确实有这个打算,那么本篇就给大家带来一次沉浸式状态栏的微技巧讲解. 其实说到沉浸式状态栏这个名字我也是感到很无奈,真不知道这种叫法是谁先发 ...

  8. three.js 相机camera位置属性设置详解

    开始很懵逼,完全不能理解,有个position,还要up和lookAt干嘛. [黑人问号脸❓❓❓] 既然是位置属性不明白,那默认其它属性都懂了. 上坐标轴: 先来第一个position属性,可以设置x ...

  9. [转]Hadoop参数汇总

    出自:https://segmentfault.com/a/1190000000709725 Hadoop参数大全 主要配置文件: core hdfs yarn mapred 重要性表示如下: 重要 ...

  10. LeetCode(43):字符串相乘

    Medium! 题目描述: 给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式. 示例 1: 输入: num1 = &quo ...