Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1250482
  • 博文数量: 220
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1769
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-13 16:19
个人简介

努力, 努力, 再努力

文章分类

全部博文(220)

文章存档

2018年(8)

2017年(46)

2016年(75)

2015年(92)

我的朋友

分类: PHP

2015-06-21 23:54:08


LNMP环境源码搭建(实测及排障)


参考 http://blog.csdn.net/stuartjing/article/details/8124491


 2

2

.2

 2

 2

 2

 3

 4

4

4

.

.

.

5

 5

5

5

............. 6

..............6

........................6

 ........................ 6

 .........................6

 .....................6

 ............8

 .........................8

9

 9

.........................

....

............................

. 环境描述

       1. linux系统环境: centos6.5 2.6.32-431.el6.x86_64

       2. nginx版本: nginx-1.8.0

       3. mysql版本: PHP 5.4.42 (cli)

       4. php版本: 5.0.95-log

. 安装步骤

      1. nginx的安装:

           (1) 安装编译工具和依赖包: 

      yum install make gcc gcc-c++ autoconf automake
      yum  -y install zlib-devel pcre-devel openssl-devel

           (2) nginx下载与解压: 

                     wget

                     tar -zxvf nginx-1.8.0.tar.gz

           (3)nginx预安装

                   cd nginx-1.8.0

              ./configure --prefix=/usr/local/nginx \  #指定nginx安装目录

              --with-openssl=/usr/include/openssl \   #启用openssl

              --with-pcre \               #启用正则表达式

              --with-debug \            #启用调试模式

              --with-http_stub_status_module   #启用查看nginx状态模块

              生成如下信息:


              creating objs/Makefile

              Configuration summary

            + using system PCRE library

            + using OpenSSL library: /usr/include/openssl

            + md5: using system crypto library

            + sha1: using system crypto library

            + using system zlib library

              nginx path prefix: "/usr/local/nginx"

            nginx binary file: "/usr/local/nginx/sbin/nginx"

            nginx configuration prefix: "/usr/local/nginx/conf"

            nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

            nginx pid file: "/usr/local/nginx/logs/nginx.pid"

            nginx error log file: "/usr/local/nginx/logs/error.log"

            nginx http access log file: "/usr/local/nginx/logs/access.log"

            nginx http client request body temporary files: "client_body_temp"

            nginx http proxy temporary files: "proxy_temp"

            nginx http fastcgi temporary files: "fastcgi_temp"

            nginx http uwsgi temporary files: "uwsgi_temp"

            nginx http scgi temporary files: "scgi_temp"

           (4) 编译及编译安装

              make && make install

           (5) 启动nginx

              /usr/local/nginx/sbin/nginx

           (6) 查看nginx

              lsof -i:80

       COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

       nginx   3824   root    6u  IPv4  59008      0t0  TCP *:http (LISTEN)

       nginx   3825 nobody    6u  IPv4  59008      0t0  TCP *:http (LISTEN)

      


      2. mysql的安装

           (1) 安装依赖包:

              yum -y install ncurses-devel   

              #ncurses包:提供字符终端处理库,包括面板和菜单。

           (2) mysql下载:

              wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.95.tar.gz

           (3) 解压mysql

                   tar zxvf mysql-5.0.95.tar.gz

           (4) 创建mysql用户

               useradd -M -s /sbin/nologin mysql

            (5) 预编译安装

         cd mysql-5.0.95
        ./configure --prefix=/usr/local/mysql \
        --without-debug \               # 取消调试模式提高性能
        --with-extra-charsets=utf8,gbk \    # 仅仅指定需要的默认字符集提高性能
        --enable-assembler \           # 使用汇编模式提高性能
        --with-mysqld-ldflags=-all-static \   # 以静态方式编译提高性能
        --with-client-ldflags=-all-static \   #以静态方式编译提高性能        
        --with-unix-socket-path=/tmp/mysql.sock \    # 使用unix socket提高性能
        --with-ssl
         配置成功,如下提示:
         Thank you for choosing MySQL!
         Remember to check the platform specific part of the reference manual
         for hints about installing MySQL on your platform.
         Also have a look at the files in the Docs directory.

           (5)编译及编译安装

              make && make install

           (6) 复制配置文件和脚本,并分配可执行权限

                   cp support-files/my-medium.cnf /etc/my.cnf

              cp support-files/mysql.server /etc/init.d/mysqld

              chmod +x /etc/init.d/mysqld

           (7) 设置软链接,为方便文件执行

        ln -s /usr/local/mysql/bin/* /usr/local/bin/ 
        ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/ 

            (8) 初始化数据库:

               mysql_install_db --user=mysql

            (9) 设置安装目录和数据库目录的属主和属组

        chown -R root.mysql /usr/local/mysql/   
        chown -R mysql.mysql /usr/local/mysql/var/  

            (10) 启动mysql数据库

                /etc/init.d/mysqld start

            (11) 设置mysql数据库

                mysqladmin -u root password 'xxxx'

           (12) 连接mysql

                   [root@slave mysql]# mysql -uroot -pxxxx

              Welcome to the MySQL monitor.  Commands end with ; or \g.

              Your MySQL connection id is 1

              Server version: 5.0.95-log Source distribution

              Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

              Oracle is a registered trademark of Oracle Corporation and/or its

              affiliates. Other names may be trademarks of their respective

              owners.

              Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

              mysql> quit

      3. php的安装

           (1) 安装依赖包

        yum -y install libxml2-devel curl-devel libpng-devel openldap-devel

           (2)安装源码依赖包

              (a)安装libmcrypt-2.5.8.tar.bz2

      wget \
        2.5.8/libmcrypt-2.5.8.tar.bz2

        tar -jxvf libmcrypt-2.5.8.tar.bz2
        cd libmcrypt-2.5.8
        ./configure
        make && make install

              (b) 安装mhash-0.9.9.9.tar.bz2

        wget \
        /mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
               tar -jxvf mhash-0.9.9.9.tar.bz2
        cd mhash-0.9.9.9
        ./configure

               make && make install

        # 这两个包安装完成后要把动态链接库做一个软连接到/usr/lib,
           以为接下来的mcrypt依赖于这两个包
        ln -s /usr/local/lib/libmcrypt* /usr/lib
        ln -s /usr/local/lib/libmhash.* /usr/lib/
        ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

              (c) 安装mcrypt-2.6.8.tar.gz

        wget \
        MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
        tar -zxvf mcrypt-2.6.8.tar.gz
        cd mcrypt-2.6.8
        ./configure

               make && make install

                  

              报错: ./configure时如下提示

              checking for libmcrypt - version >= 2.5.0... no

*** Could not run libmcrypt test program, checking why...

*** The test program compiled, but did not run. This usually means

*** that the run-time linker is not finding LIBMCRYPT or finding the wrong

*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you'll need to set your

*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point

*** to the installed location  Also, make sure you have run ldconfig if that

*** is required on your system

*** If you have an old version installed, it is best to remove it, although

*** you may also be able to get things to work by modifying LD_LIBRARY_PATH

configure: error: *** libmcrypt was not found

                  解决方法如下:运行 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

           (3) php5.4.42下载并解压

                   wget

              tar -zxvf php-5.4.42.tar.gz

              cd php-5.4.42

           (4)预编译安装

        ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --with-curl \
--with-curlwrappers --enable-fpm --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
         
         configure参数说明: 
         --prefix=/usr/local/php           指定php安装目录
               --with-mysql=/usr/local/mysql/     指定mysql安装目录, mysql的支持
         --with-zlib   打开zlib库的支持,用于http压缩传输
         --disable-rpath    关闭额外的运行库文件 
        --enable-bcmath    打开图片大小调整,用到zabbix监控的时候用到了这个模块
        --enable-shmop --enable-sysvsem  
        这样就使得你的PHP系统可以处理相关的IPC函数了
        --with-curl    打开curl浏览工具的支持
        --with-curlwrappers    运用curl工具打开url 
        --enable-fpm 打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序
        --with-mcrypt      mcrypt算法扩展
        --with-gd    打开gd库的支持
        --with-openssl      openssl的支持,加密传输https时用到的
        --enable-sockets     打开 sockets 支持
        --with-mhash        mhash算法扩展
        --with-ldap            支持ldap
        --with-ldap-sasl       支持Cyrus SASL认证的ldap
        --with-xmlrpc    打开xml-rpcc语言 
        --enable-zip   打开对zip的支持 
        --enable-soap  启用soap支持
        注意: --enable-safe-mode, --enable-fastcgi,参数已经去除不再使用
                 configure --help没有 --enable-xml这个参数
               来源php手册: 
               Fastcgi is the preferred SAPI to connect PHP and Lighttpd. Fastcgi is                     
               automagically enabled in php-cgi in PHP 5.3, but for older versions configure PHP with          --enable-fastcgi.

                 

              报错1: configure: error: Cannot find ldap libraries in /usr/lib

              解决办法如下:

         cp -frp /usr/lib64/libldap* /usr/lib/

                  

              (5)编译及编译安装

               make && make install


            警告1:

                make: warning:  Clock skew detected.  Your build may be incomplete.

                这个报错与系统时间有关,可能的原因: 系统时间与当前时间不符

4. 就配置php和nginx能运行php网站

      (1) 首先为php创建配置文件:

        cp php.ini-production /usr/local/php/php.ini
        cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
        ln -s /usr/local/php/bin/php /usr/bin/

      (2) 配置php-fpm,编辑php-fpm.conf

               vim /usr/local/php/etc/php-fpm.conf
        listen = /var/run/php-fpm/php-fpm.sock 
        listen.mode = 0666   #php-fpm.sock分配写权限

      (3) 启动php-fpm

               mkdir /var/run/php-fpm
        /usr/local/php/sbin/php-fpm
        fpm: FastCGI Process ManagerFastCGI进程管理器

      (4) 配置nginx,编辑nginx配置文件

               vim /usr/local/nginx/conf/nginx.conf

    修改nginx配置文件支持php:

    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.php index.html index.htm;    # 添加index.php的首页文件
        }
        # 添加下面内容
        location ~ \.php$ {
            fastcgi_pass        unix:/var/run/php-fpm/php-fpm.sock; 
            fastcgi_index       index.php;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            include fastcgi_params;
            include fastcgi.conf;
        }
         unix:/var/run/php-fpm/php-fpm.sock; 此处是使用unix socket
         也可以使用环回IP:  fastcgi_pass   127.0.0.1:9000;

            (5) 重启动nginx

        killall nginx
        /usr/local/nginx/sbin/nginx
         
         启动nginx时报错
         nginx: [emerg] "fastcgi_pass" directive is not allowed here in          /usr/local/nginx/conf/nginx.conf:68
         原因: /usr/local/nginx/conf/nginx.conf
         #location ~ \.php$ {      本行的注示符号 # 没有去掉导致,去掉即可

           (6) 创建测试页

                   在/usr/local/nginx/html下创建index.php

               vim /usr/local/nginx/html/index.php

                           


           (7) 在浏览器中查看测试页

                  

    


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