centos 7.6 —— 手工部署安装LNMP&&Discuz论坛

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛

文章目录

  • centos 7.6 —— 手工部署安装LNMP&&Discuz论坛
  • 一、手工部署Nginx
    • 虚拟机win10 验证
  • 二、安装MySQL
    • 2.1 编译MySQL配置文件和开启自定义功能
    • 2.2 手工修改配置文件
    • 2.3 添加环境变量
    • 2.4 数据库初始化
    • 2.6 设置数据库配置文件软链接
    • 2.7 新建数据库管理用户并登录
  • 三、安装PHP
    • 3.1 安装配置软件和make编译PHP配置文件
    • 3.2 修改配置文件 php.ini
    • 3.3 配置及优化FPM 模块
    • 3.3 配置nginx支持PHP 功能
    • 3.4 测试数据库与PHP、Nginx相连接
    • 3.5 虚拟机win10 验证
  • 四、安装Discuz论坛
    • 4.1 安装Discuz_X2.5_SC_UTF8.zip数据包
    • 4.2 win10 验证安装论坛
    • 4.3 进入主要论坛主页
    • 4.4 进入论坛后台管理
    • 排错小结

一、手工部署Nginx

[root@localhost opt]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx   //新建用户Nginx ,——M是指不产生家目录
[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \  // 安装路径
> --user=nginx \   //指定用户来管理Nginx
> --group=nginx \   // 用户组
> --with-http_stub_status_module   //添加统计并发量模块

[root@localhost nginx-1.12.2]# make && make install

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin   //配置文件软链接
[root@localhost nginx-1.12.2]# ls -l /usr/local/sbin/
总用量 0
lrwxrwxrwx. 1 root root 27 8月   6 22:01 nginx -> /usr/local/nginx/sbin/nginx
    
[root@localhost 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@localhost nginx-1.12.2]# cd /lib/systemd/system


在/etc/init.d 目录下新建Nginx文件为启动脚本

[root@localhost init.d]# vim 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@localhost init.d]# chmod +x nginx   //添加权限

[root@localhost init.d]# chkconfig --add nginx   //添加到systemctl启动文件设置中

[root@localhost init.d]# service nginx stop   
cat: /usr/local/nginx/logs/nginx.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

[root@localhost init.d]# sudo fuser -k 80/tcp   //重启出现错误,提示端口被占用,使用该命令
80/tcp:              12826 12827

[root@localhost init.d]# service nginx stop
[root@localhost init.d]# service nginx start  //修改主配置文件之后需要重启Nginx服务


虚拟机win10 验证

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第1张图片

二、安装MySQL

2.1 编译MySQL配置文件和开启自定义功能

yum -y install ncurses ncurses-devel bison cmake   //安装编译数据库的工具
useradd -s /sbin/nologin mysql   //新家数据库管理用户
tar zxvf  mysql-boost-5.7.20.tar.gz   //解压MySQL安装包
cd 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 \
-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  \
-DWITH_SYSTEMD=1
make  && make install
调整权限
chown -R mysql:mysql /usr//local/mysql/

2.2 手工修改配置文件



*******************************手工修改配置文件******************************

[root@localhost 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/mysq/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



2.3 添加环境变量

************************添加环境变量*********************************************************

[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# echo 'export PATH' >>/etc/profile
[root@localhost mysql-5.7.20]# source /etc/profile

2.4 数据库初始化

[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
2020-08-08T13:53:53.017303Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-08-08T13:53:53.388197Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-08-08T13:53:53.448793Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-08-08T13:53:53.511611Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9874be0d-d97e-11ea-9264-000c29191039.
2020-08-08T13:53:53.513156Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-08-08T13:53:53.515839Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

2.6 设置数据库配置文件软链接

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service  /usr/lib/systemd/system/ 
[root@localhost mysql]# systemctl restart mysqld.service
[root@localhost mysql]# netstat -natp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      32282/mysqld    

2.7 新建数据库管理用户并登录

[root@localhost mysql]# mysqladmin   -u  root -p  password
Enter password: 
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

[root@localhost mysql]# mysql -u root -h 127.0.0.1 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
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> CREATE DATABASE bbs;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> quit
Bye

三、安装PHP

3.1 安装配置软件和make编译PHP配置文件

[root@localhost ~]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib  zlib-devel curl curl-devel openssl openssl-devel
编译安装
[root@localhost ~]# tar jxvf php-7.1.10.tar.bz2 
cd 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@localhost ~]# make
[root@localhost ~]# make install


3.2 修改配置文件 php.ini


## php 有三个配置文件 php.ini 核心配置文件  php-fpm.conf 进程服务配置文件www.conf 扩展配置文件
修改配置文件
[root@localhost php-7.1.10]#cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]#vim /usr/local/php/lib/php.ini
mysqli.default_socket=/usr/local/mysql/mysql.sock  ## 在配置文件1170行
date.timezone = Asia/Shanghai   ## 在939[root@localhost php-7.1.10]# /usr/local/php/bin/php -m    ## 验证安装的模块  看是否有FPM 等主要的模块  这时还未加载进去
[PHP Modules] 
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

3.3 配置及优化FPM 模块

  • PHP-FPM(PHP FastCGI Process Manager)意:PHP FastCGI 进程管理器,用于管理PHP
    进程池的软件,用于接受web服务器的请求。
  • PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置。

————————配置及优化FPM 模块————

[root@localhost php-7.1.10]# cd /usr/local/php/etc/    
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf ## 从模板复制进程服务配置文件
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf ## 从模板中复制一份扩展配置文件
[root@localhost php-fpm.d]# vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid ## 去掉开头分号
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c  /usr/local/php/lib/php.ini  ## 启动fpm模块  -c 是以config模式 在/usr/local/php/lib/php.ini  启动
[root@localhost php-fpm.d]# netstat -ntap | grep 9000  ## 查看fpm模块是否启动
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      18694/php-fpm: mast 
[root@localhost php-fpm.d]# ln -s /usr/local/php/bin/* /usr/local/bin/   ## 优化路径命令
[root@localhost php-fpm.d]# ps aux |grep -c "php-fpm"     ## 查看多少php-fpm进程
4
————————————————————

3.3 配置nginx支持PHP 功能


让nginx支持PHP 功能

[root@localhost php-fpm.d]# vim /usr/local/nginx/conf/nginx.conf ## 进入nginx文件  在server里面写
 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@localhost php-fpm.d]# cd /usr/local/nginx/html/
[root@localhost html]# mv index.html  index.php  ## 修改站点后缀为php
[root@localhost html]# vim index.php  
<?php                     ## 显示php页面
phpinfo();
?>
[root@localhost html]# systemctl start nginx  ## 重启nginx服务

_______________


测试

http://192.168.75.134/index.php ## 看到php页面

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第2张图片

3.4 测试数据库与PHP、Nginx相连接

[root@localhost mysql]# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysq/mysql.sock' (2)
改用
[root@localhost mysql]# mysql -uroot -h 127.0.0.1 -p

CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';    //数据库站点bbs设置数据库表的  
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';  
flush privileges; ##  刷新
[root@localhost mysql]# vim /usr/local/nginx/html/index.php ## 修改页面文件测试
<?php
$link=mysqli_connect('192.168.75.134','bbsuser','admin123');
if($link) echo"

Success!!

"
; else echo "Fail!!"; ?> [root@localhost ~]# systemctl restart nginx.service [root@localhost ~]# systemctl restart mysqld.service [root@localhost ~]# http://192.168.233.100/index.php ## 再次进入页面测试 看到Success!! 表示数据库连接成功

3.5 虚拟机win10 验证

http://192.168.233.100/index.php ## 再次进入页面测试 看到Success!! 表示数据库连接成功

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第3张图片

四、安装Discuz论坛

4.1 安装Discuz_X2.5_SC_UTF8.zip数据包


[root@localhost LNMP]# unzip Discuz_X3.4_SC_UTF8.zip  ## 安装数据包
[root@localhost dir_SC_UTF8]# pwd
/opt/LNMP/dir_SC_UTF8
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/   ## 将upload包复制到nginx目录下边
[root@localhost ~]# cd /usr/local/nginx/html/bbs/  ## 进入bbs目录下  修改某些目录的文件属主属组及权限
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/

[root@localhost bbs]# chmod -R 777 ./config/
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

4.2 win10 验证安装论坛

http://192.168.75.134/bbs/install/index.php

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第4张图片

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第5张图片

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第6张图片

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第7张图片
centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第8张图片

4.3 进入主要论坛主页

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第9张图片

4.4 进入论坛后台管理

http://192.168.75.134/bbs/admin.php?

centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第10张图片
centos 7.6 —— 手工部署安装LNMP&&Discuz论坛_第11张图片

排错小结

 http://192.168.75.134/bbs/install/index.php     ## 安装论坛如果遇到如下错误  
Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in /usr/local/nginx/html/bbs/install/index.php:12 Stack trace: #0 {main} thrown in /usr/local/nginx/html/bbs/install/index.php on line 12
[root@localhost bbs]# vim /usr/local/nginx/html/bbs/install/index.php
直接注释掉  @set_magic_quotes_runtime(0);       
[root@localhost bbs]# systemctl restart nginx   ##然后 重启服务

安装论坛成功

你可能感兴趣的:(web——群集)