Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208732
  • 博文数量: 53
  • 博客积分: 2059
  • 博客等级: 大尉
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-30 03:03
文章分类
文章存档

2012年(4)

2011年(19)

2010年(30)

分类: LINUX

2010-10-05 08:33:00

Nginx+mysql+php配置
Nginx简介
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,Nginx是由Igor Sysoev为俄罗斯访问量第二的的Rambler.ru站点开发的
,它已经在该站点运行超过三年了。Igor 将源代码以类BSD许可证的形式发布。
Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,其中包括新浪博客、新浪播客、网易新闻、腾讯网、搜狐博
客等门户网站频道,六间房、56.com等视频分享网站,Discuz!官方论坛、水木社区等知名论坛,盛大在线、金山逍遥网等网络游戏网站,豆瓣、人人网、YUPOO相
册、金山爱词霸、迅雷在线等新兴Web 2.0网站。(来自张宴博客)
一,安装Mysql
由于目前的站点跑静态的网页基本上是没有的,所以要用到Mysql,所以我们需要安装Mysql,这里我们采用RPM包来简单安装。
rpm -ivh  MySQL-client-community-5.1.51-1.rhel5.i386.rpm  
rpm -ivh  MySQL-devel-community-5.1.51-1.rhel5.i386.rpm   
rpm -ivh  MySQL-server-community-5.1.51-1.rhel5.i386.rpm
mysql_install_db    --user=mysql
mysqld_safe&
mysqladmin  -uroot -p password 'test1234'           #修改Mysql数据库密码
chkconfig --add mysql
chkconfig --level 35 on
chkconfig --list mysql
mysql              0:off    1:off    2:on    3:on    4:on    5:on    6:off
二,安装PCRE
PCRE是perl所用到的正则表达式,目的是让所安装的软件支持正则表达式,缺省情况下,Nginx只处理静态的网页请求,也就是html,如果是来自动态的网页请求,
比如.php,那么Nginx就要根据正则表达式查询路径,然后把.php交给PHP去处理
#rpm -qa |grep pcre
pcre-devel-6.6-2.el5_1.7
#cp /lib/libpcre.so.0 ~
#rpm -e --nodeps pcre-devel-6.6
#cp libpcre.so.0 /lib/
#tar -zxvf pcre-8.01.tar.gz
#cd pcre-8.01
#./configure
pcre-8.01 configuration summary:

    Install prefix .................. : /usr/local
    C preprocessor .................. : gcc -E
    C compiler ...................... : gcc
    C++ preprocessor ................ :
    C++ compiler .................... : g++
    Linker .......................... : /usr/bin/ld
    C preprocessor flags ............ :
    C compiler flags ................ : -O2
    C++ compiler flags .............. :
    Linker flags .................... :
    Extra libraries ................. :

    Build C++ library ............... : yes
    Enable UTF-8 support ............ : no
    Unicode properties .............. : no
    Newline char/sequence ........... : lf
    \R matches only ANYCRLF ......... : no
    EBCDIC coding ................... : no
    Rebuild char tables ............. : no
    Use stack recursion ............. : yes
    POSIX mem threshold ............. : 10
    Internal link size .............. : 2
    Match limit ..................... : 10000000
    Match limit recursion ........... : MATCH_LIMIT
    Build shared libs ............... : yes
    Build static libs ............... : yes
    Link pcregrep with libz ......... : no
    Link pcregrep with libbz2 ....... : no
    Link pcretest with libreadline .. : no

#make&&make install  #安装完成
三,安装Nginx
tar -zxvf nginx-0.8.36.tar.gz
cd nginx-0.8.36
./configure --prefix=/usr/local/nginx/
make&&make install
/usr/local/nginx/sbin/nginx   #启动nginx
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local    #加入开机启动nginx
查看nginx是不是启动ps -ef |grep nginx |grep -v grep
root     10320     1  0 Oct02 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   10322 10320  0 Oct02 ?        00:00:00 nginx: worker process      #出现以上信息证明Nginx已经启动
访问地址
四,安装php
安装GD库的时候,建议使用yum来安装
yum -y install gd*
1,安装libpng
tar libpng-1.2.10
cd libpng-1.2.10
./configure --prefix=/usr/local/png
make&&make install
ln -s /usr/local/png/lib* /usr/lib
2.安装png
#mkdir /usr/local/jpeg
#mkdir /usr/local/jpeg/bin
#mkdir /usr/local/jpeg/lib
#mkdir /usr/local/jpeg/include
#mkdir /usr/local/jpeg/man
#mkdir /usr/local/jpeg/man/man1
#tar xvf jpegsrc.v7.tar.tar
#cd jpeg-7
#./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
#make;make install
#ln -s /usr/local/jpeg/lib/* /usr/lib/
3、安装freetype
#tar xvf freetype-2.3.9.tar.tar
#cd freetype-2.3.9
#./configure --prefix=/usr/local/freetype
#make;make install
4、安装fontconfig
#tar zxvf fontconfig-2.4.2.tar.gz
#cd fontconfig-2.4.2
#./configure--prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
#make;make install
安装php
在以前php5.3.3版本中并不包括php-fpm插件,需要以打补丁的形式安装,但是在5.3.3之后php-fpm已经整合到php中所以安装方式和5.3.3之前有点不同
首先需要知道的是,Nginx+php需要php生成可以执行的文件才可以,所以要利用fastcgi技术来实现Nginx与php的整合,所以安装要启用Fastcgi即可,而PHP-
FPM是FastCGI的一个管理器。
tar -zxvf php-5.3.3.tar.gz
cd php.5.3.3
./configure --prefix=/usr/local/php --with-gd --with-jpeg --with-png --with-freetypt --with-mysql --enable-fastcgi --enable-fpm
#make&&make install
cp php.ini-dist /usr/local/php/etc/php.ini
/usr/local/php/sbin/php-fpm  #启动php-fpm
ps -aux |grep php
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root      3916  0.0  0.1   3920   676 pts/1    S+   07:40   0:00 grep php
root     10323  0.0  0.4  15456  1936 ?        Ss   Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10324  0.0  0.6  15716  3012 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10326  0.0  0.5  15716  2348 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10327  0.0  0.5  15716  2352 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10329  0.0  2.2  21540 10048 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10330  0.0  2.4  22284 10892 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10331  0.0  2.2  21472  9864 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10332  0.0  2.2  21472  9864 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10333  0.0  0.6  15716  3008 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10335  0.0  0.5  15716  2348 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10336  0.0  0.5  15716  2352 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10337  0.0  0.4  15452  1772 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10338  0.0  0.4  15452  1772 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10341  0.0  0.4  15452  1780 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10342  0.0  0.4  15452  1780 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10343  0.0  0.4  15452  1780 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10345  0.0  0.4  15452  1784 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10347  0.0  0.4  15452  1784 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10348  0.0  0.4  15452  1784 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10349  0.0  0.4  15452  1784 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
nobody   10350  0.0  0.4  15452  1784 ?        S    Oct02   0:00 /usr/local/php/sbin/php-fpm
echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
五,整合Nginx和PHP
上面已经讲过,Nginx自己并出处理动态的网页请求,而且Nginx将得到的动态请求转交给php来处理,打开nginx的配置文件
   #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;
        #}
         #从以上的配置信息,我们可以知道当nginx收到php网页的请求的时候,会把该请求转发到本地的9000端口,这点和apache+tomcat的整合
很像。这里是定义的Nginx转发请求,当然在php中也会定义接受请求。
vim /usr/local/php/etc/php-fpm.conf
; Start a new pool named 'www'.
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
#以上就是php监听9000端口来获取nginx对php请求的转发

所以以上配置文件,我们只需要更改nginx.conf中一下,切把整个Location的注释取消
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name
更改为
fastcgi_param  /usr/local/nginx/html  /scripts$fastcgi_script_name  更改为一个放置PHP文件的目录即可

阅读(1325) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~