群集架构LNMP
前言
-
LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python
-
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统
一:LNMP架构的部署(理论)
1.1:LNMP架构概述
-
LNMP平台就是 Linux、 Ngnix、 My SQL、PHP的组合架构,需要 Linux服务器、MysαL数据库、PHP解析环境
-
Ngnix特长:高并发,低资源,处理静态网络访问请求非常强
Apache:静态处理和动态处理都可以做,更适合做动态处理
Nginx将动态资源请求交给PHP当中的fpm处理动态请求
PHP主配置文件:php.ini
Nginx将动态资源分配给FPM或Apache
1.2:MySQL安装配置
- 为了与 Nginx、PHP环境保持一致,此处选择采用源代码编译的方式安装 My SQL组件
- MySQL部署的方法
编译安装 MySQL
优化调整初始化数据库
启动mysq服务并设置root数据库账号的密码
1.3:PHP解析环境的安装
-
配置网页动静分离,解析PHP,有两种方法可以选择
使用PHP的FPM模块
将访问PHP页面的Web请求转交给 Apache服务器去处理
-
较新版本的PHP已经自带FPM模块,用来对PHP解析实例进行管理、优化解析效率
FastCG将 Http Server和动态脚本语言分离开
Nginx专门处理静态请求,转发动态请求
PHP FPM专门解析PHP动态请求
单服务器的LNMP架构通常使用FPM的方式来解析PHP -
PHP编译安装步骤
-
编译安装PHP
编译选项时添加"- enable-fpm”以启用此模块
安装后的调整,主要是配置文件的建立与相应命令工具的路径优化
安装 Zend Guardloader(提高PHP解析效率),并进行加载配置
CGI还有跨平台的功能
1.4:配置Ngnx支持PHP环境
-
调用本机的php-fpm进程配置方法
建立FPM配置文件php- fpm. conf,修改配置选项,如:PD文件运行用户、服务进程数等
启动php-pm进程
-
在Ngnx的配置文件中的 serve}配置段配置将PHP的网页请求转给FPM模块处理
-
在Ngnx的配置文件中的 Server{}配置段配置将PHP的网页请求转给FPM模块处理
-
[root@localhost~]# vim /usr/local/nginx/conf/nginx.conf Server{ ... location ~\.php${ root /var/www/kgc; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; ...
1.5:常见的PHP开源产品介绍
-
Discuz!
-
康盛创想(北京困技有限公司推出的一套通用的社区论坛软件系统,如001年6月面世以来,是全球成熟度最高、覆盖率最大的论坛软件系统之一
-
PHPWind
PHPWind(简称:PW)是一个基于PHP和 MySQL的论坛程序,是国内最受欢迎的通用型论坛程序之一。 PHPWind的前身是onstar,发布于2004年, PHPWind由杭州德天信息技术有限公司开发,软件全面开源免费
二: Nginx 编译安装
2.1: 安装环境依赖包
[root@lnmp opt]# mkdir /opt/LNMP
[root@lnmp LNMP]# ls //上传压缩包
Discuz_X3.4_SC_UTF8.zip ncurses-5.6.tar.gz php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz
[root@lnmp LNMP]# tar zxvf nginx-1.12.2.tar.gz -C /opt
[root@lnmp nginx-1.12.2]# yum install -y gcc gcc-c++ zlib-devel pcre pcre-devel
2.2: 创建运行用户,组
[root@lnmp nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
2.3: 编译安装Nginx
[root@lnmp nginx-1.12.2]#
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
[root@lnmp nginx-1.12.2]# make && make install
2.4: 路径优化
- 为了使Nginx服务器的运行更加方便,可以为主程序nginx 创建链接文件,一遍管理员直接指向"nginx"命令就可以调用Nginx的主程序
[root@lnmp nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/ '//nginx命令执行路径优化'
[root@lnmp nginx-1.12.2]# ls -l /usr/local/bin
总用量 0
lrwxrwxrwx. 1 root root 27 8月 6 19:52 nginx -> /usr/local/nginx/sbin/nginx
2.5: 检查配置文件
[root@lnmp nginx-1.12.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@lnmp html]# nginx
[root@lnmp html]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14933/nginx: master
[root@lnmp html]# setenforce 0
[root@lnmp html]# iptables -F
本机浏览器可以访问
2.6: 进程管理
-
主程序Nginx支持标准的进程信号,通过kill或killall命令发送HUP信号表示重载配置,QUIT信号表示退出进程,KILL 信号表示杀死进程。例如,若使用killall命令,重载配置、停止服务的操作分别如下所示(通过“-s" 选项指定信号种类)
[root@localhost ~]# killall -s HUP nginx ###选项-s HUP等同于-1重新加载 [root@localhost ~]# killall -s QUIT nginx ###选项-s QUIT等同于-3停止服务
当Nginx进程运行时,PID 号默认存放在logs/目录下的nginx.pid文件中,因此若改用kill命令,也可以根据nginx.pid文件中的PID号来进行控制。
[root@lnmp html]# pkill nginx //关闭
[root@lnmp html]# netstat -ntap | grep nginx
[root@lnmp html]# nginx
[root@lnmp html]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15029/nginx: master
2.7: 添加systemctl 管理Nginx
- 为了使Nginx服务的启动、停止、重载等操作更加方便,可以编写基于CentOS 7.6的
Nginx服务控制文件使用systemctl工具来进行管理,CentOS7.6系统的管理习惯
[root@lnmp ~]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx '描述'
After=network.target '描述服务类别'
[Service]
Type=forking ''//后台运行形势''
PIDFile =/usr/local/nginx/logs/nginx.pid 'pid进程文件路径'
ExecStart=/usr/local/nginx/sbin/nginx '启动命令'
ExecReload=/usr/bin/kill -s HUP $MAINPID '重载命令'
ExecStop=/usr/bin/kill -s QUIT $MAINPID '停止命令,写绝对路径'
PrivateTmp=true
[Install]
WantedBy=multi-user.target '多用户模式'
[root@lnmp ~]# chmod 754 /lib/systemd/nginx.service '只有属主数组使用'
[root@lnmp ~]# systemctl enable nginx.service
2.8: 检查通过systemctl 命令能否正常 启动 停止 重启 重载Nginx服务
[root@lnmp html]# pkill nginx
[root@lnmp html]# netstat -ntap | grep nginx
[root@lnmp html]# systemctl start nginx
[root@lnmp html]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15086/nginx: master
2.9: 添加service 管理Nginx
[root@lnmp ~]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@lnmp init.d]# cd /etc/init.d/
[root@lnmp init.d]# chmod +x nginx
[root@lnmp init.d]# chkconfig --add nginx
[root@lnmp init.d]# chkconfig --level 35 nginx on
三: Nginx 应用
3.1: 访问统计
[root@lnmp ~]# vim /usr/local/nginx/conf/nginx.conf
......
43 location / {
44 root html;
45 index index.html index.htm;
46 }
47 location /status { '访问位置
48 stub_status on; '开启状态统计模块'
49 access_log off; '关闭此位置的访问日志'
50 }
[root@lnmp ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@lnmp ~]# service nginx stop
[root@lnmp ~]# netstat -ntap | grep nginx
[root@lnmp ~]# service nginx start
[root@lnmp ~]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19131/nginx: master
3.2: 基于域名的虚拟主机
[root@lnmp ~]# yum install -y bind
[root@lnmp ~]# vim /etc/named.conf
options {
listen-on port 53 { any; }; '改为any'
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; '改为any'
[root@lnmp ~]# vim /etc/named.rfc1912.zones "添加以下两端"
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
zone "benet.com" IN {
type master;
file "benet.com.zone";
allow-update { none; };
};
[root@lnmp ~]# cp -p /var/named/named.localhost /var/named/kgc.com.zone
www IN A 192.168.100.110 //添加
[root@lnmp ~]# cp -p /var/named/kgc.com.zone /var/named/benet.com.zone
[root@lnmp ~]# systemctl start named
[root@lnmp ~]# vim /usr/local/nginx/conf/nginx.conf
115 # location / {
116 # root html;
117 # index index.html index.htm;
118 # }
119 #}
120 server {
121 server_name www.benet.com;
122 location / {
123 root /var/www/benet;
124 index index.html index.php;
125 }
126 }
127 server {
128 server_name www.kgc.com;
129 location / {
130 root /var/www/kgc;
131 index index.html index.php;
132 }
133 }
134 } //注意这个大括号不是添加的,是 最上面 httpd { 所对应的
[root@lnmp ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@lnmp ~]# service nginx stop
[root@lnmp ~]# netstat -ntap | grep nginx
[root@lnmp ~]# service nginx start
[root@lnmp ~]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19484/nginx: master
3.3: 基于端口的虚拟主机
[root@lnmp fpm]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 8080;
server_name www.benet.com;
location / {
root /var/www/benet;
index index.html index.php;
}
}
server {
listen 80;
server_name www.kgc.com;
location / {
root /var/www/kgc;
index index.html index.php;
}
[root@lnmp fpm]# systemctl restart nginx
[root@lnmp fpm]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 15615/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15615/nginx: master
3.4: 基于IP的虚拟主机
环境配置双网卡 ens33 192.168.100.110 ens36 192.168.100.100
[root@lnmp ~]# vim /usr/local/nginx/conf/nginx.conf
......
server {
listen 192.168.100.100:8080;
server_name www.benet.com;
location / {
root /var/www/benet;
index index.html index.php;
}
}
server {
listen 192.168.100.110:80;
server_name www.kgc.com;
location / {
root /var/www/kgc;
index index.html index.php;
}
}
.....
[root@lnmp ~]# systemctl restart nginx
[root@lnmp ~]# netstat -anpt | grep nginx
tcp 0 0 192.168.100.100:8080 0.0.0.0:* LISTEN 16640/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 16640/nginx: master
3.5: 用户访问控制
[root@lnmp ~]# which htpasswd
/usr/bin/which: no htpasswd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@lnmp ~]# yum install -y httpd
[root@lnmp ~]# which htpasswd
/usr/bin/htpasswd
[root@lnmp ~]# htpasswd -c /usr/local/nginx/passwd.db tom
New password: //设置tom访问密码123456
Re-type new password:
Adding password for user tom
[root@lnmp ~]# vim /usr/local/nginx/conf/nginx.conf
........
server {
server_name www.benet.com;
location / {
auth_basic "secret"; '对benet设置访问限制'
auth_basic_usr_file /user/local/nginx/passwd.db; '访问的密码文件'
root /var/www/benet;
index index.html index.php;
}
}
server {
server_name www.kgc.com;
location / {
root /var/www/kgc;
index index.html index.php;
}
[root@lnmp ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
[root@lnmp ~]# service nginx stop
[root@lnmp ~]# netstat -natp |grep nginx
[root@lnmp ~]# service nginx start
[root@lnmp ~]# netstat -natp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20365/nginx: master: configuration file /usr/local/nginx/conf/nginx.conf test is successful
benet已经进行访问控制,而kgc没有访问限制
3.6: 用户访问拒绝
[root@lnmp ~]# vim /usr/local/nginx/conf/nginx.conf
......
server {
server_name www.kgc.com;
location / {
deny 192.168.100.10; '拒绝192.168.100.10'访问
allow all; '允许其他所有访问'
root /var/www/kgc;
index index.html index.php;
}
}
[root@lnmp ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@lnmp ~]# service nginx stop
[root@lnmp ~]# netstat -natp |grep nginx
[root@lnmp ~]# service nginx start
[root@lnmp ~]# netstat -natp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20481/nginx: master
四: MySQL 编译安装
4.1:MySQL概述
- MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),使用最常用的数据库管理语言–结构化查询语言(SQL)进行数据库管理。
- MySQL是开放源代码的,因此任何人都可以在General Public License的许可下下载并根据个性化的需要对其进行修改。
- MySQL是一个真正的多线程,多用户的SQL数据库服务,凭借其速度、可靠性和适应性而备受关注。大多数人都认为在不需要事务化处理的情况下,MySQL是管理内容最好的选择。
4.2:源码编译安装过程
4.2.1:安装MySQL环境依赖包
[root@lnmp htdocs]# yum install ncurses-devel ncurses bison cmake -y
'//ncurses-devel是字符终端下屏幕控制的基本库'
'//bison //函数库'
'//cmake跨平台编译安装工具'
4.2.2:创建运行用户
[root@lnmp ~ ]# useradd -s /sbin/nologin mysql '//添加用户,指定shell,禁止用户登录系统'
4.2.3:cmake配置 编译 安装
[root@lnmp mnt]# cd /opt/LNMP
[root@lnmp LNMP]# ls
Discuz_X3.4_SC_UTF8.zip ncurses-5.6.tar.gz php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz
[root@lnmp LAMP]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt
[root@lnmp LAMP]# cd /opt
[root@lnmp opt]# ls
LNMP mysql-5.7.20 nginx-1.12.2 rh
[root@lnmp opt]# cd mysql-5.7.20/
[root@lnmp mysql-5.7.20]# ls
.......
cmake
[root@lnmp mysql-5.7.20]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ '//指定路径'
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \ '//指定通信文件,连接数据库的必要文件'
-DSYSCONFIDIR=/etc \ '//指定配置文件目录'
-DSYSTEMD_PID_DIR=/usr/local/mysql \ 'PID进程号文件路径'
-DDEFAULT_CHARSET=utf8 \ '//指定字符集'
-DDEFAULT_COLLATION=utf8_general_ci \ '//指定字符集'
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ '//此行和下三行为存储引擎'
-DWITH_ ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysqI/data \ '//指定数据文件目录,由mysql用户管理'
-DWITH_BOOST=boost \ '//指定boost位置'
-DWITH_SYSTEMD=1 '//守护进程'
.....
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysqI/data \
-DWITH_BOOST= boost \
-DWITH_SYSTEMD=1
[root@lnmp mysql-5.7.20]# make
[root@lnmp mysql-5.7.20]# make install '这个过程大概需要半个多小时'
-----注意:如果在CMAKE的过程中有报错---
当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧
----注意: make: *** No targets specified and no makefile found. Stop.解决方法
1.wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses- 5.6.tar.gz
2.tar zxvf ncurses-5.6.tar.gz
3./configure -prefix= /usr/local -with- shared-without- debug
4.make
5.make install
4.2.4: 数据库目录进行调整
[root@lnmp mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql
4.2.5:调整配置文件
[root@lnmp mysql-5.7.20]# vim /etc/my.cnf '//将内容全部删除,添加以下内容'
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[root@lnmp mysql-5.7.20]# chown mysql:mysql /etc/my.cnf
4.2.6: 设置环境变量
[root@lnmp mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH'>> /etc/profile
[root@lnmp mysql-5.7.20]# echo 'export PATH' >> /etc/profile
[root@lnmp mysql-5.7.20]# source /etc/profile
4.2.7: 初始化数据库
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user= mysql \
--basedir=/usr/local/mysql \
--datadir= /usr/local/mysql/data
4.2.8:数据库开启自启,关闭,状态
[root@lnmp mysql]# systemctl enable mysqld
[root@lnmp mysql]# systemctl stop mysqld
[root@lnmp mysql]# netstat -ntap | grep 3306
[root@lnmp mysql]# systemctl start mysqld
[root@lnmp mysql]# systemctl status mysqld
[root@lnmp mysql]# netstat -ntap | grep 3306 '//应该查出来3306端口'
tcp6 0 0 :::3306 :::* LISTEN 23435/mysqld
4.2.9:设置MySQL密码;登陆
[root@lnmp mysql]# mysqladmin -u root -p password "abc123"
Enter password: '//刚开始没密码是空的直接回车,然后输入密码abe123,再次确认密码'
[root@lnmp mysql]# mysql -u root -p '//这个命令敲下,提示要输入密码,这个就是刚才设置的密码abc123'
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
4.3 Mysql5.6 与5.7的启动脚本与服务脚本对比
mysql 5.6的service服务脚本 mysql.server
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
mysql 5.7 的systemctl服务脚本 systemd.service
/usr/local/mysql/bin/mysqld/usr/lib/systemd/system/mysqld.service
cp /usr/local/mysql/bin/mysqld/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
mysql 5.6 的启动脚本 mysql.server
/usr/local/mysql/bin/mysqld_safe
mysql 5.7 的启动脚本 /usr/local/mysql/bin/mysqld
/usr/local/mysql/mysqld.pid
/usr/local/mysql/scripts/mysql_install_db 执行安装脚本入代码片
四: PHP编译安装
4.1:PHP概述
- PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域
- PHP支持绝大多数流行的数据库,在数据库层面的操作功能十分强大,而且能够支持Unix,Windows,Linux等多种操作系统
4.2:源码编译过程
4.2.1:安装依赖环境环境
[root@lnmp ~]# yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
4.2.2:configure配置
[root@lnmp LNMP]# ls
Discuz_X3.4_SC_UTF8.zip ncurses-5.6.tar.gz php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz
[root@lnmp LNMP]# tar xjvf php-7.1.10.tar.bz2 -C /opt/
[root@lnmp opt]# ls
LNMP mysql-5.7.20 nginx-1.12.2 php-7.1.10 rh
[root@lnmp php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
[root@lnmp php-7.1.10]# make && make install
4.2.3: 修改PHP的三个配置文件
- php有三个配置文件 php.ini核心配置文件 ; php-fpm.conf进程服务配置文件; www.conf 扩展配置文件
'核心配置文件php.ini'
[root@lnmp php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@lnmp php-7.1.10]# vim /usr/local/php/lib/php.ini
mysqli.default_socket =/usr/local/mysql/mysql.sock #1170行
date.timezone = Asia/Shanghai #修改时区
[root@lnmp php-7.1.10]# /usr/local/php/bin/php -m #检查哪些模块
'进程服务配置文件php-fpm.conf'
[root@lnmp php-7.1.10]# cd /usr/local/php/etc/
[root@lnmp etc]# cp php-fpm.conf.default php-fpm.conf
[root@lnmp etc]# vim php-fpm.conf
17 pid = run/php-fpm.pid //分号去掉,取消注释
'www.conf 扩展配置文件'
[root@lnmp etc]# cd /usr/local/php/etc/php-fpm.d/
[root@lnmp php-fpm.d]# cp www.conf.default www.conf
[root@lnmp etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini //开启php
[root@lnmp etc]# netstat -anpt | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 33066/php-fpm: mast
[root@lnmp etc]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@lnmp etc]# ps aux|grep -c "php-fpm"
4
'添加启动服务'
[root@lnmp fpm]# cp /opt/php-7.1.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lnmp fpm]# chmod +x /etc/init.d/php-fpm
[root@lnmp fpm]# chkconfig --add php-fpm
[root@lnmp fpm]# service php-fpm status
php-fpm (pid 10290) is running...
[root@lnmp fpm]# netstat -anpt |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 10290/php-fpm: mast
[root@lnmp fpm]# service php-fpm stop
Gracefully shutting down php-fpm . done
[root@lnmp fpm]# netstat -anpt |grep 9000
[root@lnmp fpm]# service php-fpm start
Starting php-fpm done
[root@lnmp fpm]# netstat -anpt |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 15451/php-fpm: mast
'让Nginx支持PHP功能'
[root@lnmp etc]# vi /usr/local/nginx/conf/nginx.conf
......
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
[root@lnmp html]# mv /usr/local/nginx/html/index.html /usr/local/nginx/html/index.html.bak '改后缀让系统无法识别'
[root@lnmp etc]# vim /usr/local/nginx/html/index.php
<?php
phpinfo()
?>
4.2.4:测试数据库工作是否正常
[root@lnmp html]# mysql -u root -p
Enter password: '输入上文设置的密码abc123'
mysql> CREATE DATABASE bbs;
mysql> GRANT all ON bbs.* To 'bbsuser'@'%' IDENTIFIED BY 'admin123';
mysql> GRANT all ON bbs.* To 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
mysql> flush privileges;
[root@lnmp html]# vi /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.100.110','bbsuser','admin123');
if($link) echo"<h1>Success!!</h1>";
else echo "Fail!!";
?>
五: 搭建Discuz论坛
5.1:解压论坛安装包
[root@lnmp LNMP]# cd /opt/LNMP
[root@lnmp LNMP]# unzip Discuz_X3.4_SC_UTF8.zip -d /tmp
[root@lnmp LNMP]# cd /tmp/dir_SC_UTF8/
[root@lnmp dir_SC_UTF8]# ls
readme upload utility
5.2:设置论坛权限
[root@lnmp dir_SC_UTF8]# cp -r upload /usr/local/nginx/html/bbs
[root@lnmp dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/
[root@lnmp bbs]# chown -R root:nginx ./config/
[root@lnmp bbs]# chown -R root:nginx ./data/
[root@lnmp bbs]# chown -R root:nginx ./uc_client/
[root@lnmp bbs]# chown -R root:nginx ./uc_server/
[root@lnmp bbs]# chmod -R 777 ./config/
[root@lnmp bbs]# chmod -R 777 ./data/
[root@lnmp bbs]# chmod -R 777 ./uc_client/
[root@lnmp bbs]# chmod -R 777 ./uc_server/
5.3:访问论坛
http://192.168.100.110/bbs/install/index.php
数据库服务器:localhost #本地架设就用 localhost,如果不是在本机上就要填写IP地址和端口
数据库名字户名:bbsuser
管理员账号:admin
密码:admin123
http://IP/bbs/admin.php//管理后台
账户:admin
密码:admin123
访问论坛 http://192.168.100.110/bbs/index.php
可以自己写帖子,自由发挥,LNMP搭建完毕