Nginx+PHP安装(Debian6)

 

     Nginx 目前来说已经很流行了,所以打算把现有的Apache先替换一部分,在批量部署和管理方面都要考虑到。因为nginx的所有模块都是静态编译的不像apache那样可以动态添加模块,所以在一开始就要考虑清楚需求,结合现在很火的LAMP模式,其中P最常见的是PHP,目前较好的FastCGI的管理器有spaw-fcgi和php-fpm,而php老版本都是需要源码安装通过打补丁的方式把php-fpm打进去,spaw-fcgi是lighttpd默认的FastCGI管理器,因为牵扯到源码安装,当前的软件包版本在大规模部署起来不是很方便,但是还是有解决办法的。

    Nginx安装方法:

    1 apt网络安装

       修改源列表

vi /etc/apt/sources.list
#加入以下源
deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

        更新源列表并通过apt安装nginx

apt-key add nginx_signing.key
apt-get update
apt-get install nginx

    2 源码编译安装

       先安装编译环境, 由于nginx在以后的使用中会需要用到perl正则、压缩算法、SSL等特性,所以我们需要提前安装相关库文件。

apt-get install build-essential 
apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev libssl0.9.8

        下载最新的稳定版nginx

wget http://nginx.org/download/nginx-1.2.3.tar.gz

        解压查看编译选项

tar zxvf nginx-1.2.3.tar.gz
cd nginx-1.2.3
#--help可以看到可以配置的参数
./configure --help

       查看编译可选的配置参数(以下只是一些常用的配置项):

     

--prefix=PATH                      nginx的默认安装路径,没有指定的话。默认为/usr/local/nginx

--sbin-path=PATH                nginx可执行命令文件的路径,没有指定的话,默认<prefix>/sbin/nginx

--conf-path=PATH               nginx配置文件路径,没有指定的话,默认为<prefix>/conf/nginx.conf

--error-log-path=PATH        在nginx.conf中没有使用error_log指定错误日志路径时,默认<prefix>/logs/error.log

--http-log-path=PATH         定义被访问文件的日志存放路径,如果在nginx.conf中没有使用access_log指定,默认为<prefix>/logs/access.log 

--pid-path=PATH                    当在nginx.conf中没有使用pid指定pid文件路径时,默认为<prefix>/logs/nginx.pid

--lock-path=PATH                   锁文件存放路由,如果在nginx.conf中没有指定,则默认为<prefix>/logs/nginx.lock

--user=USER                        如果在Nginx.conf中没有使用user定义进程运行的属主,则默认为nobody

--group=GROUP                       如果在Nginx.conf中没有使用user定义进程运行的属组,则默认为nobody 

--builddir=DIR                     set build directory

--with-rtsig_module                使用rtsig模式

--with-select_module               使用select模式,如果当前平台没有其他有效模式,则默认编译

--without-select_module            禁止select模式

--with-poll_module                 使用poll模式,如果当前平台没有其他有效模式,则默认编译

--without-poll_module              禁止poll模式

--with-file-aio                    enable file AIO support

--with-ipv6                        开启IPV6支持

--with-debug                       开启debug

以下这些模块默认没有开启,可以使用--with命令开启以下模块

  --with-http_ssl_module             开启ssl模块

  --with-http_realip_module          可以在后端记录客户端IP

  --with-http_addition_module        enable ngx_http_addition_module

  --with-http_flv_module             开启flv模块

  --with-http_mp4_module             开启mp4模块

  --with-http_gzip_static_module     开启gzip模块

  --with-http_secure_link_module     enable ngx_http_secure_link_module

  --with-http_stub_status_module     开启状态查看模块

 

  以下模块默认是开启的,可以使用--without选项关闭相关模块

  --without-http_charset_module      disable ngx_http_charset_module

  --without-http_gzip_module         禁用gzip压缩模块

  --without-http_ssi_module          禁用ssl模块

  --without-http_userid_module       disable ngx_http_userid_module

  --without-http_access_module       禁用access模块

  --without-http_auth_basic_module   禁用auth_basic认证模块

  --without-http_autoindex_module    禁用列目录模块

  --without-http_geo_module          禁用geo模块

  --without-http_map_module          禁用map模块

  --without-http_referer_module      disable ngx_http_referer_module

  --without-http_rewrite_module      禁用重定向模块

  --without-http_proxy_module        禁用代理模块

  --without-http_fastcgi_module      禁用fastcgi模块

  --without-http_uwsgi_module        disable ngx_http_uwsgi_module

  --without-http_scgi_module         disable ngx_http_scgi_module

  --without-http_memcached_module    disable ngx_http_memcached_module

  --without-http_limit_conn_module   disable ngx_http_limit_conn_module

  --without-http_limit_req_module    disable ngx_http_limit_req_module

  --without-http_empty_gif_module    disable ngx_http_empty_gif_module

  --without-http_browser_module      disable ngx_http_browser_module

  --without-http_upstream_ip_hash_module    禁用upstream模块

 --with-http_perl_module            开启perl模块
  --with-perl_modules_path=PATH      设置perl模块路径
  --with-perl=PATH                   为perl库设置路径
  --http-client-body-temp-path=PATH  set path to store http client request body temporary files
  --http-proxy-temp-path=PATH        set path to store http proxy temporary files
  --http-fastcgi-temp-path=PATH      set path to store http fastcgi temporary files
  --http-uwsgi-temp-path=PATH        set path to store http uwsgi temporary files
  --http-scgi-temp-path=PATH         set path to store http scgi temporary files
  --without-http                     禁用http服务
  --without-http-cache               禁用http cache
  --with-mail                       开启mail服务
  --with-mail_ssl_module             在mail服务中开启ssl
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module
  --with-google_perftools_module     开启google_perftools模块
  --with-cpp_test_module             开启cpp_test模块
  --add-module=PATH                  enable an external module
  --without-pcre                     禁止使用perl正则库
  --with-pcre                        强制使用perl正则库

     编译安装
./configure  --prefix=/etc/nginx/  --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module 
--with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module 
--with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-ipv6
    结果如下图:

     编译并安装
make && make install
     FastCGI回顾
     FastCGI是一个可伸缩地、高速地在HTTP server和动态脚本语言间通信的接口。多数流行的HTTP server都支持FastCGI,包括Apache、Nginx和lighttpd等,同时,FastCGI也被许多脚本语言所支持,其中就有PHP。FastCGI是从CGI发展改进而来的。传统CGI接口方式的主要缺点是性能很差,因为每次HTTP服务器遇到动态程序时都需要重新启动脚本解析器来执行解析,然后结果被返回给HTTP服务器。这在处理高并发访问时,几乎是不可用的。另外传统的CGI接口方式安全性也很差,现在已经很少被使用了。FastCGI接口方式采用C/S结构,可以将HTTP服务器和脚本解析服务器分开,同时在脚本解析服务器上启动一个或者多个脚本解析守护进程。当HTTP服务器每次遇到动态程序时,可以将其直接交付给FastCGI进程来执行,然后将得到的结果返回给浏览器。这种方式可以让HTTP服务器专一地处理静态请求或者将动态脚本服务器的结果返回给客户端,这在很大程度上提高了整个应用系统的性能。
    Nginx不支持对外部程序的直接解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket,(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接纳到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。
      

    PHP5.3版本源码已经默认支持php-fpm了,但是debian6认为它还没经过广泛的测试,所以在debian6的软件仓库中,虽然php版本为5.3.3,但是却没包含php-fpm,如果不想手工编译安装php的话可以换一个源。
     
     修改源列表
vi /etc/apt/sources.list
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
    更新源列表,安装php5-fpm
apt-get update wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg |  apt-key add -
apt-get install php5-fpm
    安装其他常用php5组件
apt-get install php5 php5-cgi php5-cli php5-mysql php5-memcache
    启动php-fpm
/etc/init.d/php5-fpm start

    这样的话最基本的nginx+php环境就搭建完毕了。    

 


转载于:https://my.oschina.net/guol/blog/73282

Ubuntu Debian(NGINX/PHP/MYSQL)快速配置工具LNMP云安装 Ubuntu Debian安装基于debian apt-get 快速配置安装nginx php mysql等。LNMP云安装Ubuntu Debian(NGINX/PHP/MYSQL)快速配置工具经测试,整个过程约2-5分钟完成。各种组件均使用最新稳定版。加入php host功能限制每个网站的访问目录,防止跨目录,更安全!解决nginx 0day漏洞! DebianLNMP特点:1. 独特的DebianLNMP安全增强设置。2. 新软件库基于http://www.dotdeb.org/可保持同步更新。3. Nginx MySQL PHP 全部升级到最新稳定版本。4. 快捷的安装脚本,快速安装开源LNMP软件组合。5. 适合懒人+初学者。随着时间变迁,安装的版本会是更新版本。6. 最快安装、最新稳定版、最省资源! Ubuntu Debian(NGINX/PHP/MYSQL)LNMP云安装 直接给出安装方法:最快安装、最新稳定版、最省资源! root@DebianLNMP-Jimmyli:~# wget http://sourceforge.net/projects/debian-lnmp/files/DebianLNMP/DebianLNMP-Jimmyli.sh root@DebianLNMP-Jimmyli:~# sh DebianLNMP-Jimmyli.sh 输入域名,回车。 接着输入MYSQL root用户密码,再次输入确认MYSQL root用户密码,等待安装完成。整个过程约2-5分钟。 安装完成了! 一如既往,安装快捷方便、迅速! 直接给出安装方法:最快安装、最新稳定版、最省资源! 两步安装即完成命令(Pro加强版) root@DebianLNMP-Jimmyli:~# wget http://sourceforge.net/projects/debian-lnmp/files/DebianLNMP/DebianLNMP-Pro-Jimmyli.sh root@DebianLNMP-Jimmyli:~# sh DebianLNMP-Pro-Jimmyli.sh DebianLNMP加强版? 延续DebianLNMP全部功能...新增PHP5插件ImageMagick、XCache、memcache、curl、MCrypt。 DebianLNMP一键安装LNMP状态管理: 安装完成后,管理NginxPHP5、MySQL已经有标准管理命令,其状态管理沿用了Linux通用性。 Nginx状态管理 /etc/init.d/nginx {start|stop|restart|reload|force-reload|status|configtest}PHP5-FPM状态管理 /etc/init.d/php5-fpm {start|stop|status|restart|reload|force-reload}MySQL状态管理/etc/init.d/mysql {start|stop|restart|reload|force-reload|status} Nginx nginx.conf:/etc/nginx/nginx.conf MySQL my.cnf:/etc/mysql/my.cnf PHP php.ini:/etc/php5/fpm/php.ini DebianLNMP一键安装LNMP效果图: Ubuntu Debian(NGINX/PHP/MYSQL)快速配置工具 Debian6系统下使用之前发布的“DebianLNMP”服务器软件套件,DebianLNMP一键安装包是一个快捷的服务器套件,轻轻松松全自动安装LNMP(Nginx、MySQL、PHPphpMyAdmin)可直接用再生产环境。现在我们已经在Debian/UbuntuVPS(VDS)或独立主机安装LNMP,安装最快最新(Nginx、MySQL、PHPphpMyAdmin)生产环境。 下面介绍配套的DebianLNMP虚拟主机管理工具,快速创建Nginx PHP5.3 MySQL配置。 什么是DebianLNMP虚拟主机管理工具? 使用DebianLNMP一键安装包,安装Nginx/PHP5.3/MySQL环境后,需要创建添加、新建、删除虚拟主机。它能管理多域名(子域名)的虚拟主机,在Debian系统中以向导的形式管理,按照向导问题选择相应功能即可快速创建。 Debian虚拟主机管理软件?Debian系统安装LNMP环境只需要两条命令,Debian6一键安装DebianLNMP最快.最新.最省!同样,管理LNMP虚拟主机
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值