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

版权声明:
本文遵循“署名非商业性使用相同方式共享 2.5 中国大陆”协议
您可以自由复制、发行、展览、表演、放映、广播或通过信息网络传播本作品
您可以根据本作品演义自己的作品
您必须按照作者或者许可人指定的方式对作品进行署名。
您不得将本作品用于商业目的。
如果您改变、转换本作品或者以本作品为基础进行创作,您只能采用与本协议相同的许可协议发布基于本作品的演绎作品。
对任何再使用或者发行,您都必须向他人清楚地展示本作品使用的许可协议条款。
如果得到著作权人的许可,您可以不受任何这些条件的限制。
Designed by 小诺(www.rsyslog.org  dreamfire.blog.51cto.com)

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. [root@rhel6u3-7 yuanma]# tar -zxvf libiconv-1.14.tar.gz  //libiconv 用于实现一个字符编码到另一个字符编码的转换。
  5. [root@rhel6u3-7 yuanma]# cd libiconv-1.14
  6. [root@rhel6u3-7 libiconv-1.14]# ./configure
  7. [root@rhel6u3-7 libiconv-1.14]#make && make install
  8. [root@rhel6u3-7 yuanma]# tar xf libmcrypt-2.5.7.tar.gz  //libmcrypt 可以使php支持更多加密算法。
  9. [root@rhel6u3-7 yuanma]# cd libmcrypt-2.5.7
  10. [root@rhel6u3-7 libmcrypt-2.5.7]# ./configure
  11. [root@rhel6u3-7 libmcrypt-2.5.7]# make && make install
  12. [root@rhel6u3-7 yuanma]# tar xf mhash-0.9.9.tar.gz //mhash是一个哈稀演函数库,它可以支持多种哈稀演算法,例如最出名的MD5、SHA1 或 GOST,还有其它多种的哈稀演算法。
  13. [root@rhel6u3-7 yuanma]# cd mhash-0.9.9
  14. [root@rhel6u3-7 mhash-0.9.9]# ./configure
  15. [root@rhel6u3-7 mhash-0.9.9]# make && make install
  16. [root@rhel6u3-7 yuanma]# tar -xf libevent-2.0.21-stable.tar.gz  //libevent 是一个事件触发的网络库,适用于windows、linux、bsd等多种平台,内部用select、epoll、kqueue等系统调用管理事件机制。
  17. [root@rhel6u3-7 yuanma]# cd libevent-2.0.21-stable
  18. [root@rhel6u3-7 libevent-2.0.21-stable]# ./configure
  19. [root@rhel6u3-7 libevent-2.0.21-stable]# make && make install
  20. [root@rhel6u3-7 yuanma]# yum –y install  libxml2-devel  libcurl-devel  //安装其他支持包
  21. //以下开始安装php软件
  22. [root@rhel6u3-7 yuanma]# tar xf php-5.2.17.tar.gz
  23. [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源码中
  24. [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
  25. //--enable-fastcgi启动fast-cgi "
  26. ---enable-fpm"是激活对FastCGI模式的fpm支持,
  27. "--enable-discard-path" 打开这个选项,用户就不能透过浏览器读取类似.htaccess 的系统安全相关的文件。
  28. "--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 的一部份,则不需要加入本选项。
  29. --with-config-file-path在指定php主配置文件的路径
  30. --with-mysql和--with-mysqli在指定你的mysql的位置和它的相关工具
  31. --with-iconv-dir,--with-freetype-dir,-with-jpeg-dir,--with-png-dir,--withgd,--with-zlib,--with-libxml-dir这些都是在启用对某种文件的支持
  32. --with-curl和--with-curlwrappers是用于支持curl函数,此函数允许你用不同的协议连接和沟通不同的服务器
  33. --with-openssl,--with-mhash,--with-mcrypt这都是和加密有关的参数,启用它们是为了让php可以更好的支持各种加密。
  34. "--enable-bcmath" 高精度数学运算组件。
  35. "--enable-shmop" 和 "--enable-sysvsem" 使得你的PHP系统可以处理相关的IPC函数 。IPC是一个Unix标准通讯机制,它提供了使得在同一台主机不同进程之间可以互相通讯的方法。
  36. "--enable-inline-optimization" 栈堆指针和优化线程。
  37. "--enable-pcntl" 多线程优化。
  38. make ZEND_EXTRA_LIBS='-liconv' 手工指定将iconv加到php额外库中,一般来说这些库的增加php可以自动完成,只是iconv貌似不太合群,需要手工操作。
  39. …… //出现以下内容,说明配置成功
  40. +--------------------------------------------------------------------+
  41. | License:                                                           |
  42. | This software is subject to the PHP License, available in this     |
  43. | distribution in the file LICENSE.  By continuing this installation |
  44. | process, you are bound by the terms of this license agreement.     |
  45. | If you do not agree with the terms of this license, you must abort |
  46. | the installation process at this point.                            |
  47. +--------------------------------------------------------------------+
  48. Thank you for using PHP.
  49. [root@rhel6u3-7 php-5.2.17]# make && make install //make完了之后,如果没有错误,你也可以执行一下make test看看是否有错误,不过时间会比较长。
  50. [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. [root@rhel6u3-7 yuanma]# cd eaccelerator-eaccelerator-42067ac  //eAccelerator加速引擎是基于mmcache开发的PHP加速优化软件。通过编译和缓存来增加PHP脚本的性能,使得PHP脚本在编译的状态下降低服务器负载,对服务器的开销几乎完全消除。它还对脚本起优化作用,能加快其执行效率,提高PHP应用执行速度最高达10倍。
  7. [root@rhel6u3-7 eaccelerator-eaccelerator-42067ac]# /usr/local/php/bin/phpize
  8. [root@rhel6u3-7 eaccelerator-eaccelerator-42067ac]# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
  9. [root@rhel6u3-7 eaccelerator-eaccelerator-42067ac]# make && make install
  10. [root@rhel6u3-7 yuanma]# tar xf PDO_MYSQL-1.0.2.tgz //PDO_MYSQL 是一个php的扩展模块,可以让php更好调用mysql。
  11. [root@rhel6u3-7 yuanma]# cd PDO_MYSQL-1.0.2
  12. [root@rhel6u3-7 PDO_MYSQL-1.0.2]# /usr/local/php/bin/phpize  //ImageMagick是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软件套装。
  13. [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
  14. [root@rhel6u3-7 PDO_MYSQL-1.0.2]# make && make install
  15. [root@rhel6u3-7 ImageMagick-6.5.9-10]# yum -y install  perl-ExtUtils-CBuilder perl-ExtUtils-MakeMake  //安装imageMangick包依赖的系统包
  16. [root@rhel6u3-7 yuanma]# tar xf ImageMagick-6.5.9-10.tar.gz // //ImageMagick是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软件套装。
  17. [root@rhel6u3-7 yuanma]# cd ImageMagick-6.5.9-10
  18. [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
  19. [root@rhel6u3-7 ImageMagick-6.5.9-10]# make && make install
  20. [root@rhel6u3-7 yuanma]# tar xf imagick-3.0.1.tgz
  21. [root@rhel6u3-7 yuanma]# cd imagick-3.0.1
  22. [root@rhel6u3-7 imagick-3.0.1]# /usr/local/php/bin/phpize
  23. [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的外挂模块。
  24. [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进行解析

注意:下载软件包版本时,尽量使php和php-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

测试Nginx对PHP的解析功能

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 可以尽情访问论坛并发布文章了。

Nginx实战基础篇PDF高清下载系列:

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

http://down.51cto.com/data/688744

Nginx实战基础篇二:Nginx主配置文件参数详解

http://down.51cto.com/data/688835

Nginx实战基础篇三:Nginx上虚拟主机的实现过程

http://down.51cto.com/data/688836

Nginx实战基础篇四:通过https方式安全访问web服务器

http://down.51cto.com/data/689197

Nginx实战基础篇五:Nginx上实现用户名密码认证访问

http://down.51cto.com/data/694934

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

http://down.51cto.com/data/694932

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

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

    Nginx实战基础篇一 源码包编译安装部署web服务器 版权声明: 本文遵循"署名非商业性使用相同方式共享 2.5 中国大陆"协议 您可以自由复制.发行.展览.表演.放映.广播或通 ...

  2. 如何在源码包编译安装的 LEMP 环境下开启 OpenSSL 功能

    如何在源码包编译安装的 LEMP 环境下开启 OpenSSL 功能 Hello,大家好!我是--邪恶君子! 今天,给大家分享一下解决源码包编译安装 LEMP 环境下开启 OpenSSL 功能问题的过程 ...

  3. zabbix 3.2.2 server端(源码包)安装部署 (一)【转】

    环境准备: 操作系统 CentOS 6.8 2.6.32-642.11.1.el6.x86_64 zabbix server 172.16.10.150 zabbix agent 172.16.10. ...

  4. 编译 php mysql 依赖包_MySQL 5.5.15源码包编译安装

    mysql果然是不愧是目前最火的数据库,自从mysql5.5.8之后,mysql的源码包编译安装都要用到cmake来进行编译了,编译的过程没有本质 mysql果然是不愧是目前最火的数据库,自从mysq ...

  5. RedHat6.4系统下LAMP环境的搭建---(源码包编译安装)---v1.0

    一:配置本地yum源 :--目录 作者:李文轩 座右铭:一个愿意为理想奋斗终生的人! 联系QQ:838997384 网站地址:www.74cto.com 说明:本篇安装的系统版本RedHat6.4(6 ...

  6. MySQL源码包编译安装

    +++++++++++++++++++++++++++++++++++++++++++ 标题:MySQL数据库实例部署 时间:2019年5月2日 内容:MySQL源码包进行编译,然后部署MySQL单实 ...

  7. linux yum源码安装mysql_linux下通过源码包安装mysql,以及yum安装

    环境介绍:本安装教程基于虚拟机CentOS7.6版本进行安装,mysql版本为5.7版本. 一.卸载已安装的mysql服务 由于我原本在虚拟机已安装过mysql,所以这里我需要先卸载掉mysql才能进 ...

  8. nginx源码包编译安装

    1.到官方站点卸载nginx-1.6.3版本的源码包 http://nginx.org/en/download.html http://nginx.org 2.安装依赖包和编译工具 yum -y in ...

  9. 源码编译安装部署LNMP架构(Nginx、MYSQL、PHP+论坛)

    目录 1.LNMP概述 1.1 LNMP所需要的安装包 2.Nginx安装 3. MYSQL安装 4. PHP安装 4.1 数据库安装 5. 论坛安装 6. 小结 1.LNMP概述 LNMP:Linu ...

最新文章

  1. 把变量赋值给寄存器_用C语言对DSP的寄存器进行操作?
  2. java中运算符_JAVA中的运算符
  3. java中一些对象(po,vo,dao,pojo)等的解释
  4. php注册界面模板,WeUI注册页面
  5. Windows Azure 安全最佳实践 - 第 6 部分:Azure 服务如何扩展应用程序安全性
  6. windows7系统损坏修复_【软件资讯】还在用win7?微软Windows 7系统正式停止技术支持...
  7. 【高校宿舍管理系统】第六章 用户管理和年级管理
  8. wps序号打乱重新排序_wps表格序号自动排列
  9. 家用计算机设置网络,教您电脑如何设置宽带连接
  10. android9.0+wifi叹号,手机wifi连上有个感叹号怎么解决_wifi已连接但有感叹号的处理方法-系统城...
  11. 精算未来会被计算机代替吗,年薪过百万还不用加班?揭开精算专业的真面目(下篇)...
  12. 用python统计字母个数_python统计字母个数 python 统计文本中字母个数
  13. 牛顿-欧拉迭代动力学算法
  14. 属牛人性格特点及脾气如何呢?
  15. 行测测评(二)——图形找规律技巧
  16. 亚马逊Amazon SP-API注册申请和授权对接开发和亚马逊SP-API开发人员注册资料的注意事项,PII申请的事项
  17. 归并排序的python实现:递归与非递归
  18. 2017AP计算机科学5分线,2017各国际学校AP分数大比拼,看看你是啥水平
  19. 全景虚拟漫游实现(three.js)
  20. Windows API详情

热门文章

  1. JWTToken在线编码生成
  2. Linux之iostat命令
  3. 《手机测试Robotium实战教程》——第2章,第2.2节Eclipse的安装
  4. 指针的指针指向指针数组的指针
  5. Centos7 下配置mysql5.6主从复制实例(一主两从)
  6. 正则表达式5-分组突击
  7. delphi listbox 使用
  8. Revip MEP二次开发之“连接弯头”
  9. 一个简单的samba案例(测试与思考)
  10. 【摘】蓝牙技术及其协议栈