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就搭建完成了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章