Linux下源碼安裝lnmp

 
Nginx(發音同 engine x)是一款輕量級的Web 服務器/反向代理服務器及電子郵件(IMAP/POP3)代理服務器,並在一個BSD-like 協議下發行。由俄羅斯的程序設計師Igor Sysoev所開發,最初供俄國大型的入口網站及搜尋引擎Rambler(俄文:Рамблер)使用。 其特點是佔有內存少,併發能力強,事實上nginx的併發能力確實在同類型的網頁伺服器中表現較好.目前中國大陸使用nginx網站用戶有:新浪、網易、 騰訊,另外知名的微網誌Plurk也使用nginx。
這個來自俄羅斯的Web服務器(Nginx)儼然已經成爲了該領域的一匹黑馬,目前每天新增的一百萬網站中有超過100個網站使用Nginx。Nginx獲得的這些市場份額來自於其他Web服務器,其中大部分是從Apache轉過來的。
據統計,流量高的網站更喜歡使用Nginx,前1000個頂級網站中,有23.9%的網站使用的是Nginx。這包括許多廣爲人知的網站,如Wordpress.com、Tumblr.com、Sourceforge.net、Archive.org和Dropbox.com等。
一.安裝nginx
必要的編譯環境
Development Libraries 開發的庫文件
Development Tools  開發的工具
Legacy Software Development 傳統的開發工具
X Software Development 圖形化的軟件開發工具
GNOME Software Development gnome桌面下的軟件開發工具
KDE Software Development kde桌面下的軟件開發工具
 
1.解決依賴性關係
首先掛載光盤文件
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
搭建好安裝環境,解決依賴性關係,可在圖形界面下操作,如下
wps_clip_p_w_picpath-10798
安裝 pcre,系統自帶的 pcre 版本過低,不能滿足我們的需求。 pcre 是一個正則表達式相關的包,要想 Nginx 使用 Rewrite,那麼就需要正則的支持。
[root@localhost ~]# yum -y install pcre-devel
2.安裝
[root@localhost ~]# tar -zxvf nginx-1.0.11.tar.gz
[root@localhost ~]# cd nginx-1.0.11
添加用戶組及用戶nginx
[root@localhost nginx-1.0.11]# groupadd  -r  nginx       
[root@localhost nginx-1.0.11]# useradd -r -g nginx -s /bin/false  -M nginx
開始編譯和安裝
[root@localhost nginx-1.0.11]# ./configure \
   --prefix=/usr/local/nginx \
   --sbin-path=/usr/sbin/nginx \
   --conf-path=/etc/nginx/nginx.conf \    
   --error-log-path=/var/log/nginx/error.log \    
   --http-log-path=/var/log/nginx/access.log \    
   --pid-path=/var/run/nginx/nginx.pid  \  
   --lock-path=/var/lock/nginx.lock \
   --user=nginx \
   --group=nginx \
   --with-http_ssl_module \
   --with-http_flv_module \
   --with-http_stub_status_module \     --with-http_gzip_static_module \
   --http-client-body-temp-path=/var/tmp/nginx/client/ \
   --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 
   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
   --with-pcre
[root@localhost nginx-1.0.11]# make
[root@localhost nginx-1.0.11]# make install
3.爲nginx提供腳本並進行一些操作
[root@localhost nginx-1.0.11]# cd /etc/nginx/
[root@localhost nginx]# vim /etc/init.d/nginxd
#!/bin/sh
    #
    # nginx - this script starts and stops the nginx daemon
    #
    # chkconfig:   - 85 15
    # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
    #               proxy and IMAP/POP3 proxy server
    # processname: nginx
    # config:      /etc/nginx/nginx.conf
    # config:      /etc/sysconfig/nginx
    # pidfile:     /var/run/nginx.pid
    # Source function library.
    . /etc/rc.d/init.d/functions
    # Source networking configuration.
    . /etc/sysconfig/network
    # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit 0
    nginx="/usr/sbin/nginx"
    prog=$(basename $nginx)
    NGINX_CONF_FILE="/etc/nginx/nginx.conf"
    [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
    lockfile=/var/lock/subsys/nginx
    make_dirs() {
       # make required directories
       user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
       options=`$nginx -V 2>&1 | grep 'configure arguments:'`
       for opt in $options; do
           if [ `echo $opt | grep '.*-temp-path'` ]; then
               value=`echo $opt | cut -d "=" -f 2`
               if [ ! -d "$value" ]; then
                   # echo "creating" $value
                   mkdir -p $value && chown -R $user $value
               fi
           fi
       done
    }
    start() {
        [ -x $nginx ] || exit 5
        [ -f $NGINX_CONF_FILE ] || exit 6
        make_dirs
        echo -n $"Starting $prog: "
        daemon $nginx -c $NGINX_CONF_FILE
        retval=$?
        echo
        [ $retval -eq 0 ] && touch $lockfile
        return $retval
    }
    stop() {
        echo -n $"Stopping $prog: "
        killproc $prog -QUIT
        retval=$?
        echo
        [ $retval -eq 0 ] && rm -f $lockfile
        return $retval
    }
    restart() {
        configtest || return $?
        stop
        sleep 1
        start
    }
    reload() {
        configtest || return $?
        echo -n $"Reloading $prog: "
        killproc $nginx -HUP
        RETVAL=$?
        echo
    }
    force_reload() {
        restart
    }
    configtest() {
      $nginx -t -c $NGINX_CONF_FILE
    }
    rh_status() {
        status $prog
    }
    rh_status_q() {
        rh_status >/dev/null 2>&1
    }
    case "$1" in
        start)
            rh_status_q && exit 0
            $1
            ;;
        stop)
            rh_status_q || exit 0
            $1
            ;;
        restart|configtest)
            $1
            ;;
        reload)
            rh_status_q || exit 7
            $1
            ;;
        force-reload)
            force_reload
            ;;
        status)
            rh_status
            ;;
        condrestart|try-restart)
            rh_status_q || exit 0
                ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
            exit 2
esac
爲此腳本賦予執行權限
[root@localhost nginx]# chmod a+x /etc/init.d/nginxd
添加到服務器列表並設置爲開機啓動
[root@localhost nginx]# chkconfig  --add  nginxd
[root@localhost nginx]# chkconfig nginxd on
創建目錄"/www"和"/www/html"
[root@localhost nginx]# mkdir -pv /www/html
mkdir: 已創建目錄 “/www”
mkdir: 已創建目錄 “/www/html”
[root@localhost nginx]# vim  /etc/nginx/nginx.conf
wps_clip_p_w_picpath-17308
[root@localhost nginx]# cd  /www/html/
[root@localhost html]# vim  index.htm
<h1>Welcome to my Nginx Page!</h1> //將這些內容添加到index/html文件中       
4.啓動nginx服務並測試
[root@localhost html]# service  nginxd  start
啓動 nginx:                                               [確定]
[root@localhost html]#
在本地進行測試
wps_clip_p_w_picpath-24260
 
 
二.安裝Mysql
步驟如下
將軟件包解壓縮到/usr/local/目錄下
[root@localhost ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/
創建一個軟連接
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.5.15-linux2.6-i686 mysql
在mysql目錄下創建用戶和組
[root@localhost local]# cd mysql
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -g mysql -s /sbin/nologin -M mysql
修改目錄權限
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
安裝mysql數據庫
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# vim /etc/profile
wps_clip_p_w_picpath-32034
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
wps_clip_p_w_picpath-8185
重新加載系統庫文件
[root@localhost mysql]# ldconfig -v |grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -&gt; libmysqlclient_r.so.18.0.0
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
加入到系統服務列表並設置開機啓動
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
啓動mysql
[root@localhost mysql]# service mysqld start
Starting MySQL....                                         [確定]
三.安裝php
步驟如下:
[root@localhost ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/libevent-2.0.16-stable/
[root@localhost libevent-2.0.16-stable]# ./configure
[root@localhost libevent-2.0.16-stable]# make
[root@localhost libevent-2.0.16-stable]# make install
[root@localhost ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/src/
[root@localhost ~]# cd /usr/src/php-5.3.7/
[root@localhost php-5.3.7]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-libevent-dir=/usr/local --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr//local
[root@localhost php-5.3.7]# make ZEND_EXTRA_LIBS='-liconv'
[root@localhost php-5.3.7]# make install
[root@localhost php-5.3.7]#/usr/src/php-5.3.7/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
[root@localhost php-5.3.7]# ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
[root@localhost php-5.3.7]# cd /usr/local/php/etc/
[root@localhost etc]# cp -p php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd ../sbin/      
[root@localhost sbin]# ./php-fpm
修改配置文檔php-fpm.conf
[root@localhost sbin]# vim ../etc/php-fpm.conf
wps_clip_p_w_picpath-5455
測試,使Nginx和Php、Mysql進行關聯
[root@localhost ~]# vim /etc/nginx/nginx.conf
wps_clip_p_w_picpath-21679                       
[root@localhost ~]# cd /www/html/
[root@localhost html]# mv index.html index.php
[root@localhost html]# vim index.php
wps_clip_p_w_picpath-19861
重新啓動服務然後測試
[root@localhost html]# service nginxd restart
wps_clip_p_w_picpath-15940
這樣lnmp就搭建完成了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章