lnmp安装文档

环境:操作系统:centos 5.5 32位 服务器地址:192.168.1.101
      软件版本:pcre-8.12.zip  nginx-1.0.5.tar.gz  mysql-5.1.55.tar.gz  php-5.3.6.tar.gz
1 安装pcre
    unzip pcre-8.12.zip
    cd pcre-8.12
   ./configure
   make && make install
   cd ..
2 安装nginx
   useradd nginx -s /sbin/nologin
   tar -zxvf nginx-1.0.5.tar.gz
   cd nginx-1.0.5
   ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make && make install
3安装mysql
  参考我博客写的 mysql 安装文档
4 安装php准备工作
 a curl安装
   tar -zxvf curl-7.15.0.tar.gz
     cd curl-7.15.0
    ./configure --prefix=/usr/local/curl
    make && make install
 
 b expat安装
  tar -zxvf expat-2.0.1.tar.gz
  cd expat-2.0.1
  ./configure --prefix=/usr/local/expat
  make && make install

 c gzip安装
  tar -zxvf gzip-1.3.5.tar.gz
  cd gzip-1.3.5
   ./configure --prefix=/usr/local/gzip
   make && make install
 D.libxml2安装
   tar -zxvf libxml2-2.6.19.tar.gz
   cd libxml2-2.6.19
   ./configure --prefix=/usr/local/libxml2
   make && make install
  E.zlib安装
  tar -zxvf zlib-1.2.3.tar.gz
  cd zlib-1.2.3
  ./configure
  make && make install
  F.jpeg6安装
   mkdir -p /usr/local/jpeg6
   mkdir -p /usr/local/jpeg6/bin
   mkdir -p /usr/local/jpeg6/lib
   mkdir -p /usr/local/jpeg6/include
   mkdir -p /usr/local/jpeg6/man
   mkdir -p /usr/local/jpeg6/man1
   mkdir -p /usr/local/jpeg6/man/man1
   tar -zvxf jpegsrc.v6b.tar.gz
   cd jpeg-6b
   ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
    make && make install
  G.安装libpng
   tar -zxvf libpng-1.2.37.tar.gz
   cd libpng-1.2.37
   ./configure   //这个如同上面zlib的说明一样,不要带参数,让它默认安装到相应目录
   make && make install
  H 安装 freetype
   tar -zvxf freetype-2.3.5.tar.gz
    cd freetype-2.3.5
    mkdir -p /usr/local/freetype
     ./configure --prefix=/usr/local/freetype
    make && make install
   I  安装libmcrypt 加解密包(以免登陆phpmyadmin 报错)
   tar zxvf libmcrypt-2.5.7.tar.gz
   cd libmcrypt-2.5.7
   ./configure
   make  && make install
  J 安装fontconfig
  tar zxvf fontconfig-2.4.2.tar.gz
  cd fontconfig-2.4.2
  ./configure --prefix=/usr/local/fontconfig   --with-freetype-config=/usr/local/freetype/bin/freetype-config
  make && make install
   k 安装gettext-devel
   yum -y install gettext gettext-devel
  (如果不安装,make gd时报错 `AM_ICONV’ not found in library )
  L安装gd
  tar -zxvf gd-2.0.35.tar.gz
  cd gd-2.0.35
   ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg6/ --with-png --with-zlib --with-freetype=/usr/local/freetype/ --with-fontconfig=/usr/local/fontconfig
  make &&  make install
5 安装php
执行下面两个命令,以防编译php报错
cp /usr/local/mysql/bin/mysql_config  /usr/bin/mysql_config
ln -s /usr/local/mysql/include/mysql/mysql.h  /usr/include/
tar -zxvf php-5.3.6.tar.gz
cd php-5.3.6
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-gd=/usr/local/gd  --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-jpeg-dir=/usr/local/jpeg6/ --with-zlib-dir --enable-mbstring=all --with-pdo-mysql --with-freetype-dir=/usr/local/freetype --with-mcrypt --enable-sockets --enable-mbstring --enable-fpm
make && make install
# cp php.ini-production  /usr/local/php/etc/php.ini
# vi /usr/local/php/etc/php.ini
添加 date.timezone = Asia/Shanghai
更改 short_open_tag = Off 为short_open_tag = On (开启短格式支持)
更改expose_php = on 为expose_php = off (在curl中隐藏php版本号)
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vi /usr/local/php/etc/php-fpm.conf 取消以下;分号注释

1 ;pid = run/php-fpm.pid

2 ;pm.start_servers = 20

3 ;pm.min_spare_servers = 5

4 ;pm.max_spare_servers = 35

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig --levels 2345 php-fpm on
# service php-fpm start
6 整合php和nginx
#vi /usr/local/nginx/conf/nginx.conf 更改为如下内容:
user nginx nginx;
worker_processes 8;
error_log logs/error.log crit;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events
{
  use epoll;
 worker_connections 51200;
}
http
{
  include       mime.types;
  default_type  application/octet-stream;

  #charset  gb2312;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;

  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;
  server_tokens off;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

server
  {
    listen       80;
    server_name 192.168.1.101;
    index index.html index.htm index.php;
    root /data/web;
  location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;

      include fcgi.conf;
    }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }

log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
 access_log /usr/local/nginx/logs/webaccess.log access;

   location /nginxstatus {
 stub_status on;
    access_log   off;
           }
  }
}
在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/webserver/nginx/conf/fcgi.conf

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;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

7.测试配置文件
/usr/local/nginx/sbin/nginx -t
启动nginx并加入/etc/rc.d/rc.local开机自启动
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx

8.优化Linux内核参数

vi /etc/sysctl.conf 在末尾增加以下内容:

# Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog =  32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024  65535

使配置立即生效:

/sbin/sysctl -p

9.安装eaccelerator 优化php
tar -jxvf eaccelerator-0\[1\].9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
vi /usr/local/php/etc/php.ini
添加
extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
建立文件夹
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator

重启php
service php-fpm restart
10 测试

建立网站根目录
mkdir -p /data/web  上传 index.php(附件提供下载) 到 /data/web下, 在浏览器里输入 http://192.168.1.101/index.php看看效果吧 
 

 

你可能感兴趣的:(nginx,职场,LNMP,休闲)