lnmp的架构
lnmp架构为:linux +nginx +mysql+php/perl/python,我们将只用linux(rhel6.5)+nginx+mysql+php构建企业web架构
环境:RHEL6.5
iptables -F
selinux is disabled
注意:在搭建lnmp环境前,必须检测系统内部不能存在相关的软件:(纯净搭建)
#rpm -qa | grep php
#rpm -qa | grep httpd
#rpm -qa | grep mysql
1、nginx的源码编译安装:
nginx使用c编写,因此在编译的时候需要安装gcc和make
#yum install make gcc -y
#tar zxf nginx-1.4.2.tar.gz
#cd nginx-1.4.2/src/core/
#vim nginx.h
#define NGINX_VER "westos" 修改版本号,名称(每种版本都有bug)
#cd auto/cc/
#vim gcc
#CFLAGS="$CFLAGS -g" 注释debug功能,可以减少编译占用资源
#./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module
这时应该会缺少*-devel包,按照提示挨个安装即可。
#make && make install
#vim /usr/local/lnmp/nginx/conf/nginx.conf nginx主配置文件
events {
use epoll; #高效模式
worker_connections 1024;
}
创建软链接#ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin #便于启动和管理nginx
#nginx -t 检查nginx配置
#nginx -s reload 重新加载配置文件
#netstat -antlp | grep 80 检测nginx开放的80端口
这时通过firefox访问192.168.2.40(本机ip)就会看见welcome to nginx!
#curl -I localhost 会看到自己改的版本号
2.mysql的编译安装
#tar zxf mysql-5.5.12.tar.gz
#yum install cmake gcc-c++ -y
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql #安装目录
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \ #数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \ #Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \ #安装myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安装 innodb 存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ #安装 archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #安装 blackhole 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 \ #安装数据库分区
-DENABLED_LOCAL_INFILE=1 \ #允许从本地导入数据
-DWITH_READLINE=1 \ #快捷键功能
-DWITH_SSL=yes \ #支持SSL
-DDEFAULT_CHARSET=utf8 \ #使用utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \ #校验字符
-DEXTRA_CHARSETS=all \ #安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 \ #MySQL 监听端口(默认)
1)开始编译
在编译结束后会提示缺少相应的依赖包,按顺序安装
重新编译时,需要清除旧的对象文件和缓存信息 #rm -fr CMakeCache.txt
#make && make install
2) 初始化mysql
#useradd -M -d /usr/local/lnmp/mysql/data/ -s /sbin/nologin mysql
#cd /usr/local/lnmp/mysql
#chown -R mysql.mysql .
#cd /usr/local/lnmp/mysql/support-files
#cp mysql.server /etc/init.d/mysql
#cp my-medium.cnf /etc/my.cnf 根据你的主机内存复制 mysql 配置文件
#./mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql --datadir=/usr/loca/lnmp/mysql/data/
#cd /root
#vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
source ~/.bash_profile 让它生效
#cd /usr/local/lnmp/mysql/
#chown root * -R
#chown mysql -R data/ 只允许data/目录下的数据让mysql修改
#/etc/init.d/mysqld restart 启动mysqld开启3306
#chkconfig mysqld on
#mysql登录验证 mysql命令已经被加载到root用户的环境里了
# mysql_secure_installation 初始化mysql
3、php源码编译与安装
1)先安装所需的一些模块
#tar zxf libiconv-1.13.1.tar.gz 加强系统对支持字符编码转换的功能
#cd libiconv-1.13.1/
#./configure --prefix=/usr/local/lnmp/modules/libiconv/
#make && make install
#tar jxf libmcrypt-2.5.8.tar.bz2 mcrypt mhash 是php加密算法扩展库
#cd libmcrypt-2.5.8
#./configure --prefix=/usr/local/lnmp/modules/libmcrypt/
#make && make install
#cd libltdl
#./configure –libdir=/usr/local/lnmp/modules/libmcrypt --enable-ltdl-install
#make && make install
#cd
#tar jxf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure --prefix=/usr/local/lnmp/modules/mhsh/
#make && make install
#ldconfig /usr/local/lnmp/modules
#cd
#tar zxvf mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8/
#./configure --prefix=/usr/local/lnmp/modules/mcrypt/ --with-libmcrypt-perfix=/usr/local/lnmp/modules/libmcrypt/
#make && make install
提示不找不到libmcrypt
#ln -s /usr/local/lnmp/modules/libmcrypt/include/* /usr/local/
#ln -s /usr/local/lnmp/modules/libmcrypt/lib/* /usr/local/lib/
#ln -s /usr/local/lnmp/modules/mhash/lib/* /usr/local/lib /
#ln -s /usr/local/lnmp/modules/mhash/include/* /usr/local/include/
重新编译
#./configure --prefix=/usr/local/lnmp/modules/mcrypt --with-libmcrypt-prefix=/usr/loca/lnm/modules/libmcrypt/
#make && make install
# vim /etc/ld.so.conf 开机自动加载动态链接库文件
2)php的编译安装
#tar jxf php-5.3.6.tar.bz2
#cd php-5.3.6
#useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx
#yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel(这些是编译过程中所依赖的包,你也可以根据提示边编译边安装)
#ln -s /usr/local/lnmp/modules/libmcrypt/include/* /usr/local/include
#ln -s /usr/local/lnmp/modules/libmcrypt/lib/* /usr/local/lib
#./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/etc --with-mysql=/usr/local/lnmp/mysql/ --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx
#make ZEND_EXTRA_LIBS='-liconv'
#make install
3)配置php
#cd php-5.4.12 去主目录寻找主配置文件
#cp php.ini-production /usr/local/lnmp/php/etc/php.ini 主配置文件
#cd /root/php-5.4.12/sapi/fpm/
#cp init.d.php-fpm /etc/init.d/php-fpm
#vim /usr/local/lnmp/php/etc/php.ini
cgi.fix_pathinfo=0 防止nginx检查漏洞
date.timezone = Asia/Shanghai
#vim /usr/local/lnmp/php/etc/php-fpm.conf
user=nginx group=nginx
pid = run/php-fpm.pid
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
#/etc/init.d/php-fpm restart
#chkconfig php-fpm on
加载环境变量
#vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
#source ~/.bash_profile
4)修改nginx主配置文件让其支持php
#vim /usr/local/lnmp/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
indexindex.html index.htm index.php;
}
location ~ \.php$ { 以php结尾的交给本机的9000
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf; 包含fastcgi接口文件
}
}
重新加载nginx配置文件 #nginx -s reload
编写php测试文件
#vim /usr/local/lnmp/nginx/html/index.php
<?phpinfo()
?>
测试:http://192.168.2.40/index.php
4、Discuz论坛的搭建
download:Discuz_X2.5_SC_UTF8.zip
修改nginx先让执行index.php
#cd /usr/local/lnmp/nginx/conf
#vi nginx.conf
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
#nginx -t
#nginx -s reload
# unzip Discuz_X2.5_SC_UTF8.zip
# cp -r upload/ /usr/local/lnmp/nginx/html/bbs/
提示修改config/和data/需要可写权限# chown nginx config/ data/ -R
http://lnmp.xxb.com/bbs/ 提示什么安装什么
一般使uc_client/和uc_server/没有写权限 ,给需要的目录文件权限,权限不能给太大咯
# chown nginx -R uc_client/
# chown nginx -R uc_server/
这时登录192.168.2.40/bbs按照提示进行安装,安装完之后就能玩论坛了!