实验环境 :
RHEL6 x86-64 selinux and iptables disabled
****卸载原来系统中 httpd mysql php相关的文件
本文档将安装所有文件至 /usr/local/lnmp/ 目录下
一、安装mysql
(1)安装依赖包
# yum install -y cmake gcc make gcc-c++ ncurses-devel bison openssl-devel
(2)编译安装
#tar zxf mysql.******.tar.gz #cd #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 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all #make && make install
(3)配置mysql
#useradd mysql #cd /usr/local/lnmp/mysql #chown -R mysql.mysql * #cd scripts/ #./mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql/ --datadir=/usr/local/lnmp/mysql/data/
配置环境变量
#cd /usr/local/lnmp/mysql/bin/ #pwd /usr/local/lnmp/mysql/bin #vi ~/bash_profile PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin #source ~/.bash_profile
改变 data 目录权限
#cd /usr/local/lnmp/mysql/ #chown -R root * #chown -R mysql data/
添加启动脚本 && 配置文件
#cd support-files/ #cp mysql.server /etc/init.d/mysqld #cp my-medium.cnf /etc/my.cnf #/etc/init.d/mysqld start #mysql_secure_installation In order to log into MySQL to secure it, we'll need the current password for the root user.If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):第一次安装在这里直接按空格,下面开始设置mysql密码 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y
二、安装nginx
(1)安装pcre-devel && 添加nginx用户
#yum install -y pcre-devel openssl-devel #useradd nginx
(2)解压源码包 && 编译安装
#tar zxf nginx.*****.tar.gz #cd #./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx #make && make install
(3)配置nginx
#ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
(4)nginx 具体用法参考 http://wiki.nginx.org/NginxChs
三、安装php
(1)安装 libiconv 、 libmcrypt 、 mhash 、 mcrypt
libiconv
#tar zxf libiconv-1.13.1.tar.gz # ./configure --prefix=/usr/local/lnmp/phpmodule/libiconv #make && make install
libmcrypt
# tar jxf libmcrypt-2.5.8.tar.bz2 # ./configure --prefix=/usr/local/lnmp/phpmodule/libmcrypt #make && make install
mhash
#tar zxf mhash-0.9.9.9.tar.bz2 # ./configure --prefix=/usr/local/lnmp/phpmodule/mhash #make && make install
mcrypt ******安装的时候不指定安装路径,默认安装;或者指定安装路径,但是需要把 mhash 里面的 include 以及 lib 里面的文件做软连接到 /usr/local/include 和 /etc/local/lib 底下******
# tar zxf mcrypt-2.6.8.tar.gz #cd mcrypt-2.6.8 #ln -s /usr/local/lnmp/phpmodule/mhash/include/* /usr/local/include/ #ln -s /usr/local/lnmp/phpmodule/mhash/lib/* /usr/local/lib/ #vim /etc/ld.so.conf #ldconfig #./configure --prefix=/usr/local/lnmp/phpmodule/mcrypt \ --with-libmcrypt-prefix=/usr/local/lnmp/phpmodule/libmcrypt/ \ --with-libiconv-prefix=/usr/local/lnmp/phpmodule/libiconv/ #make && make install
编辑/etc/ld.so.conf
#cat << EOF > /etc/ld.so.conf /usr/local/lnmp/phpmodule/libiconv/lib /usr/local/lnmp/phpmodule/libmcrypt/lib /usr/local/lib
(2)安装php
安装依赖包
#yum install -y curl-devel gd-devel libjpeg-devel libxml2-devel gmp-devel net-snmp-devel
配置安装
#./configure --prefix=/usr/local/lnmp/php \ --with-config-file-path=/usr/local/lnmp/php/etc \ --with-mysql=/usr/local/lnmp/mysql \ --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config \ --with-openssl --with-snmp --with-gd --with-zlib \ --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir \ --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization \ --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm \ --with-fpm-user=nginx --with-fpm-group=nginx \ --with-mcrypt=/usr/local/lnmp/phpmodule/libmcrypt/ \ --with-mhash=/usr/local/lnmp/phpmodule/mhash/ \ --with-iconv-dir=/usr/local/lnmp/phpmodule/libiconv/ #make && make install
配置文件
#cd /usr/local/lnmp/php/etc/ #cp php-fpm.conf.default php-fpm.conf #vim php-fpm.conf pid = run/php-fpm.pid
启动文件 复制源码包中的 php-5.4.12/scripts/sapi/fpm/init.d.php-fpm
#cp init.d.php-fpm /etc/init.d/php-fpm #chmod +x /etc/init.d/php-fpm
#cd php-5.4.12 #cp php.ini-production /usr/local/lnmp/php/etc/php.ini #主配置文件 #vim php.ini date.timezone = Asia/Shanghai
四、搭建Discuz
(1) pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#cd /usr/local/lnmpp/nginx/conf #vim nginx.conf location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; } #nginx -t #nginx -s reload
(2) 下载 php-5.4.12.tar.bz2 源码包,解压
#mv upload/* /usr/local/lnmp/nginx/html/bbs/ #cd /usr/local/lnmp/nginx/html/bbs/ #chmod -R 777 config/ data/ uc_client/ uc_server/
(3)添加数据库用户
#mysql -p(root用户密码) mysql> create database discuz; mysql> grant all on discuz.* to discuz@localhost identified by '(root用户密码)'; mysql> quit
(4)web浏览器访问 Discuz!安装向导
_________至此,架站完成!!
思考:(1)LNMP搭建过程中 ‘憋’ 的最久的还是mhash编译,如果指定安装路径,那么就必须做相应的软链接,这样安装的时候才能找到对应的 .h .so 头文件等,这样做的目地就是为了以后使用的时候方便些;如果觉得麻烦,那么就直接解压->编译->安装,会直接成功的。不然会报错: configure: error: "You need at least libmhash 0.8.15 to compile this program. http:// mhash.sf.net/"
(2)编译安装mysql的时候,如果出错,要删除新生成的缓存文件,不然后边还是不能编译通过.