原理

LNMP是一个基于CentOS/Debian编写的Nginx、PHP、MySQL,phpMyAdmin、eAccelerator一键安装包。可以在VPS、独立主机上轻松的安装LNMP生产环境。[1]

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

Mysql是一个小型关系型数据库管理系统。

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

特点 Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。

Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。

作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。

作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。

作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。

Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。

 

案例

 安装mysql

1.解压

[[email protected] ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/

2.切换目录

[[email protected] local]# cd mysql-5.5.15-linux2.6-i686/

3.查看安装说明

[[email protected] mysql-5.5.15-linux2.6-i686]# less INSTALL-BINARY

4.按步骤安装mysql

[[email protected] mysql]# groupadd mysql
[[email protected] mysql]# useradd -r -g mysql mysql
[[email protected] mysql]# cd /usr/local
[[email protected] local]# cd mysql
[[email protected] mysql]# chown -R mysql .
[[email protected] mysql]# chgrp -R mysql .

[[email protected] mysql]# scripts/mysql_install_db --user=mysql

[[email protected] mysql]# chown -R root .
[[email protected] mysql]# chown -R mysql data
[[email protected] mysql]# cp support-files/my-medium.cnf /etc/my.cnf

[[email protected] mysql]# bin/mysqld_safe --user=mysql &

5.

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

 LNMP搭建

6.

[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on

7.链接库文件

[[email protected] mysql]# cd /etc/ld.so.conf.d/
[[email protected] ld.so.conf.d]# vim mysql.conf

 LNMP搭建

8.链接头文件

LNMP搭建

安装php

1.解压

[[email protected] ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src/

2.检测执行./configure

[[email protected] php-5.4.6]#

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --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-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php --with-bz2 --with-curl

3.编译

[[email protected] php-5.4.6]#make

4.安装

[[email protected] php-5.4.6]# make install

5.配置php

[[email protected] php-5.4.6]# cp php.ini-production /etc/php/php.ini

[[email protected] php-5.4.6]# cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm

[[email protected] php-5.4.6]#chkconfig --add php-fpm
[[email protected] php-5.4.6]# chkconfig php-fpm on
[[email protected] php-5.4.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 

 安装pcre-devel

[[email protected] Server]# yum install pcre-devel

1.解压libevent

[[email protected] ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/

2.安装libevent

[[email protected] libevent-2.0.16-stable]# ./configure

 

[[email protected] libevent-2.0.16-stable]# vim /etc/ld.so.conf.d/libevent.conf

LNMP搭建

 

[[email protected] libevent-2.0.16-stable]# make

[[email protected] libevent-2.0.16-stable]# make install

 

安装nginx

[[email protected] ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src/

 

[[email protected] nginx-1.0.11]# groupadd  -r  nginx
[[email protected] nginx-1.0.11]# useradd -r -g nginx -s /bin/false  -M nginx

 

[[email protected] nginx-1.0.11]# ./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/ \
>  --with-pcre

 

[[email protected] nginx-1.0.11]# make

[[email protected] nginx-1.0.11]# make install

 

[[email protected] usr]# mkdir /var/tmp/nginx

 

7.启动ngnix

[[email protected] usr]# nginx

 

 

9.配置nginx

[[email protected] ~]# vim /etc/nginx/nginx.conf

LNMP搭建

LNMP搭建

LNMP搭建

 

10.测试

LNMP搭建