LNMP编译安装

一、安装Nginx

    1、解决依赖关系,创建系统用户

[root@localhost ~]# yum -y groupinstall "Development Libraries" "Development Tools"
[root@localhost ~]# yum -y install openssl-devel pcre-devel
[root@localhost ~]# groupadd -r nginx
[root@localhost ~]# useradd -r -g nginx -s /sbin/nologin nginx

    2、开始编译安装

[root@localhost ~]# tar -zxvf nginx-1.6.1.tar.gz 
[root@localhost ~]# cd nginx-1.6.1
[root@localhost nginx-1.6.1]# ./configure \
   --prefix=/usr \
   --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/ \
   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
   --http-scgi-temp-path=/var/tmp/nginx/scgi \
   --with-pcre
[root@localhost nginx-1.6.1]# make && make install

    3、为Nginx提供启动脚本

[root@localhost ~]# vim /etc/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
[root@localhost ~]# chmod +x /etc/init.d/nginx 
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on

二、安装mysql,略过...

三、安装php,与Nginx结合只支持CGI方式运行,不支持模块话

    1、解决依赖关系

[root@localhost ~]# yum -y install libxml2-devel bzip2-devel

    libmcrypt-2.5.8-4.el5.centos.i386.rpm
    libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm
    mhash-0.9.9-1.el5.centos.i386.rpm
    mhash-devel-0.9.9-1.el5.centos.i386.rpm
    mcrypt-2.6.8-1.el5.i386.rpm

[root@localhost ~]# tar xf php-5.4.31.tar.gz 
[root@localhost ~]# cd php-5.4.31
[root@localhost php-5.4.31]# ./configure --prefix=/usr/local/php \
--with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets \
--enable-sysvshm  --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
--with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  \
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
--with-bz2 --with-curl
[root@localhost php-5.4.31]# make
[root@localhost php-5.4.31]# make install
[root@localhost php-5.4.31]# cp php.ini-production /etc/php.ini
[root@localhost php-5.4.31]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.4.31]# chmod +x /etc/init.d/php-fpm
[root@localhost php-5.4.31]# chkconfig --add php-fpm
[root@localhost php-5.4.31]# chkconfig php-fpm on
[root@localhost php-5.4.31]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost ~]# vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid
[root@localhost ~]# service php-fpm start
[root@localhost ~]# ps aux |grep php-fpm

    2、整合Nginx和php

[root@localhost ~]# vim /etc/nginx/nginx.conf
location / {
            root   html;
            index  index.php index.html index.htm;
        }
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; #/scripts指包含PHP文件的路径
            include        fastcgi_params;
        }
[root@localhost ~]# vim /etc/nginx/fastcgi_params
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

    3、测试php是否能正常工作

[root@localhost ~]# vim /usr/html/index.php 
<h1>Test Page</h1>
<?php
phpinfo();
?>


你可能感兴趣的:(nginx,PHP,LNMP)