LNMP搭建

简介:

LNMP指的是在Linux系统下Nginx+MySQL+PHP这种网站服务器的架构.此时我们需用到nginx.Nginx 是一个高性能的 HTTP 和 反向代理服务器.作为 Web 服务器,和Apache相比,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率.当然Apache也有它自己的优点,比如功能丰富,稳定等等.今天主要介绍一下LNMP的实现.安装LNMP的过程和LAMP的类似,因此如果你会配置LAMP,相信这个就对你来说就不在话下了.

此处用到的软件版本为nginx-1.0.11.tar.gz mysql-5.0.77-3.el5和php-5.1.6-23.2.el5_3以下为安装过程:

(注:因为上篇博客里面已经介绍了lamp的安装搭建,所以今天就只介绍nginx的安装配置过程,mysql和php的源码安装过程请参考上篇博客lamp的搭建,不再赘述)

步骤:

安装nginx:

拷贝安装包:

image

 

解压libevent:

image

image

查看:

image

 

解压nginx:

image 

创建和账号:

image

配置:

image

编译make

安装make install

成功启动nginx:

image

 

测试》访问站点

image

将nginx和php进行整合以便使用:

进入文件/etc/nginx/nginx.conf 启动如下选项:

image

修改如下文件/etc/nginx/fastcgi_params:

image

修改文件/etc/nginx/nginx.conf:

image

为了使用起来更方便,我们为nginx提供SysV init脚本:

  #vim  /etc/rc.d/init.d/nginx  添加如下内容:

#!/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

然后执行如下操作:

image

到此LNMP平台已搭建成功 下面就可提供测试页面测试了

提供测试页面

# cat &gt; /usr/html/index.php <&lt; EOF

&lt;?php

phpinfo();

?>

用浏览器访问此页面测试LNMP是否能正常工作,到此lNMP已搭建成功

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