源碼編譯安裝LNMP環境及配置基於域名訪問的多虛擬主機

實驗環境及軟件版本:

CentOS版本: 6.6(2.6.32.-504.el6.x86_64)

nginx版本: nginx-1.6.2

mysql版本:  Mysql-5.6.23

php版本:    php-5.6.3


一、關閉防火牆:service iptables stop

                chkconfig iptables off

二、關閉selinux: sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

                 init 6 重啓系統一定要!

三、nginx安裝

1.安裝準備

  

  a.mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup  

  b.wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

  c. pcre:yum -y install pcre pcre-devel

  d. openssl:yum -y install openssl openssl-devel


2.安裝nginx


  a.tar xf nginx-1.6.2.tar.gz

  b.cd nginx-1.6.2, useradd nginx -s /sbin/nologin -M

  c. ./configure --prefix=/application/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module --user=nginx --group=nginx

  d.[root@LNMP nginx-1.6.2]# echo $?

    0    代表編譯沒有任何錯誤

  e.make

  f.make install

  g.[root@LNMP nginx-1.6.2]# echo $?

    0    代表編譯沒有任何錯誤

  h.cd -,ln -s /application/nginx-1.6.2 /application/nginx

  i.編輯nginx.conf 

    cd /application/nginx/conf

    vi nginx.conf

    修改第2行的用戶名,用戶組名爲:nginx nginx,保存退出.

  

3.啓動nginx

[root@LNMP tools]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.2/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.2/conf/nginx.conf test is successful

出現以上提示,代表nginx安裝配置,語法等沒錯!

[root@LNMP tools]# /application/nginx/sbin/nginx

[root@LNMP tools]# netstat -lntup|grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3685/nginx          

[root@LNMP tools]# lsof -i:80

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   3685  root    6u  IPv4  13603      0t0  TCP *:http (LISTEN)

nginx   3686 nginx    6u  IPv4  13603      0t0  TCP *:http (LISTEN)

出現以上提示,代表nginx已成功運行!

[root@LNMP tools]# curl 192.168.0.111

curl後如果有內容,就代表nginx運行正常!


四、源碼安裝Mysql-5.6.23

       請移步:http://linuxzkq.blog.51cto.com/9379412/1584642,這裏不在描述


五、php安裝

    1.安裝依賴:

     yum install zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y

#確保devel安裝上X software development

   2.tar zxf libiconv-1.14.tar.gz

     cd libiconv-1.14

     ./configure --prefix=/usr/local/libiconv

     make

     make install


   3.libmcrypt

    wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz

    tar zxf libmcrypt-2.5.8.tar.gz 

    cd libmcrypt-2.5.8

    ./configure

    make

    make install


   4. libltdl

    cd libltdl/

    ./configure --enable-ltdl-install

    make

    make install

   5.mhash

    wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz

    tar zxf mhash-0.9.9.9.tar.gz

    cd mhash-0.9.9.9/

    ./configure

    make

    make install

rm -f /usr/lib64/libmcrypt.*

rm -f /usr/lib64/libmhash*

ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la

ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so

ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4

ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8

ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a

ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la

ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so

ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2

ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config


   6.mcrypt

    centos6.5/6.6 x86_64

    wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz

    tar zxf mcrypt-2.6.8.tar.gz

    cd mcrypt-2.6.8/

    ./configure LD_LIBRARY_PATH=/usr/local/lib

    make

    make install

    cd ../


   7.php安裝

   tar xf php-5.6.3.tar.gz

   cd php-5.6.3

   ./configure \

   --prefix=/application/php-5.6.3 \

   --with-mysql=/application/mysql \

   --with-iconv-dir=/usr/local/libiconv \

   --with-freetype-dir \

   --with-jpeg-dir \

   --with-png-dir \

   --with-zlib \

   --with-libxml-dir=/usr \

   --enable-xml \

   --disable-rpath \

   --enable-safe-mode \

   --enable-bcmath \

   --enable-shmop \

   --enable-sysvsem \

   --enable-inline-optimization \

   --with-curl \

   --with-curlwrappers \

   --enable-mbregex \

   --enable-fpm \

   --enable-mbstring \

   --with-mcrypt \

   --with-gd \

   --enable-gd-native-ttf \

   --with-openssl \

   --with-mhash \

   --enable-pcntl \

   --enable-sockets \

   --with-xmlrpc \

   --enable-zip \

   --enable-soap \

   --enable-short-tags \

   --enable-zend-multibyte \

   --enable-static \

   --with-xsl \

   --with-fpm-user=nginx \

   --with-fpm-group=nginx \

   --enable-ftp


出現錯誤:Don't know how to define struct flock on this system, set --enable-opcache=no

這是安裝php 5.5時的錯誤,同樣適用5.6.3

解決辦法如下:

編輯 /etc/ld.so.conf 加入/usr/local/lib

再執行 ldconfig即可


出現錯誤:提示沒有安裝libxslt,請安裝libxslt

yum -y install libxslt*


出現警告:configure: WARNING: unrecognized options: --enable-safe-mode, --with-curlwrappers, --enable-zend-multibyte


    上面的警告提示是說:上面的參數已經去除了,說明上述這些參數廢棄了,php-5.6.3 已經去掉了該選項,編譯時可以 #./configure --help | grep “safe-mode” 查看一下,沒有信息輸出,表示已經不支持!


出現錯誤:make: *** [sapi/cli/php] Error 1


決方法:make ZEND_EXTRA_LIBS='-liconv'

ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/

make install


ln -s /application/php-5.6.3/ /application/php

cp php.ini-production /application/php/lib/php.ini

    8.整合nginx和php

    cd /application/php/etc/

    mv php-fpm.conf.default  php-fpm.conf

    編輯php-fpm.conf 

    cd /application/php/etc

    vi php-fpm.conf

    修改裏面的用戶名,用戶組名爲:nginx nginx(user=nobody group=nobody改成user=nginx group=nginx),保存退出.

     重點注意:php-fpm.conf文件裏面的用戶名,用戶組名一定要和nginx.conf文件裏面的用戶名,用戶組名統一,否則會出錯!

     /application/php/sbin/php-fpm -t

     /application/php/sbin/php-fpm

    [root@LNMP ~]# netstat -lntup|grep php-fpm

    tcp        0      0 127.0.0.1:9000        0.0.0.0:*          LISTEN     14801/php-fpm       ==============成功標誌==================

    9.加入開機自啓動

    

    cat >>/etc/rc.local<<EOF

    /etc/init.d/mysqld start

    /application/php/sbin/php-fpm

    /application/nginx/sbin/nginx

    EOF


    六.定義虛擬機:

    1. cd  /application/nginx/conf

     mkdir vhost

     cd vhost

     vi www.etiantian.org.conf

     加入以下內容:

     

server {

        listen 80;

        server_name www.etiantian.org;

        root /web/www;

        index index.php index.html index.htm;

        location ~* \.php$ {

           fastcgi_index   index.php;

           fastcgi_pass    127.0.0.1:9000;

           include         fastcgi_params;

           fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;

           fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

            }

                }

      保存退出,其他兩個虛擬主機定義和以上類同,不再敘述.

      編輯nginx.conf:

      vi nginx.conf

     在http模塊裏面的第一個server標籤前加入include vhost/*.conf開啓nginx的虛擬機功能

     在根目錄創建虛擬機根目錄:mkdir /web/{bbs,blog,www}

     給nginx授權讀取執行虛擬機根目錄的權限:chown -R nginx:root /web


    2. 測試LNMP是否成功:

     cd /web/www             

     vi phpinfo.php

     <?php

     phpinfo();

     ?>

     保存退出,給予虛擬機讀取運行phpinfo.php文件的權限

     chown -R nginx:root /web

     在windows客戶端的hosts文件裏做好IP和域名的映射,訪問www.etiantian.org後,如果出現PHP紫色      的配置界面,訪問正常;如不正常,現給出以下排障方法      及步驟:

     

     windows瀏覽器訪問:

     排錯三步曲:

     1)ping 192.168.0.111 物理網絡通不通

     2)telnet 192.168.0.111 80 瀏覽器到web服務通不通

     3)服務器本地curl 192.168.0.111 web服務開沒開


     希望能給大家有所幫助,通過我分享的筆記,如有遺漏之處歡迎拍磚!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章