Lnmp是一组常用于来搭建动态网站或者服务器的软件平台,由linux、nginx、mysql、php四个组件组成。
安装开发工具:Development tools、Server Platform Development、Additional 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 指出库文件的路径
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路径
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
- 创建一个mysql用户组和系统帐号
groupadd -r mysql
useradd -r -g mysql mysql
- yum --disablerepo=\* --enablerepo=c6-media remove mysql-libs移除
- 安装cmake ncurses-devel包
- tar -zxvf mysql-5.6.15.tar.gz -C /usr/local
- 进入/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
- make && make install
- [[email protected] ~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拷贝主配置文件
- [[email protected] mysql ]#cd support-files 进入目录
cp -p mysql.server /etc/init.d/mysql
15.[[email protected] support-files]# service mysql restart重启mysql
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
- [[email protected] mysql]# vim /etc/profile增加path变量
/usr/local/mysql/bin
- [[email protected] mysql]# . /etc/profile重新读取
进入数据库
- [[email protected] mysql]# mysqladmin -u root -p password ‘135983‘
- 把数据库加入启动
- echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf库文件输出
22.[[email protected] mysql]# cd /usr/includ
23.[[email protected] include]# ln -s /usr/local/mysql/include/ mysql头
24.[[email protected] 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
- [[email protected] ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/
- [[email protected] ~]# cd /usr/local/src/php-5.5.8/
- 编译
./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
- make && make install
5.[[email protected] php-5.5.8]# mkdir -pv /etc/php/
- [[email protected] php-5.5.8]# cp php.ini-production /etc/php/php.ini
- [[email protected] php-5.5.8]# cd sapi/fpm
- [[email protected] fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
- [[email protected] fpm]# chmod a+x /etc/init.d/php-fpm控制脚本权限
- [[email protected] fpm]# cd /usr/local/php/etc
- [[email protected] etc]# cp php-fpm.conf.default php-fpm.conf拷贝成配置文件
- [[email protected] etc]# service php-fpm start 重启php服务
- [[email protected] etc]# chkconfig --add php-fpm 加入启动阵列
- [[email protected] etc]# chkconfig php-fpm on
然后设置反向代理,将访问php相关页面时,反向代理至127.0.0.1 9000端口给php-fpm
- [[email protected] etc]# vim /etc/nginx/nginx.conf
打开反向代理,并修改如下
- [[email protected] etc]# cd /usr/local/nginx/html
- [[email protected] html]# vim index.php如下图
service nginxd restart
打开浏览器访问http://192.168.88.100/index.php
说明nginx与php已经结合在一起
4.[[email protected] html]#vim /usr/local/apache/htdocs/index.php如下
Service httpd restart
Service mysql restart
打开浏览器访问http://192.168.88.100/index.php
说明通过php已经连接数据库
压力测试:
vim /usr/local/nginx/html/index.php如下图
ab -n 10000 -c 1000 http://127.0.0.1/index.php
安装xcache:
- [[email protected] ~]# tar -zxvf xcache-3.1.0.tar.gz /usr/local/src
- [[email protected] ~]#cd /usr/local/src/xcache-3.1.0
- [[email protected] xcache-3.1.0]# /usr/local/php/bin/phpize
- [[email protected] xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config 编译
- [[email protected] xcache-3.1.0]# make && make install 安装
- [[email protected] xcache-3.1.0]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
进入目录查看下模块
7.[[email protected] no-debug-non-zts-20121212]# ls
opcache.a opcache.so xcache.so
8.[[email protected] no-debug-non-zts-20121212]# cp xcache.so /etc/php5.d/ 把模块移动到php5.d目录下
9.[[email protected] no-debug-non-zts-20121212]# cd/usr/local/src/xcache-3.1.0
10.[[email protected] xcache-3.1.0]# cp xcache.ini /etc/php5.d/
拷贝配置文件
service php-fpm restart
打开浏览器访问http://192.168.88.100/index.php
xcache是否加载成功。
明显增加!