nginx是一个高性能,轻量级的HTTP和反射代理服务器,也是一个IMAP/POP3/SMTP代理服务器.基于事件驱动机制,主要特点:占用内存少,并发能力强,对处理静态页面更是有明显的效果.

 

1.下载和安装nginx软件

[root@node1 ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

[root@node1 ~]# tar xvf nginx-1.6.2.tar.gz

[root@node1 ~]# cd nginx-1.6.2

[root@node1 nginx-1.6.2]# yum install gcc gcc-c++ make pcre-* zlib-*     --安装链接库

[root@node1 nginx-1.6.2]# ./configure  --help | more             --查看详细参数

参数解释:

--with-rtsig_module                enable rtsig module        --with是使用此模块,默认为没有启用

--without-http_gzip_module         disable ngx_http_gzip_module     --without是禁用此模块,默认是启用

[root@node1 nginx-1.6.2]# groupadd  -g 501 nginx
[root@node1 nginx-1.6.2]# useradd -u 501 -g nginx -s /sbin/nologin -r nginx

[root@node1 nginx-1.6.2]# ./configure  --prefix=/usr/local/nginx-1.6.2 --user=nginx --group=nginx   --with-http_sub_module   --with-http_dav_module  --with-http_flv_module  --with-http_mp4_module

[root@node1 nginx-1.6.2]# make
[root@node1 nginx-1.6.2]# make install

[root@node1 nginx-1.6.2]# echo $?
0
[root@node1 nginx-1.6.2]# cd /usr/local/nginx-1.6.2/sbin/
[root@node1 sbin]# ll
total 2892
-rwxr-xr-x. 1 root root 2960527 Dec 27 23:37 nginx
[root@node1 sbin]# chown -R nginx:nginx /usr/local/nginx-1.6.2/

[root@node1 sbin]# ./nginx -h
nginx version: nginx/1.6.2
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx-1.6.2/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

[root@node1 sbin]# ./nginx
[root@node1 sbin]# netstat -antup | grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      5777/nginx         
[root@node1 sbin]# vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT    --添加防火墙

[root@node1 sbin]# /etc/init.d/iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
[root@node1 sbin]#

 

2.测试nginx服务是否正常启动

Centos 6.4用源代码安装LNMP环境 _Centos 6.4源代码安装LNMP环

 

3.安装mysql数据库软件

[root@node1 mysql-5.6.22]# yum install cmake ncurses-devel

[root@node1 mysql-5.6.22]# groupadd -g 502 mysql
[root@node1 mysql-5.6.22]# useradd  -u 502 -g mysql -s /sbin/nologin -r mysql
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.22.tar.gz

[root@node1 ~]# tar xvf mysql-5.6.22.tar.gz

[root@node1 mysql-5.6.22]# cd mysql-5.6.22

[root@node1 mysql-5.6.22]# chown -R root:root ../mysql-5.6.22

[root@node1 mysql-5.6.22]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.22

-DMYSQL_DATADIR=/usr/local/mysql-5.6.22/data

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8_general_ci

-DMYSQL_USER=mysql

-DMYSQL_GROUP=mysql

[root@node1 mysql-5.6.22]# make

[root@node1 mysql-5.6.22]# make install

[root@node1 mysql-5.6.22]# echo $?
0
[root@node1 mysql-5.6.22]# cd /usr/local/mysql-5.6.22/

[root@node1 mysql-5.6.22]# chown -R mysql:mysql data/

[root@node1 scripts]# vim /etc/my.cnf

datadir=/usr/local/mysql-5.6.22/data
basedir=/usr/local/mysql-5.6.22

[root@node1 scripts]# ./mysql_install_db --user=mysql --group=mysql

--datadir=/usr/local/mysql-5.6.22/data/ --basedir=/usr/local/mysql-5.6.22/ --defaults-file=/etc/my.cnf

[root@node1 scripts]# cp -a ../support-files/mysql.server  /etc/init.d/mysqld
[root@node1 scripts]# chkconfig --add mysqld
[root@node1 scripts]# chkconfig mysqld on
[root@node1 scripts]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL..... SUCCESS!
[root@node1 scripts]# vim /root/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/mysql-5.6.22/bin/    --加载环境变量

[root@node1 scripts]# . /root/.bash_profile      --使环境变量生效

[root@node1 scripts]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.22 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.22    |
+-----------+
1 row in set (0.00 sec)

mysql>

 

4.安装php软件

[root@node1 ~]# wget http://mirrors.sohu.com/php/php-5.4.28.tar.gz

[root@node1 ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

[root@node1 ~]# tar xvf libmcrypt-2.5.7.tar.gz

[root@node1 ~]# cd libmcrypt-2.5.7

[root@node1 libmcrypt-2.5.7]# ./configure  --prefix=/usr/local/libmcrypt

[root@node1 libmcrypt-2.5.7]# make

[root@node1 libmcrypt-2.5.7]# make install

[root@node1 libmcrypt-2.5.7]# cd ..

[root@node1 ~]# tar xvf php-5.4.28.tar.gz

[root@node1 ~]# cd php-5.4.28
[root@node1 php-5.4.28]# yum install libjpeg* libpng* freetype* libcurl-devel  libvpx-devel libxml2-devel libXpm-devel openldap-devel

[root@node1 php-5.4.28]# ./configure  --prefix=/usr/local/php-5.4.28 --enable-fpm --with-libxml-dir --with-zlib --with-curl --with-gd  --with-vpx-dir  --with-jpeg-dir  --with-png-dir  --with-zlib-dir  --with-xpm-dir  --with-iconv   --with-ldap --with-mcrypt=/usr/local/libmcrypt/  --with-mysql=/usr/local/mysql-5.6.22/ --with-mysqli=/usr/local/mysql-5.6.22/bin/mysql_config  --with-pdo-mysql  --with-freetype-dir

[root@node1 php-5.4.28]# make && make install

[root@node1 php-5.4.28]# cp -a php.ini-development  /usr/local/php-5.4.28/lib/php.ini

[root@node1 php-5.4.28]# cd /usr/local/php-5.4.28/etc/
[root@node1 etc]# cp -a php-fpm.conf.default  php-fpm.conf
[root@node1 etc]# cd ../sbin/
[root@node1 sbin]# ./php-fpm
[root@node1 sbin]# netstat -antup | grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      31387/php-fpm      
[root@node1 sbin]#

 

5.nginx和php相接合

[root@node1 sbin]# cd /usr/local/nginx-1.6.2/conf/
[root@node1 conf]# vim nginx.conf

user  nginx;      --使用nginx用户访问

location / {
        root   html;
        index  index.php index.html index.htm;    --添加index.php首页
  }

location ~ \.php$ {
       root           html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params;
 }

[root@node1 conf]# ../sbin/nginx -s reload
[root@node1 conf]# vim ../html/index.php

<?php
phpinfo();
?>

[root@node1 conf]#

 

6.打开测试页 

Centos 6.4用源代码安装LNMP环境 _Centos 6.4源代码安装LNMP环_02

 

7.安装php加速器(eaccelerator)

[root@node1 ~]# tar  xvf eaccelerator-eaccelerator-42067ac.tar.gz

[root@node1 ~]# cd eaccelerator-eaccelerator-42067ac
[root@node1 eaccelerator-eaccelerator-42067ac]# export PHP_PREFIX="/usr/local/php-5.4.28/"
[root@node1 eaccelerator-eaccelerator-42067ac]# setenforce 0
[root@node1 eaccelerator-eaccelerator-42067ac]# /usr/local/php-5.4.28/bin/phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[root@node1 eaccelerator-eaccelerator-42067ac]# ./configure --enable-eaccelerator=shared

--with-php-config=/usr/local/php-5.4.28/bin/php-config

[root@node1 eaccelerator-eaccelerator-42067ac]# make

[root@node1 eaccelerator-eaccelerator-42067ac]# make test

[root@node1 eaccelerator-eaccelerator-42067ac]# make install

[root@node1 eaccelerator-eaccelerator-42067ac]# ll /usr/local/php-5.4.28/lib/php/extensions/no-debug-non-zts-20100525/
total 380
-rwxr-xr-x. 1 root root 387940 Dec 28 03:27 eaccelerator.so
[root@node1 eaccelerator-eaccelerator-42067ac]# vim /etc/ld.so.conf
[root@node1 eaccelerator-eaccelerator-42067ac]# ldconfig  -v

[root@node1 eaccelerator-eaccelerator-42067ac]# vim /usr/local/php-5.4.28/lib/php.ini

zend_extension="/usr/local/php-5.4.28/lib/php/extensions/no-debug-non-zts-20100525/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.log_file = "/var/log/httpd/eaccelerator_log"
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"

[root@node1 eaccelerator-eaccelerator-42067ac]# /usr/local/php-5.4.28/sbin/php-fpm
[root@node1 eaccelerator-eaccelerator-42067ac]# /usr/local/nginx-1.6.2/sbin/nginx -s reload
[root@node1 eaccelerator-eaccelerator-42067ac]#

 

8.测试是否加载eaccelerator加速器

Centos 6.4用源代码安装LNMP环境 _Centos 6.4源代码安装LNMP环_03