Lnmp是一组常用于来搭建动态网站或者服务器的软件平台,由linuxnginxmysqlphp四个组件组成。

安装开发工具:Development toolsServer Platform DevelopmentAdditional Development

源码安装nginx

1.yum --disablerepo=\* --enablerepo=c6-media install pcre-devel openssl-devel -y
2.groupadd -r nginx

3.useradd -r -g nginx nginx  创建帐号与组

4.tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/

5.tar -zxvf nginx-1.6.0.tar.gz -C /usr/local/src/

6.cd /usr/local/src

7.cd libevent-2.0.16-stable/

8.  ./configure --prefix=/usr/local/libevent

9.make && make install

10.vim /etc/ld.so.conf.d/libevent.conf 指出库文件的路径

WEB服务器搭建—lnmp_ lnmp 

11. ldconfig刷新

12.ldconfig -pv |grep libevent

13.cd /usr/local/src/nginx-1.6.0/

14.编译

./configure --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

15.make && make install

16.mkdir -pv /var/tmp/nginx/client/

17.vim /etc/profile   写出PATH路径

WEB服务器搭建—lnmp_web_02 

18.service iptables stop

19.setenforce 0

20.pkill -9 nginx

21.netstat -tupln |grep 80

22.nginx

23.vim /etc/init.d/nginxd编写一个启动脚本

源码安装Mysql数据库:下载mysql-5.6.15.tar.gz

  1. 创建一个mysql用户组和系统帐号

groupadd -r mysql

useradd -r -g mysql  mysql

  1. yum --disablerepo=\* --enablerepo=c6-media remove mysql-libs移除

  2. 安装cmake  ncurses-devel

  3.  tar -zxvf mysql-5.6.15.tar.gz -C /usr/local

  4. 进入/usr/local/mysql-5.6.15 

6.进行编译

cmake ./ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -

DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -

DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -

DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -

DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

  1. make && make install 

WEB服务器搭建—lnmp_ lnmp_03 

  1. [root@wangcf1009 ~l]#cd /usr/local/mysql    进入目录

   chown -R mysql:mysql .更改权限

./scripts/mysql_install_db --user=mysql 进行mysql的初始化安装

chown -R root .

chown -R mysql data/

cp my.cnf  /etc拷贝主配置文件

  1. [root@wangcf1009 mysql ]#cd support-files 进入目录

cp -p mysql.server /etc/init.d/mysql

15.[root@wangcf1009 support-files]# service mysql restart重启mysql

Shutting down MySQL.. SUCCESS! 

Starting MySQL. SUCCESS! 

  1. [root@wangcf1009 mysql]# vim /etc/profile增加path变量

/usr/local/mysql/bin

  1. [root@wangcf1009 mysql]# . /etc/profile重新读取

进入数据库

WEB服务器搭建—lnmp_ lnmp_04 

  1. [root@wangcf1009 mysql]# mysqladmin -u root -p password '135983'

  2. 把数据库加入启动

WEB服务器搭建—lnmp_web_05 

  1. echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf库文件输出

WEB服务器搭建—lnmp_ lnmp_06 

22.[root@wangcf1009 mysql]# cd /usr/includ

23.[root@wangcf1009 include]# ln -s /usr/local/mysql/include/ mysql头

24.[root@wangcf1009 include]# vim /etc/man.config 处理手册

增加:MANPATH  /usr/local/mysql/man

Mysql安装完毕!

源码安装PHP

yum --disablerepo=\* --enablerepo=c6-media install   libxml2-devel  libjpeg-turbo-devel  libpng-devel  freetype-devel

  1. [root@wangcf1009 ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/

  2. [root@wangcf1009 ~]# cd /usr/local/src/php-5.5.8/

  3. 编译

./configure  --prefix=/usr/local/php --enable-fpm   --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --

with-mysqli=/usr/local/mysql/bin/mysql_config  --enable-mbstring  --enable-xml  --with-png-dir --with-gd   --with-jpeg-

dir  --with-zlib  --with-freetype-dir --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php5.d

  1. make && make install

5.[root@wangcf1009 php-5.5.8]# mkdir -pv /etc/php/

  1. [root@wangcf1009 php-5.5.8]# cp php.ini-production /etc/php/php.ini

  2. [root@wangcf1009 php-5.5.8]# cd sapi/fpm

  3. [root@wangcf1009 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm    

  4. [root@wangcf1009 fpm]# chmod a+x /etc/init.d/php-fpm控制脚本权限

  5. [root@wangcf1009 fpm]# cd /usr/local/php/etc

  6. [root@wangcf1009 etc]# cp php-fpm.conf.default php-fpm.conf拷贝成配置文件

  7. [root@wangcf1009 etc]# service php-fpm start  重启php服务

  8. [root@wangcf1009 etc]# chkconfig --add php-fpm  加入启动阵列   

  9. [root@wangcf1009 etc]# chkconfig php-fpm on 

然后设置反向代理,将访问php相关页面时,反向代理至127.0.0.1 9000端口给php-fpm

  1. [root@wangcf1009 etc]# vim /etc/nginx/nginx.conf

打开反向代理,并修改如下

WEB服务器搭建—lnmp_web_07 

 

  1. [root@wangcf1009 etc]# cd /usr/local/nginx/html

  2. [root@wangcf1009 html]# vim index.php如下图

WEB服务器搭建—lnmp_web_08 

service nginxd restart

打开浏览器访问http://192.168.88.100/index.php

WEB服务器搭建—lnmp_ lnmp_09 

 

说明nginxphp已经结合在一起

4.[root@wangcf1009 html]#vim /usr/local/apache/htdocs/index.php如下

WEB服务器搭建—lnmp_ lnmp_10 

Service httpd restart 

Service mysql restart  

打开浏览器访问http://192.168.88.100/index.php

WEB服务器搭建—lnmp_web_11 

说明通过php已经连接数据库

 

压力测试:

vim /usr/local/nginx/html/index.php如下图

WEB服务器搭建—lnmp_ lnmp_12 

ab -n 10000 -c 1000 http://127.0.0.1/index.php

WEB服务器搭建—lnmp_ lnmp_13 

安装xcache

  1. [root@wangcf1009 ~]# tar -zxvf xcache-3.1.0.tar.gz /usr/local/src

  2. [root@wangcf1009 ~]#cd /usr/local/src/xcache-3.1.0

  3. [root@wangcf1009 xcache-3.1.0]# /usr/local/php/bin/phpize

  WEB服务器搭建—lnmp_web_14

  1. [root@wangcf1009 xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config 编译

  2. [root@wangcf1009 xcache-3.1.0]# make && make install 安装

  3. [root@wangcf1099 xcache-3.1.0]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/

 进入目录查看下模块

7.[root@wangcf1009 no-debug-non-zts-20121212]# ls

opcache.a  opcache.so  xcache.so

8.[root@wangcf1009 no-debug-non-zts-20121212]# cp xcache.so /etc/php5.d/  把模块移动到php5.d目录下

9.[root@wangcf1009 no-debug-non-zts-20121212]# cd/usr/local/src/xcache-3.1.0

10.[root@wangcf1009 xcache-3.1.0]# cp xcache.ini /etc/php5.d/

拷贝配置文件

service php-fpm restart

打开浏览器访问http://192.168.88.100/index.php

WEB服务器搭建—lnmp_web_15 

xcache是否加载成功。

WEB服务器搭建—lnmp_ lnmp_16 

明显增加!