共计 8378 个字符,预计需要花费 21 分钟才能阅读完成。
LNMP 架构的搭建(Linux+Nginx+MySQL+PHP 源码安装)+Discuz 论坛的搭建
主机环境 RedHat6.5 64 位
实验环境 服务端 ip172.25.29.1 nginx+mysql+php
安装包 nginx-1.10.1.tar.gz
mysql-boost-5.7.11.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm
php-5.6.20.tar.bz2
re2c-0.13.5-1.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
Discuz_X3.2_SC_UTF8.zip
1. nginx 源码安装及配置
1. 安装
[root@server1 mnt]# yum install gcc -y #安装 gcc
[root@server1 mnt]# tar zxf nginx-1.10.1.tar.gz #解压 nginx 压缩包
[root@server1 mnt]# ls
nginx-1.10.1 nginx-1.10.1.tar.gz
[root@server1 mnt]# cd nginx-1.10.1
[root@server1 nginx-1.10.1]# vim auto/cc/gcc #禁止 debug 调试
178 # debug
179#CFLAGS=”$CFLAGS -g”
[root@server1 nginx-1.10.1]# vim src/core/nginx.h #禁止出现 nginx 版本号,以保证安全性
14 #defineNGINX_VER “nginx/”
[root@server1 nginx-1.10.1]# ./configure–prefix=/usr/local/lnmp/nginx –with-http_ssl_module–with-http_stub_status_module
如果出现以下错误
[root@server1 nginx-1.10.1]# yum install pcre-devel -y
重新配置
[root@server1 nginx-1.10.1]# ./configure –prefix=/usr/local/lnmp/nginx–with-http_ssl_module –with-http_stub_status_module
如果出现以下错误
[root@server1 nginx-1.10.1]# yum install openssl-devel -y
重新配置
[root@server1 nginx-1.10.1]# ./configure–prefix=/usr/local/lnmp/nginx –with-http_ssl_module –with-http_stub_status_module
[root@server1 nginx-1.10.1]# make
[root@server1 nginx-1.10.1]# make install
2. 将 nginx 作为系统变量,开启 nginx
[root@server1nginx-1.10.1]# cd /usr/local/lnmp/nginx/
[root@server1 nginx]# ls
conf html logs sbin
[root@server1 nginx]# ln -s /usr/local/lnmp/nginx/sbin/nginx/usr/local/sbin/ #作软链接将 nginx 的启动命令作为系统命令
[root@server1 nginx]# nginx -t #检测
nginx: the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conftest is successful
[root@server1 nginx]# nginx #打开 nginx
2. mysql 的源码安装及配置
1. 安装
[root@server1 mnt]#tar zxf mysql-boost-5.7.11.tar.gz #解压 gz 包
[root@server1 mnt]#yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y #安装 cmake
[root@server1 mnt]#cd mysql-5.7.11/
2 软件配置
[root@server1mysql-5.7.11]# 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 存储引擎
>-DDEFAULT_CHARSET=utf8 \ #使用 utf8 字符
>-DDEFAULT_COLLATION=utf8_general_ci \ #校验字符
>-DEXTRA_CHARSETS=all \ #安装所有扩展字符集
>-DWITH_BOOST=boost/boost_1_59_0/ #boost 的指定路径
如果出现如下错误
[root@server1mysql-5.7.11]# rm -fr CMakeCache.txt #清空缓存文件
[root@server1mysql-5.7.11]# yum install ncurses-devel gcc-c++ -y #安装上图需要的软件包
#### 注意:一定要清空缓存文件
重新配置
[root@server1mysql-5.7.11]# 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 -DWITH_INNOBASE_STORAGE_ENGINE=1-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all-DWITH_BOOST=boost/boost_1_59_0/
[root@server1mysql-5.7.11]# yum install bison -y #系统可以跳过 warning 错误,此步骤可有可无
[root@server1 mysql-5.7.11]# make #编译,链接,生成可执行文件
[root@server1 mysql-5.7.11]# make install #安装
2.mysql 的简单配置
[root@server1 mysql-5.7.11]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# useradd -u 27 -M -d /usr/local/lnmp/mysql/data -s/sbin/nologin mysql #创建 mysql 用户
[root@server1 mysql]#groupmod -g 27 mysql
[root@server1 mysql]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
[root@server1 mysql]# chown mysql.mysql . -R #修改 mysql 目录下文件的权限
[root@server1 mysql]# cp /etc/my.cnf /mnt/ #备份 my.cnf
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf #服务器配置文件
cp: overwrite `/etc/my.cnf’? y
[root@server1 support-files]# cp mysql.server/etc/init.d/mysqld #添加 mysql 启动命令
[root@server1 support-files]# cd ..
[root@server1 mysql]# cd bin/
[root@server1 bin]# pwd
/usr/local/lnmp/mysql/bin
[root@server1 bin]# vim /root/.bash_profile #将 mysql 添加到系统的环境变量里
10PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
[root@server1 bin]# source /root/.bash_profile #刷新环境变量文件
[root@server1 bin]# echo $PATH #查看 mysql 添加到环境变量
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/usr/local/lnmp/mysql/bin
[root@server1 bin]# which mysql #测试
/usr/local/lnmp/mysql/bin/mysql
[root@server1 ~]# mysqld –initialize –user=mysql #初始化 mysql
[root@server1 bin]# cd /usr/local/lnmp/mysql/
[root@server1 ~]# chown root . -R #改回权限
[root@server1 mysql]# chown mysql data/ -R
[root@server1 ~]# /etc/init.d/mysqld start #启动 mysql
Starting MySQL. SUCCESS!
[root@server1 ~]# mysql-p #登陆 mysql
Enter password: #密码是上一个截图里最后的 QV>6!r4LCyjw
3. php 的源码安装及配置
1. 安装
[root@server1 mnt# tar jxf php-5.6.20.tar.bz2 #解压
[root@server1 php-5.6.20]# rpm -vih libmcrypt-* #安装 libmcrypt 库
[root@server1 php-5.6.20]# yum installre2c-0.13.5-1.el6.x86_64.rpm –y #安装 re2c
[root@server1 php-5.6.20]# ./configure–prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc–with-openssl –with-snmp –with-gd –with-zlib –with-curl –with-libxml-dir–with-png-dir –with-jpeg-dir –with-freetype-dir –with-gettext–without-pear –with-gmp –enable-inline-optimization –enable-soap–enable-ftp –enable-sockets –enable-mbstring –with-mysqli –with-mysql–with-pdo-mysql –enable-fpm –with-fpm-user=nginx –with-fpm-group=nginx–with-mcrypt –with-mhash
如果出现如下错误
[root@server1 php-5.6.20]# yum install libxml2-devel -y
[root@server1 php-5.6.20]# ./configure–prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc–with-openssl –with-snmp –with-gd –with-zlib –with-curl –with-libxml-dir–with-png-dir –with-jpeg-dir –with-freetype-dir –with-gettext–without-pear –with-gmp –enable-inline-optimization –enable-soap–enable-ftp –enable-sockets –enable-mbstring –with-mysqli –with-mysql–with-pdo-mysql –enable-fpm –with-fpm-user=nginx –with-fpm-group=nginx–with-mcrypt –with-mhash
##### 注意:php 在加载配置过程中,如上面会报很多错误。有经验的可以根据报错自己去装所需要的包;新手可以参考前几篇博文,安装所需要的包
[root@server1 php-5.6.20]# make #编译
[root@server1 php-5.6.20]# make install #安装
2.php 的配置
[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
php-fpm.conf.default
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf #备份 php 的文件
[root@server1 etc]# ls
php-fpm.conf php-fpm.conf.default
[root@server1 etc]# cp /mnt/php-5.6.20/php.ini-productionphp.ini #php 的配置文件
[root@server1 etc]# ls
php-fpm.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php.ini
925 date.timezone = Asia/Shanghai #修改时区
1001 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock #指定连接数据库的 sock 文件的路径
1150 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock #同上
1209 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock #同上
[root@server1 etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid #将 pid 的标记去掉
[root@server1 etc]# cd /mnt/php-5.6.20/sapi/fpm/
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm #添加启动命令
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm #添加可执行权限
[root@server1 fpm]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2359 Sep 18 00:18 /etc/init.d/php-fpm
[root@server1 fpm]# /etc/init.d/php-fpm start #开启 php 服务
Starting php-fpm done
[root@server1 fpm]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf
51 root html;
52 index index.php index.html index.htm; #在 nginx 里添加默认访问目录为 php 优先
50 location / {
53 }
75 location ~ \.php$ {
76 root html;
77 fastcgi_pass 127.0.0.1:9000;
78 fastcgi_index index.php;
79 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
80 include fastcgi.conf; #设置成已存在的文件
81 }
[root@server1 conf]# nginx –t #检测
[root@server1 conf]# nginx #开启
4. 搭建 bbs 论坛
[root@server1 html]# unzip /mnt/Discuz_X3.2_SC_UTF8.zip -d/usr/local/lnmp/nginx/html/ #解压 Discuz 包
[root@server1 html]# ls
50x.html index.html index.php readme upload utility
[root@server1 html]# mv upload/ bbs/ #给 upload 文件重命名
[root@server1 html]# ls
50x.html bbs index.html index.php readme utility
[root@server1 html]# chmod 777 -R bbs/ #修改权限
[root@server1 html]# mysql –p
Enter password:
mysql> grant all on discuz.* to Discuz@localhost identifiedby ‘Red+hat888’; #创建能从论坛操作数据库的数据库用户
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
[root@server1 html]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# chmod 755 data/
LNMP 安装参考如下文章
Ubuntu 14.04 搭建 LNMP http://www.linuxidc.com/Linux/2015-05/116933.htm
Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL http://www.linuxidc.com/Linux/2014-05/102351.htm
Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm
在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm
Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-10/135978.htm