Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛

LNMP是一个缩写,它指一组通常一起使用来运行动态网站或者服务器的自由软件:

Linux+Nginx+MySQL+php(php-fpm),由于Nginx有大并发的优势,现在越来越多的企业LAMP平台都在向LNMP迁移。

接着我们开始进入LNMP搭建。现实生产环境下,不同的业务需求都不相同,因此更多的企业会考虑使用源码搭建LNMP环境,这样可以更加灵活使用各个功能参数将性能调制到最佳状态。当然如果贵公司的环境比较简单,可以考虑rpm包安装。

注意:本实验环境基本上都是从各大官网下载的最新安装包。

一、系统环境:

 
  
  1. [root@rhel6u3-7 ~]# uname -r 
  2. 2.6.32-279.el6.i686 
  3. [root@rhel6u3-7 ~]# cat /etc/redhat-release  
  4. Red Hat Enterprise Linux Server release 6.3 (Santiago) 
  5. [root@rhel6u3-7 ~]# 

二、开始安装部署LNMP

1、部署环境之前先配置好yum仓库指向对应光盘所在位置即可。

yum能够自动解决依赖包问题,功能明显优越于rpm安装。

 
  
  1. [root@rhel6u3-7 ~]# mount /dev/cdrom  /media/cdrom/   //挂载光盘 
  2. mount: block device /dev/sr0 is write-protected, mounting read-only 
  3. [root@rhel6u3-7 ~]# vim /etc/yum.repos.d/rhel-source.repo  //编辑并修改默认yum配置文件 
  4. [rhel-source] 
  5. name=Red Hat Enterprise Linux $releasever - $basearch - Source 
  6. baseurl=file:///media/cdrom 
  7. enabled=1 
  8. gpgcheck=0 
  9. [root@rhel6u3-7 ~]# yum clean all  //清空yum环境 
  10. Loaded plugins: product-id, security, subscription-manager 
  11. Updating certificate-based repositories. 
  12. Unable to read consumer identity 
  13. Cleaning repos: rhel-source 
  14. Cleaning up Everything 
  15. [root@rhel6u3-7 ~]# yum makecache  //清空yum缓存 
  16. Loaded plugins: product-id, security, subscription-manager 
  17. Updating certificate-based repositories. 
  18. Unable to read consumer identity 
  19. rhel-source                                                                       | 4.0 kB     00:00 ...  
  20. rhel-source/filelists_db                                                          | 3.1 MB     00:00 ...  
  21. rhel-source/primary_db                                                            | 2.5 MB     00:00 ...  
  22. rhel-source/other_db                                                              | 1.2 MB     00:00 ...  
  23. rhel-source/group_gz                                                              | 204 kB     00:00 ...  
  24. Metadata Cache Created   //当出现以上信息时候,说明yum环境配置OK了。 

2、安装LNMP环境所需要的最基本包

 
  
  1. [root@rhel6u3-7 ~]#yum -y install libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl-devel libtool-ltdl-devel gcc *c++* ncurses-devel   // libjpeg-devel ,libpng-devel ,libtiff-devel ,fontconfig-devel ,freetypedevel, 
  2. libXpm-devel这些都是图片与字体相关的开发包,为了使php可以对其做更好的支持。gettext是语言相关的一个函数库。openssl-devel是一套工具,用于生成X.509协议中所使用的密钥,公钥等文件。libtool是一个通用库支持脚本,在php编译过程中会需要使用到。 
  3. [root@rhel6u3-7 yuanma]#tar -zxvf pcre-8.32.tar.gz //解压 
  4. [root@rhel6u3-7 yuanma]#cd pcre-8.32/  安装nginx需要的pcre包 
  5. [root@rhel6u3-7 pcre-8.32]#./configure  //检查配置环境 
  6. [root@rhel6u3-7 pcre-8.32]#make && make install  //编译安装 
  7. [root@rhel6u3-7 lib]# ln -s libpcre.so.0.0.1 libpcre.so.1  //做个软连接指向libpcre.so.1,否则安装nginx会报错,找不到libpcre.so.1 

 

3、安装nginx软件包

关于nginx详细配置可参看以下文档

Nginx实战基础篇一 源码包编译安装部署web服务器

http://dreamfire.blog.51cto.com/418026/1140965

Nginx实战基础篇二 Nginx主配置文件参数详解http://dreamfire.blog.51cto.com/418026/1140995

 
  
  1. [root@rhel6u3-7 yuanma]# tar -xzf nginx-1.2.7.tar.gz 
  2. [root@rhel6u3-7 nginx-1.2.7]# useradd nginx 
  3. [root@rhel6u3-7 nginx-1.2.7]#  ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-sha1=/usr/lib   //-with-sha1指定希哈函数库位置,其他参数参看以上共享文档 
  4. [root@rhel6u3-7 nginx-1.2.7]#make && make install 
  5. [root@rhel6u3-7 pcre-8.32]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf //启动nginx 
  6. [root@rhel6u3-7 pcre-8.32]# links 192.168.100.107  //出现welcome to nginx! 说明nginx安装成功 

4、安装mysql数据库

安装mysql包,并设置mysql开机自动启动。

 
  
  1. [root@rhel6u3-7 mysql-5.5.9]# autoreconf --force –install  //由autoconf包提供 Autoconf可以用来分析用户的系统,判断是否符合POSIX标准,并提供相应解决方法。 
  2. autoreconf: `configure.ac' or `configure.in' is required 
  3. [root@rhel6u3-7 yuanma]# tar -xzf mysql-5.1.67.tar.gz  //解压mysql安装包 
  4. [root@rhel6u3-7 mysql-5.1.67]# ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql  --enable-assembler  --with-extra-charsets=all --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-pthread --with-big-tables --without-debug --with-ssl  //编译安装mysql时我们尽量以静态化方式编译,提高mysql性能,在安装之前你应该已经停止机器上原有的mysql,甚至应该将原本的卸载。--enable-assembler参数将会使mysql使用一些字符函数的汇编版本,--with-extra-charsets设置了支持的字符集,--enable-thread-safe-client和--with-pthread这两个参数要求mysql使用线程库并以线程方式编译了客户端。 
  5. ……  //出现以下信息说明安装成功 
  6. Thank you for choosing MySQL! 
  7. Remember to check the platform specific part of the reference manual 
  8. for hints about installing MySQL on your platform. 
  9. Also have a look at the files in the Docs directory. 
  10. [root@rhel6u3-7 mysql-5.1.67]# make && make install 
  11. [root@rhel6u3-7 mysql-5.1.67]# useradd mysql  –s /sbin/nologin  // 创建mysql管理用户名为mysql,并设置禁止登陆系统。 
  12. [root@rhel6u3-7 mysql-5.1.67]# /usr/local/mysql/bin/mysql_install_db  --user=mysql  //使用本地用户mysql运行mysql数据库 
  13. [root@rhel6u3-7 mysql-5.1.67]# cd /usr/local/mysql/ 
  14. [root@rhel6u3-7 mysql]# chown -R root:mysql .   //更改mysql主目录属主和属组,增强安全性 
  15. [root@rhel6u3-7 mysql]# chown mysql. /var/lib/mysql -R 
  16. [root@rhel6u3-7 mysql]# cp share/mysql/my-huge.cnf /etc/my.cnf  
  17. cp: overwrite `/etc/my.cnf'? y 
  18. [root@rhel6u3-7 mysql]# cp share/mysql/mysql.server /etc/init.d/mysqld  //创建system V 脚本 
  19. [root@rhel6u3-7 mysql]# chmod 755 /etc/init.d/mysqld  
  20. [root@rhel6u3-7 mysql]# chkconfig --add mysqld  //添加到开机启动项中 
  21. [root@rhel6u3-7 mysql]# chkconfig mysqld on  //设置开机启动 
  22. [root@rhel6u3-7 mysql]# service mysqld start  //用system V脚本启动开是否能够成功启动mysql 
  23. Starting MySQL. SUCCESS!  
  24. [root@rhel6u3-7 mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >>~/.bashrc  //创建搜索路径 
  25. [root@rhel6u3-7 ~]# cat ./.bashrc | grep mysql 
  26. export PATH=$PATH:/usr/local/mysql/bin 
  27. [root@rhel6u3-7 init.d]# mysqladmin -u root password 123.com  //创建数据库管理用户及密码 

 

5、安装php软件

安装php软件之前,需要安装以下库,方可更佳完美的支持php软件

 

 
  
  1. [root@rhel6u3-7 yuanma]# tar -xf gd-2.0.35.tar.gz  //gd2是一个用以生成图形图片的库,RHEL自带gd2的开发包,但是版本比较低,生成的图片是黑白的,非常不美观,因此这边单独编译一个高版本。 
  2. [root@rhel6u3-7 gd-2.0.35]# ./configure -prefix=/usr/local/gd2 
  3. [root@rhel6u3-7 gd-2.0.35]# make && make install 
  4.  
  5. [root@rhel6u3-7 yuanma]# tar -zxvf libiconv-1.14.tar.gz  //libiconv 用于实现一个字符编码到另一个字符编码的转换。 
  6. [root@rhel6u3-7 yuanma]# cd libiconv-1.14 
  7. [root@rhel6u3-7 libiconv-1.14]# ./configure 
  8. [root@rhel6u3-7 libiconv-1.14]#make && make install 
  9.  
  10. [root@rhel6u3-7 yuanma]# tar xf libmcrypt-2.5.7.tar.gz  //libmcrypt 可以使php支持更多加密算法。 
  11. [root@rhel6u3-7 yuanma]# cd libmcrypt-2.5.7 
  12. [root@rhel6u3-7 libmcrypt-2.5.7]# ./configure 
  13. [root@rhel6u3-7 libmcrypt-2.5.7]# make && make install 
  14.  
  15. [root@rhel6u3-7 yuanma]# tar xf mhash-0.9.9.tar.gz //mhash是一个哈稀演函数库,它可以支持多种哈稀演算法,例如最出名的MD5、SHA1 或 GOST,还有其它多种的哈稀演算法。 
  16. [root@rhel6u3-7 yuanma]# cd mhash-0.9.9 
  17. [root@rhel6u3-7 mhash-0.9.9]# ./configure 
  18. [root@rhel6u3-7 mhash-0.9.9]# make && make install 
  19.  
  20. [root@rhel6u3-7 yuanma]# tar -xf libevent-2.0.21-stable.tar.gz  //libevent 是一个事件触发的网络库,适用于windows、linux、bsd等多种平台,内部用select、epoll、kqueue等系统调用管理事件机制。 
  21. [root@rhel6u3-7 yuanma]# cd libevent-2.0.21-stable 
  22. [root@rhel6u3-7 libevent-2.0.21-stable]# ./configure 
  23. [root@rhel6u3-7 libevent-2.0.21-stable]# make && make install 
  24.  
  25. [root@rhel6u3-7 yuanma]# yum –y install  libxml2-devel  libcurl-devel  //安装其他支持包 
  26. //以下开始安装php软件 
  27. [root@rhel6u3-7 yuanma]# tar xf php-5.2.17.tar.gz 
  28. [root@rhel6u3-7 yuanma]# gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 //将php-fpm作为补丁加入php源码中 
  29. [root@rhel6u3-7 php-5.2.17]# ./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --enable-discard-path --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config  -with-iconv-dir --with-freetype-dir with-jpeg-dir --with-png-dir --with-gd=/usr/local/gd2/  --with-zlib --with-libxml-dir --with-curl --with-curlwrappers --with-openssl --with-mhash --with-xmlrpc --with-mcrypt --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex  --enable-mbstring --enable-gd-native-ttf --enable-ftp --enable-pcntl --enable-sockets --enable-zip --disable-debug --disable-ipv6 
  30. //--enable-fastcgi启动fast-cgi " 
  31. ---enable-fpm"是激活对FastCGI模式的fpm支持, 
  32. "--enable-discard-path" 打开这个选项,用户就不能透过浏览器读取类似.htaccess 的系统安全相关的文件。 
  33. "--enable-force-cgi-redirect" 若使用 CGI VERSION 模式来执行 PHP 的设,打开本选项会增加安全性。例如用户读 http://my.host/cgi-bin/php/secret/doc.html 遇到比较了解 PHP 系统的黑客级用户可能会自已输入以下网址 http://my.host/secret/doc.html 来读取相关信息。若 PHP 和 Apache 编译在一起,让 PHP 变成 Apache 的一部份,则不需要加入本选项。 
  34. --with-config-file-path在指定php主配置文件的路径 
  35. --with-mysql和--with-mysqli在指定你的mysql的位置和它的相关工具 
  36. --with-iconv-dir,--with-freetype-dir,-with-jpeg-dir,--with-png-dir,--withgd,--with-zlib,--with-libxml-dir这些都是在启用对某种文件的支持 
  37. --with-curl和--with-curlwrappers是用于支持curl函数,此函数允许你用不同的协议连接和沟通不同的服务器 
  38. --with-openssl,--with-mhash,--with-mcrypt这都是和加密有关的参数,启用它们是为了让php可以更好的支持各种加密。 
  39. "--enable-bcmath" 高精度数学运算组件。 
  40. "--enable-shmop" 和 "--enable-sysvsem" 使得你的PHP系统可以处理相关的IPC函数 。IPC是一个Unix标准通讯机制,它提供了使得在同一台主机不同进程之间可以互相通讯的方法。 
  41. "--enable-inline-optimization" 栈堆指针和优化线程。 
  42. "--enable-pcntl" 多线程优化。 
  43. make ZEND_EXTRA_LIBS='-liconv' 手工指定将iconv加到php额外库中,一般来说这些库的增加php可以自动完成,只是iconv貌似不太合群,需要手工操作。 
  44. …… //出现以下内容,说明配置成功 
  45. +--------------------------------------------------------------------+ 
  46. | License:                                                           | 
  47. | This software is subject to the PHP License, available in this     | 
  48. | distribution in the file LICENSE.  By continuing this installation | 
  49. | process, you are bound by the terms of this license agreement.     | 
  50. | If you do not agree with the terms of this license, you must abort | 
  51. | the installation process at this point.                            | 
  52. +--------------------------------------------------------------------+ 
  53. Thank you for using PHP. 
  54. [root@rhel6u3-7 php-5.2.17]# make && make install //make完了之后,如果没有错误,你也可以执行一下make test看看是否有错误,不过时间会比较长。 
  55. [root@rhel6u3-7 php-5.2.17]# cp php.ini-dist /usr/local/php/etc/php.ini  //创建php配置文件 

 

6、安装php扩展模块,更好的支持php

安装扩展模块是为了进一步完善我们的php,或提高性能,或提高安全性,或扩展功能,或增加稳定

性等。

 
  
  1. [root@rhel6u3-7 yuanma]# tar -zxf memcache-3.0.7.tgz  //memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。 
  2. [root@rhel6u3-7 yuanma]# cd memcache-3.0.7 
  3. [root@rhel6u3-7 memcache-3.0.7]# /usr/local/php/bin/phpize  
  4. [root@rhel6u3-7 memcache-3.0.7]# ./configure --with-php-config=/usr/local/php/bin/php-config 
  5. [root@rhel6u3-7 memcache-3.0.7]# make && make install 
  6.  
  7. [root@rhel6u3-7 yuanma]# cd eaccelerator-eaccelerator-42067ac  //eAccelerator加速引擎是基于mmcache开发的PHP加速优化软件。通过编译和缓存来增加PHP脚本的性能,使得PHP脚本在编译的状态下降低服务器负载,对服务器的开销几乎完全消除。它还对脚本起优化作用,能加快其执行效率,提高PHP应用执行速度最高达10倍。 
  8. [root@rhel6u3-7 eaccelerator-eaccelerator-42067ac]# /usr/local/php/bin/phpize  
  9. [root@rhel6u3-7 eaccelerator-eaccelerator-42067ac]# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config 
  10. [root@rhel6u3-7 eaccelerator-eaccelerator-42067ac]# make && make install 
  11.  
  12. [root@rhel6u3-7 yuanma]# tar xf PDO_MYSQL-1.0.2.tgz //PDO_MYSQL 是一个php的扩展模块,可以让php更好调用mysql。 
  13. [root@rhel6u3-7 yuanma]# cd PDO_MYSQL-1.0.2 
  14. [root@rhel6u3-7 PDO_MYSQL-1.0.2]# /usr/local/php/bin/phpize  //ImageMagick是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软件套装。 
  15.  [root@rhel6u3-7 PDO_MYSQL-1.0.2]# ./configure --prefix=/usr/local/pdo-mysql --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql 
  16. [root@rhel6u3-7 PDO_MYSQL-1.0.2]# make && make install 
  17.  
  18. [root@rhel6u3-7 ImageMagick-6.5.9-10]# yum -y install  perl-ExtUtils-CBuilder perl-ExtUtils-MakeMake  //安装imageMangick包依赖的系统包 
  19. [root@rhel6u3-7 yuanma]# tar xf ImageMagick-6.5.9-10.tar.gz // //ImageMagick是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软件套装。 
  20.  
  21. [root@rhel6u3-7 yuanma]# cd ImageMagick-6.5.9-10 
  22. [root@rhel6u3-7 ImageMagick-6.5.9-10]# ./configure --enable-shared --with-modules --without-x --with-gs-font-dir=default --with-perl=yes --with-zlib=yes --with-jpeg=yes 
  23. [root@rhel6u3-7 ImageMagick-6.5.9-10]# make && make install 
  24.  
  25. [root@rhel6u3-7 yuanma]# tar xf imagick-3.0.1.tgz  
  26. [root@rhel6u3-7 yuanma]# cd imagick-3.0.1  
  27. [root@rhel6u3-7 imagick-3.0.1]# /usr/local/php/bin/phpize 
  28. [root@rhel6u3-7 imagick-3.0.1]# ./configure --with-php-config=/usr/local/php/bin/php-config //--with-php-config在指定php的配置工具,/usr/local/php/bin/phpize 是用来扩展php的扩展模块的,通过phpize可以建立php的外挂模块。 
  29. [root@rhel6u3-7 imagick-3.0.1]# make && make install 

 

 

7、修改php主配置文件,以使php支持扩展模块。

 

 
  
  1. [root@rhel6u3-7 imagick-3.0.1]# cat >>/usr/local/php/etc/php.ini <<ENDF //修改php主配置文件,以使php支持扩展模块。 
  2. > [eAccelerator] 
  3. > zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" 
  4. > eaccelerator.shm_size="32" 
  5. > eaccelerator.cache_dir="/usr/local/cache/ea" 
  6. > eaccelerator.enable="1" 
  7. > eaccelerator.optimizer="1" 
  8. > eaccelerator.check_mtime="1" 
  9. > eaccelerator.debug="0" 
  10. > eaccelerator.filter="" 
  11. > eaccelerator.shm_max="0" 
  12. > eaccelerator.shm_ttl="0" 
  13. > eaccelerator.shm_prune_period="0" 
  14. > eaccelerator.shm_only="0" 
  15. > eaccelerator.compress="1" 
  16. > eaccelerator.compress_level="9" 
  17. > ENDF 
  18. [root@rhel6u3-7 imagick-3.0.1]# 
  19. [root@rhel6u3-7 imagick-3.0.1]# mkdir -p /usr/local/cache/ea  
  20. [root@rhel6u3-7 imagick-3.0.1]# vim /usr/local/php/etc/php.ini //注意:以下是更改后的内容 
  21. expose_php = Off  //expose是php的一个参数,关闭它则会显示更少的php消息,以提高安全性。output_buffering是一个缓存有关的参数选项。 
  22. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/" 
  23. extension = "memcache.so" 
  24. extension = "pdo_mysql.so" 
  25. extension = "imagick.so" 
  26. output_buffering = On 
  27. 更多php核心参数的配置请参考 http://manual.phpv.net/zh/ini.core.php 

 

8、优化配置PHP-FPM

PHP-FPM是第三方的FastCGI进程管理器,它是作为PHP的一个补丁来开发的,在安装的时候也需

要和PHP源码一起编译,也就是说PHP-FPM被编译到PHP内核中,因此在处理性能上更加优秀,同

PHP-FPM在处理高并发方面也比spawn-fcgi引擎好很多,因此,推荐Nginx+php/php-fpm这个组合

php进行解析

注意:下载软件包版本时,尽量使phpphp-fpm版本一致,如果版本之间相差太大,可能会出现兼

容的问题。

 

 
  
  1. [root@rhel6u3-7 ~]# vim /usr/local/php/etc/php-fpm.conf  //配置并优化php-fpm,红色部分为修改后的部分,部分注释部分需要取消掉。 
  2. <value name="listen_address">192.168.100.107:9000</value> //配置FastCGI进程监听的IP地址以及端口。 
  3.           <value name="display_errors">1</value> //设置为1显示php错误信息 
  4.    <value name="user">nginx</value>  //设置允许FastCGI运行的用户名为nginx 注意和nginx主配置文件中的指定的用户保持一致                             
  5.     <value name="group">nginx</value>  //设置运行FastCGI运行的组名为nginx  注意和nginx主配置文件中的指定的用户保持一致         
  6.   <value name="max_children">64</value>  //设置FstCGI的进程数,根据官方建议,小于2GB内存的服务器,可以只开启64个进程,4GB以上内存的服务器可以开启200个进程 
  7. <value name="request_terminate_timeout">0s</value> //设置FastCGI执行脚本的时间,默认是0秒,也就是无限制的执行下去,可以根据情况进行修改 
  8. <value name="rlimit_files">65536</value>  //通过ulimit –HSn 65536 设置系统文件数打开最大值为65535,这里的设置才能生效。 
  9. <value name="max_requests">500</value> //指明了每个children最多处理多少个请求后便会被关闭。 
  10. <value name="allowed_clients">192.168.100.107</value> //设置允许访问FastCGI进程解析器的IP地址,如果不在这里指定IP地址,将无法接受Nginx转发过来的PHP解析请求。 
  11. [root@rhel6u3-7 imagick-3.0.1]# /usr/local/php/sbin/php-fpm start   //启动FastCGI方法1 
  12. Starting php_fpm  done 
  13. [root@rhel6u3-7 imagick-3.0.1]# /usr/local/php/bin/php-cgi –fpm  //启动FastCGI方法2 建议采用 
  14. [root@rhel6u3-7 imagick-3.0.1]# netstat -antl | grep 9000  //查看监听端口及FastCGI运行程序 
  15. tcp        0      0 192.168.100.107:9000        0.0.0.0:*                   LISTEN       
  16. [root@rhel6u3-7 imagick-3.0.1]# ps -ef | grep php-cgi 
  17. root      9891     1  0 16:48 ?        00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf 
  18. nginx     9892  9891  0 16:48 ?        00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf 
  19. nginx     9893  9891  0 16:48 ?        00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf 
  20. ……….. 

 

9、配置Nginx支持PHP-FPM

 

 
  
  1. [root@rhel6u3-7 ~]# vim /usr/local/nginx/conf/nginx.conf //配置网站基本信息,以下只显示主要信息,其他信息可参看Nginx实战基础篇二 Nginx主配置文件参数详解http://dreamfire.blog.51cto.com/418026/1140995 ,当然也可以配置虚拟主机,这里不做介绍。 
  2. …………………. 
  3.   server { 
  4.         listen       80; 
  5.         server_name  51bbs.rsyslog.org;  //网址 
  6.         location / { 
  7.             root   html; 
  8.             index  index.php index.html; 
  9.         } 
  10. //以下php部分nginx默认配置文档中有打开注释即可 
  11.         location ~ \.php$ {  
  12.             root           html; 
  13.             fastcgi_pass   192.168.100.107:9000;  //设置监听IP及端口 
  14.             fastcgi_index  index.php; 
  15.             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;  //红色部分为网站绝对路径 
  16.             include        fastcgi_params; 
  17.         } 
  18. …………. 
  19. [root@rhel6u3-7 ~]# cd /usr/local/nginx/html/ 
  20. [root@rhel6u3-7 html]# vim index.php  //创建一个php主页用于测试php是否能够正常解析nginx的请求,如果出现了php安装配置以及功能列表统计系统,说明php环境安装成功。 
  21. <?php 
  22.         phpinfo(); 
  23. ?> 
  24. [root@rhel6u3-7 html]# /etc/rc.d/init.d/nginx restart 
  25. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
  26. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 
  27. Stopping nginx:                                            [  OK  ] 
  28. Starting nginx:                                            [  OK   ] 

 

10、在DNS上设置A记录,并在客户机上解析是否成功

有关DNS搭建及配置请参看http://dreamfire.blog.51cto.com/418026/1091943

 

 
  
  1. 51bbs       A   192.168.100.107 

 

测试NginxPHP的解析功能

 

 

11、优化NginxFastCGI的参数

 

 
  
  1. [root@rhel6u3-7 bbs]# vim /usr/local/nginx/conf/nginx.conf //在nginx中添加以下FastCGI优化参数 
  2. http { 
  3. …….. 
  4. fastcgi_connect_timeout 300; //指定连接到后端FastCGI的超时时间 
  5. fastcgi_send_timeout 300;  //指定向FastCGI传送请求的超时时间,这个值是已经完成两次握手后向FastCGI传送请求的超时时间 
  6. fastcgi_read_timeout 300;  //指定向FastCGI接收请求的超时时间,这个值是已经完成两次握手后向FastCGI传送请求的超时时间 
  7. fastcgi_buffer_size 128k;  //使用1个128KB的缓冲区读取应答的第一部分 
  8. fastcgi_buffers 4 128k; //需要4个128K的缓冲区来缓冲FastCGI的应答请求 
  9. fastcgi_busy_buffers_size 256k; //默认值是Fastcig_buffers的两倍 
  10. fastcgi_temp_file_write_size 128k; //表示在写入缓存文件时使用多大的数据块,默认值是fastcig_buffers的两倍 
  11. fastcgi_intercept_errors on; //记录错误 
  12. ……..} 

 

以上LNMP环境配置基本完成,现在我们通过搭建一个Discuz论坛来测试LNMP是否能够完美的结合

运转。

12、搭建Discuz论坛

先去Discuz下载最新版的安装包

 

 
  
  1. [root@rhel6u3-7 ~]# unzip Discuz_X2.5_SC_UTF8.zip 
  2. [root@rhel6u3-7 ~]# cd upload/ 
  3. [root@rhel6u3-7 upload]# cp -rfp * /usr/local/nginx/html/  //copy论坛网站部分到nginx网站主目录下 
  4. cp: overwrite `/usr/local/nginx/html/index.php'? y  
  5. [root@rhel6u3-7 ~]# chown nginx. /usr/local/nginx/html/* -R  //修改网站主目录及附属的所有文件和文件夹属主和属组都为nginx 
  6. [root@rhel6u3-7 bbs]# /etc/rc.d/init.d/mysqld restart  //启动mysql 
  7. Starting MySQL......................... SUCCESS!  
  8. [root@rhel6u3-7 bbs]# /etc/rc.d/init.d/nginx restart   //启动nginx 
  9. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
  10. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 
  11. Stopping nginx:                                            [  OK  ] 
  12. Starting nginx:                                            [  OK  ] 
  13. [root@rhel6u3-7 bbs]# /usr/local/php/sbin/php-fpm restart  //启动FastCGI 
  14. Shutting down php_fpm .. done 
  15. Starting php_fpm  done 
  16. [root@rhel6u3-7 bbs]# 

在客户机的浏览器中输入http://51bbs.rsyslog.org/install

 

 

 注意以下是环境检测,主要看看权限是否满足需求。

 

 

 

 

 

数据库名称及密码为创建mysql时候创建的,用于管理创建的数据库51bbs,管理员账户及密码用于

管理论坛。

 

 

 

 

出现以下页面说明安装成功,由于没有联网,所以未显示出来,呵呵。

 

 

 

 

通过访问http://51bbs.rsyslog.org 可以尽情访问论坛并发布文章了。

 



本文转自凌激冰51CTO博客,原文链接:http://blog.51cto.com/dreamfire/1148203,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值