### 一 、搭建前期准备
1.服务器要求
```
1.操作系统Centos7.0以上 64位
2.服务器是否需要添加域名白名单(ip可以访问,域名不能访问)
3.开放所有端口(根据搭建后的实际情况开放对应端口)
```
2.服务器优先处理
生成软件包信息缓存
```shell
yum makecache
```
安装更新
```shell
yum update -y
```
安装必要软件
```shell
yum install -y zip unzip wget curl git vim zsh nano screen
```
安装oh my zsh(有助于补全和选择目录)
```shell
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
```
### 二、搭建LNMP环境
这里以一键包oneinstack为例
依次执行
```shell
wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz
tar xzvf oneinstack-full.tar.gz
cd oneinstack
./install.sh #注:请勿sh install.sh或者bash install.sh这样
```
执行`./install.sh`后,安装选项选择
```shell
1.设置SSH端口(默认22),回车即可
Do you want to enable iptables? [y/n]: n
2.然后选择是否安装 web,输入y
3.输入 1 安装 nginx
4.输入 3 不安装Apache
5.输入 5 不安装tomcat
6.然后选择是否安装数据库database,输入y
7.输入 2 安装mysql-5.7
8.然后输入数据库root密码123456(注:妥善保管)
9.然后输入1 选择从二进制安装
10.然后输入 y 安装PHP
11.输入 5 安装PHP7.2
12.输入 y 安装php 缓存插件
Do you want to instal opcode cache of the PHP? [y/n]:y
13.输入 1 安装Zend OPcache
14.Please select PHP extensions: 选择 fileinfo和Redis【这个地方特别注意】
15.输入 n 不安装Pure-FTPd
16.输入 y 安装phpMyAdmin
17.输入 y 安装redis-server
18.输入 n 不安装memcached-server
```
### 三、redis配置
配置redis密码
执行命令修改/usr/local/redis/etc/redis.conf文件,(也可以手动修改redis.conf文件)
```shell
echo requirepass redis的密码 >> /usr/local/redis/etc/redis.conf
```
重启redis
```shell
systemctl restart redis-server
```
注:service redis-server restart 在centos7.x中不支持
### 四、创建数据库
使用oneinstack一键搭建中的phpMyAdmin插件
```shell
vim /etc/my.cnf
在my.cnf 里面设置
[mysqld]下面添加语句
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
```
访问
http://你的ip地址/phpMyAdmin/

创建数据库用户名和数据库名,密码


上传之前,先解压web源码,导入数据库sql文件 (其中admin/visitor 是搭建完成后登陆网站后台的默认账号和密码)

### 五、web站点搭建
在oneinstack目录下添加虚拟机
```shell
cd ~/oneinstack
./vhost.sh
```
选项选择
```shell
1.选择1 ,Use HTTP Only
2.然后输入域名
3.输入网站的文件目录,直接回车就行
4.然后添加其他域名,有的话就输入 y ,没有就输入 n
5.是否添加防盗链,输入n
Do you want to add hotlink protection? [y/n]: n
6.Allow Rewrite rule? [y/n]: y
7.Allow Rewrite rule? [y/n]: y
Please input the rewrite of programme :
wordpress,opencart,magento2,drupal,joomla,laravel,thinkphp,discuz,typecho,ecshop rewrite was exist.
(Default rewrite: other): thinkphp
8.输入 y ,开启日志
Allow Nginx/Tengine/OpenResty access_log? [y/n]:y
```
nginx thinkphp 静态化
1、修改/usr/local/nginx/conf/rewrite/thinkphp.conf,
```shell
vim /usr/local/nginx/conf/rewrite/thinkphp.conf
```
文件内容如下;
```shell
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
```
修改为
```shell
location / {
if (!-e $request_filename) {
rewrite ^/([0-9]+)$ /home/show/index?roomnum=$1 last;
#rewrite ^/([0-9]+)$ /index.php?m=Show&a=index&roomnum=$1 last;
#rewrite ^(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
```
2、然后创建pathinfo.conf⽂文件
```shell
touch /usr/local/nginx/conf/pathinfo.conf
vim /usr/local/nginx/conf/pathinfo.conf
```
然后输入以下内容并保存
```shell
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "(.+?\.php)(/.*)") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
```
3、编辑 /usr/local/nginx/conf/vhost/您的域名.conf 文件,
```shell
vim /usr/local/nginx/conf/vhost/您的域名.conf
```
编辑文件如下
```shell
location ~ \.php {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
# include fastcgi_params;
include fastcgi.conf;
}
```
在include fastcgi.conf; 下⾯面加入一句
```shell
include pathinfo.conf;
```
4.修改网站根目录为public
```shell
server {
listen 80;
server\_name [www.abc.com;](http://www.abc.com;)
access\_log /data/wwwlogs/www.abc.com\_nginx.log combined;
index index.html index.htm index.php;
root /data/wwwroot/www.abc.com/public;
```
5.然后修改/usr/local/php/etc/php.ini,搜索cgi.fix\_pathinfo.把值从0改成1
```shell
vim /usr/local/php/etc/php.ini
cgi.fix_pathinfo=1
```
部署直播程序
1.将代码包里面的web文件夹中的东西拷贝到网站根目录。
举例说明:
假设您的站点为: www.abc.com
上传web端源码到网站根目录 比如 /data/wwwroot/www.abc.com/
然后unzip解压源码即可
```shell
#改变读写权限
chmod -R 775 /data/wwwroot/www.abc.com/
#改变所属者和所属组
chown -R www:www /data/wwwroot/www.abc.com
```
修改几个配置文件:
位置:/data/wwwroot/[www.abc.com](http://www.abc.com)/PhalApi/Config/app.php
内容
```php
'REDIS\_HOST' => "redis地址",
'REDIS\_AUTH' => "redis密码",
REDIS\_PORT'=>"6379"
七⽜相关配置
'Qiniu' => array(
//统⼀的key
'accessKey' => '七⽜accessKey',
'secretKey' => '七⽜secretKey',
//⾃定义配置的空间
'space\_bucket' => '七⽜空间名',
'space\_host' => '七⽜上传地址',
),
本地上传
'UCloudEngine' => 'local',
本地存储相关配置( UCloudEngine为local时的配置)
'UCloud' => array(
//对应的⽂件路径
'host' => 'http://域名/api/public/upload'
)
```
位置:/data/wwwroot/[www.abc.com](http://www.abc.com)/PhalApi/Config/dbs.php
内容
```php
'servers' => array(
'db_appapi' => array( //服务器标记
'host' => '数据库地址', //数据库域名
'name' => '数据库名', //数据库名字
'user' => '数据库⽤户名', //数据库⽤户名
'password' => '数据库密码', //数据库密码
'port' => '数据库端⼝号', //数据库端⼝
'charset' => '数据库编码', //数据库字符集
);
```
位置:/data/wwwroot/[www.abc.com](http://www.abc.com)/data/config/database.php
内容
```php
return array(
'type' => 'mysql',
'hostname' => '数据库地址',
'database' => '数据库名称',
'username' => '数据库账户',
'password' => '数据库密码',
'hostport' => '数据库端⼝',
'DB_PREFIX' => 'cmf_',
/* redis */
'REDIS_HOST' => "redis地址",
'REDIS_AUTH' => "redis密码",
'REDIS_PORT' => "redis端口",
);
```
注释掉这个文件【02-opcache.ini】的内容
```shell
/usr/local/php/etc/php.d/02-opcache.ini
```
这个PHP缓存,开发测试阶段需要关闭否则会影响问题的修改和测试偏差。
清理掉web缓存
/data/wwwroot/www.abc.com/data/runtime/目录下的文件清空
重启服务
```shell
systemctl restart php-fpm
systemctl restart nginx
systemctl restart redis-server
systemctl restart mysqld
```
### 六、nodejs部署
1.下载nvm一键安装脚本
```shell
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
```
2.查看~/.zshrc文件,会看到如下几⾏
```shell
#查看zshrc文件中是否添加
cat ~/.zshrc
#若没有,则手动添加
vim ~/.zshrc
#添加内容如下
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
```
3.重新载入配置文件
```shell
source ~/.zshrc
```
4.安装nodejs(安装最新稳定版 node)
```shell
nvm install stable
```
如果此命令安装失败,可以先`nvm ls `,先看下最新版本,然后直接安装最新版 `nvm install xxx`
5.输入如下命令,如果返回的是版本号,就说明nodejs安装成功
```shell
node -v
```
6.安装cnpm
注:只有国内服务器,才安装cnpm,执行下面的命令。国外服务器跳过.
```shell
npm install -g cnpm --registry=https://registry.npm.taobao.org
```
7.安装pm2
```shell
#国内服务器选执行如下
cnpm install pm2 -g
#国外服务器执行如下
npm install pm2 -g
```
8.安装nodejs拓展块
```
#删除原始node_modules文件
cd /data/wwwroot/www.abc.com(自己创建的站点)/node
rm -rf node_modules
#国外服务器使用
npm install
#国内服务器使用命令
cnpm inst
```
9.修改配置文件,将node目录下的config.js文件里面的信息修改为自己的
```shell
cd /data/wwwroot/www.abc.com(新建的站点)/node
vim config.js
#内容如下:
'REDISHOST' : 'redis地址',
'REDISPASS' : 'redis密码',
'REDISPORT' : '6379',
'TOKEN' : '1234567',
'WEBADDRESS': 'http://www.abc.com(自己的域名)/appapi/'
```
10.启动nodejs程序
```shell
pm2 start s1.js --watch
pm2 start exposure.js --watch
```
11.保存pm2启动信息
```shell
pm2 save
```
12.设置开机启动
```shell
pm2 startup
```
### 七、后台信息配置需要修改的地方
管理后台默认地址 http://你的域名/admin
管理后台默认账号 admin 默认密码 visitor
1.系统设置--->公共配置--->网站信息,修改为你自己的域名http://www.abc.com

2.系统设置--->私密设置--->直播配置,填写聊天服务地址,修改为http://www.abc.com:19967

3.系统设置--->私密设置--->直播配置,填写视频推拉流地址(即视频cdn)
4.七牛云信息填写


恭喜你,管理后台和接口搭建完成!
下面进行UNIAPP端的配置
### 八、UNIAPP端配置
1.将UNIAPP端源码拉取到本地,打开App.vue,配置顶部的信息
```
export default {
globalData: {
userinfo:[],
site_url:'',//此处填写搭建后的网址
socket_url: "",//此处填写搭建后的网址或ip地址,必须带socket的端口
},
```
恭喜你,本程序已搭建完成!