1、    安装系统必要的工具
    [root@localhost lamp]# yum groupinstall "Development Tools" –y
    [root@localhost lamp]# yum groupinstall "Development Libraries" –y
    -----------------------------------------------------------------------
    //如果系统中没有“Development Libraries“, 安装下面的
    [root@localhost lamp]#yum groupinstall "Desktop Platform Development" -y
    [root@localhost lamp]#yum groupinstall "Server Platform Development" –y
    -----------------------------------------------------------------------
    //nginx需要的pcre
    [root@localhost lamp]# yum -y install pcre-devel
    //php需要的gd图片处理库
    [root@localhost lamp]# yum install -y libjpeg-turbo libjpeg-turbo-devel freetype freetype-devel libpng libpng-devel php-gd libxml2-devel bzip2-devel libcurl-devel
    //php需要的libcrypt
    [root@localhost lamp]# wget ftp://195.220.108.108/linux/centos/5.10/extras/i386/RPMS/libmcrypt-2.5.8-4.el5.centos.i386.rpm
    [root@localhost lamp]# wget ftp://195.220.108.108/linux/centos/5.10/extras/i386/RPMS/libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm
    (64位的
wget ftp://195.220.108.108/linux/centos/5.11/extras/x86_64/RPMS/libmcrypt-2.5.8-4.el5.centos.x86_64.rpm
wget ftp://195.220.108.108/linux/centos/5.11/extras/x86_64/RPMS/libmcrypt-devel-2.5.8-4.el5.centos.x86_64.rpm
    )
    [root@localhost lamp]# rpm -iv libmcrypt-2.5.8-4.el5.centos.i386.rpm libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm
2、安装mysql
    [root@localhost lamp]#tar –xzvf mysql-5.6.19-linux-glibc2.5-i686.tar.gz
    [root@localhost lamp]# cp mysql-5.6.19-linux-glibc2.5-i686 /usr/local/ -r
    [root@localhost lamp]# cd /usr/local
    [root@localhost local]# ln –sv mysql-5.6.19-linux-glibc2.5-i686 mysql
    [root@localhost local]# cd mysql
    [root@localhost mysql]# more INSTALL-BINARY  //可以查看安装过程
    [root@localhost mysql]# groupadd mysql
    [root@localhost mysql]#useradd –r –g mysql mysql
    [root@localhost mysql]# chown –R mysql:mysql .
    [root@localhost mysql]#scripts/msql_install_db –user=mysql –datadir=/usr/local/mysql/data
    [root@localhost mysql]# chown –R root .
    [root@localhost mysql]# chown –R mysql data
    [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
    [root@localhost mysql]# cp my.cnf /etc/my.cnf
    [root@localhost mysql]# vi /etc/my.cnf
#设置datadir
[mysqld]
    port            = 3306
    datadir         = /usr/local/mysql/data
    socket          = /tmp/mysql.sock
    skip-external-locking
    key_buffer_size = 16M
    max_allowed_packet = 1M
    table_open_cache = 64
    sort_buffer_size = 512K
    net_buffer_length = 8K
    read_buffer_size = 256K
    read_rnd_buffer_size = 512K
    myisam_sort_buffer_size = 8M
    //如果启动成功了就证明好了
    [root@localhost mysql]# /etc/init.d/mysqld start
    [root@localhost mysql]# /usr/local/mysql/bin/mysql –uroot
    mysql>SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123456');    
    [root@localhost mysql]# /usr/local/bin/mysqladmin –root –p “密码”
    [root@localhost mysql]# chkconfig –add mysqld //加入启动进程
3、安装php
    [root@localhost mysql]# cd /lamp
    [root@localhost lamp]# wget http://cn2.php.net/distributions/php-5.6.2.tar.gz
    [root@localhost lamp]# tar –xzvf php-5.4.30.tar.gz
    [root@localhost lamp]# cd php-5.4.30.
    [root@localhost php-5.6.2]# ./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/php/ \
    --with-config-file-scan-dir=/etc/php/php.d/ \
    --with-bz2 \
    --with-curl \
    --with-gd   \
    //64位,小于1G的内存需要加上这句
    --disable-fileinfo  
     [root@localhost php-5.6.2]# make && make install
     [root@localhost php-5.6.2]# cp php.ini-production /etc/php/php.ini
     [root@localhost php-5.6.2]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
     [root@localhost php-5.6.2]# chmod +x /etc/rc.d/init.d/php-fpm 
     [root@localhost php-5.6.2]# chkconfig --add php-fpm
     [root@localhost php-5.6.2]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf   
     [root@localhost php-5.6.2]# vim /usr/local/php/etc/php-fpm.conf
    #修改其内容
    pm.max_children = 150      //每个大概占内存20M
    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 php-5.6.2]# service php-fpm start
    #使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
    [root@localhost php-5.6.2]# ps aux | grep php-fpm
4、安装nginx
    [root@localhost php-5.6.2]# cd ../
    [root@localhost lamp]#  wget http://nginx.org/download/nginx-1.6.2.tar.gz
    [root@localhost lamp]# tar -xzvf nginx-1.6.2.tar.gz
    [root@localhost lamp]# cd nginx-1.6.2
    [root@localhost lamp]# groupadd nginx
    [root@localhost lamp]# useradd –r –g nginx nginx
    [root@localhost lamp]#./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 \   //需要支持python的web是需要开启
    --http-scgi-temp-path=/var/tmp/nginx/scgi \
    --with-pcre
    [root@localhost nginx-1.6.2]# make && make install
    [root@localhost nginx-1.6.2]#vim /etc/rc.d/init.d/nginx
    //为nginx提供SysV init脚本:
    //新建文件/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
    [root@localhost nginx-1.6.2]# chmod +x /etc/rc.d/init.d/nginx
    [root@localhost nginx-1.6.2]# chkconfig --add nginx
    [root@localhost nginx-1.6.2]# chkconfig nginx on
    [root@localhost nginx-1.6.2]# service nginx start
    [root@localhost nginx-1.6.2]# vim /etc/nginx/nginx.conf
     //修改location / {}
    Location / {
        root html ;
         index index.php index.html index.html ;        //修改这里
    }
    //在server里面追加这段
    location ~ \.php$ {
                  root           html;
                  fastcgi_pass   127.0.0.1:9000;
                  fastcgi_index  index.php;
                
                  fastcgi_connect_timeout 300;
                  fastcgi_send_timeout 300;
                  fastcgi_read_timeout 300;
                  fastcgi_buffer_size 256k;
                  fastcgi_buffers 16 256k;
                  fastcgi_busy_buffers_size 512k;
                  fastcgi_temp_file_write_size 512k;

                  fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                  include        fastcgi_params;
     }    
    //编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
    [root@localhost nginx-1.6.2]# 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;
    [root@localhost nginx-1.6.2]# service nginx reload
    [root@localhost nginx-1.6.2]# echo ‘< ?php echo phpinfo() ;?>’ > /usr/html/index.php
    //访问测试index.php是否解析

版权声明:未经博主允许不得转载。http://smister.com/post-22.html