目录
一.LNMP的概述
二.Nginx的安装
三.MySQL的安装
四.PHP的安装
五.Discuz的安装
systemctl start vsftpd //开启ftp服务
#使用wget工具从官网上下载nginx压缩包
wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压安装包,安装环境工具
tar zxvf nginx-1.12.2.tar.gz -C /opt
yum install gcc gcc-c++ pcre* zlib-devel make -y
创建nginx用户
useradd -M -s /sbin/nologin nginx
配置,安装且编译
cd /opt/nginx-1.12.2/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
#nigix运行的用户和组都为nginx
#启用http_stub_status_module模块以支持状态统计,便于查看服务器的连接信息
make && make install
优化服务控制,使用service工具控制服务
#为主程序nginx创建软链接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: -99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" //nginx主程序
PIDF="/usr/local/nginx/logs/nginx.pid" //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
#添加执行权限
chmod +x /etc/init.d/nginx
#添加为系统服务
chkconfig --add nginx
关闭防火墙,开启服务
systemctl stop firewalld
setenforce 0
service nginx start
验证服务是否开启
tar xzvf mysql-boost-5.7.20.tar.gz -C /opt
安装环境工具
#ncurses*字符终端处理工具
#bison mysql的语法编辑器
yum install ncurses ncurses-devel bison cmake autoconf -y
创建mysql的运行用户
useradd -s /sbin/nologin mysql
配置环境
cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //链接性文件
-DSYSCONFDIR=/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/mysql/data \ //数据存放位置
-DWITH_BOOST=boost \ //c++的运行库
-DWITH_SYSTEMD=1 //mysql主从复制的组件
make && make install
chown -R mysql:mysql /usr/local/mysql
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/mysql.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
设置环境变量
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
#声明为全局变量
echo 'export PATH' >> /etc/profile
#启动文件
source /etc/profile
初始化数据库
#初始化数据库
cd /usr/local/mysql/bin
mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /lib/systemd/system/
systemctl start mysqld.service
#验证服务是否开启
netstat -natp | grep 3306
mysqladmin -u root -p password
#如abc123等
mysql -u root -p
tar xjvf php-7.1.10.tar.bz2 -C /opt
#jpeg、png图片格式
#freetype字体
#xml网页格式
#zlib压缩工具
#curl文件的下载上传
#openssl安全验证
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
cd /opt/php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \ //指向mysql的sock文件
--with-mysqli \ //客户终端
--with-zlib \ //压缩工具
--with-curl \
--with-gd \ //图像化的处理
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \ //动态请求的模块
--enalbe-mbstring \ //多节点字符串
--enable-session \ //session会话
--enable-ftp \ //支持ftp服务
--enable-pdo \ //通用接口
--enable-tokenizer \ //函数库
--enable-zip //压缩格式
#编译且安装
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
#指定路径和时区
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
/usr/local/php/bin/php -m
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
#去掉注释
pid = run/php-fpm.pid
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -natp | grep 9000
ln -s /usr/local/php/bin/* /usr/local/bin/
vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
#指定站点目录
root html;
#FPM模块的位置
fastcgi_pass 127.0.0.1:9000;
#支持php的网页格式
fastcgi_index index.php;
#加载脚本类型和位置
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
#把nginx中的变量转化为php中的变量
include fastcgi_params;
}
vim /usr/local/nginx/html/index.php
systemctl restart nginx
#进入数据库
mysql -u root -p
#创建数据库和用户密码
CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
#刷新数据库
flush privileges;
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/
cd dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs
cd /usr/local/nginx/html/bbs/
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/