实验·搭建LNMP架构的社区动力论坛

实验·搭建LNMP架构的社区动力论坛

实验环境

CentOS 7.6

Win 10

实验步骤

#搭建Nginx

#安装环境

[root@localhost opt]# yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel

#解压缩源码包

[root@localhost opt]# tar zxvf nginx-1.12.2.tar.gz

#创建nginx用户

[root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx

#编译安装

[root@localhost opt]# cd nginx-1.12.2/

[root@localhost nginx-1.12.2]# ./configure \
--prefix=/usr/local/nginx \
--user=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]# 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]# nginx 

[root@localhost nginx-1.12.2]# netstat -antp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22287/nginx: master 

#添加Nginx系统服务

[root@localhost nginx-1.12.2]# vim /lib/systemd/system/nginx.service
[Unit]
Description = nginx
After = network.target
[Service]
Type = forking
PIDFile = /usr/local/nginx/logs/nginx.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@localhost nginx-1.12.2]# chmod 754 /lib/systemd/system/nginx.service

[root@localhost nginx-1.12.2]# systemctl enable nginx.service 

[root@localhost nginx-1.12.2]# systemctl start nginx.service 

#安装MySQL

#安装环境

[root@localhost opt]# yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

#创建用户

[root@localhost opt]# useradd -s /sbin/nologin mysql

#解压源码包

[root@localhost opt]# tar zxvf mysql-boost-5.7.20.tar.gz 

#编译安装

[root@localhost opt]# cd mysql-5.7.20/

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

[root@localhost mysql-5.7.20]# make && make install

[root@localhost mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql

#调整配置文件

[root@localhost opt]# 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 = mysqlbasedir = /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@localhost opt]# chown mysql:mysql /etc/my.cnf

#设置环境变量

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

[root@localhost opt]# echo 'export PATH'>>/etc/profile

[root@localhost opt]# source /etc/profile

#初始化数据库

[root@localhost opt]# cd /usr/local/mysql/

[root@localhost mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

#数据库开启并查看状态

[root@localhost system]# systemctl start mysqld

[root@localhost system]# systemctl enable mysqld

[root@localhost system]# systemctl status mysqld

[root@localhost system]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      21684/mysqld 

#添加数据库的管理员密码;密码为"abc123"

[root@localhost etc]# mysqladmin -u root -p password "abc123"
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

#安装PHP

#安装环境

[root@localhost opt]# 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 opt]# tar jxvf php-7.1.10.tar.bz2

#编译安装

[root@localhost opt]# cd php-7.1.10/

[root@localhost 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 php-7.1.10]# make && make install

[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 
......
date.timezone = Asia/Shanghai
......
mysqli.default_socket = /usr/local/mysql/mysql.sock

#验证安装的模块

[root@localhost php-7.1.10]# /usr/local/php/bin/php -m

#配置优化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]# cd /usr/local/php/etc/

[root@localhost etc]# vim php-fpm.conf
pid = run/php-fpm.pid

[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini 

[root@localhost etc]# netstat -antp | grep php-fpm

[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/

[root@localhost etc]# ps aux | grep -c "php-fpm"
4

#让nginx支持php

[root@localhost etc]# vim /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@localhost etc]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

[root@localhost etc]# systemctl restart nginx.service 

在浏览器上输入"20.0.0.10/index.php"

image-20200808121913839

#测试数据库

[root@localhost etc]# mysql -u root -p
Enter password:

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@localhost etc]# vim /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('20.0.0.10','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>

[root@localhost etc]# systemctl restart nginx

在浏览器上输入"20.0.0.10/index.php"

image-20200808123251250

#部署社区动力论坛

#解压源码包

[root@localhost opt]# unzip Discuz_X3.4_SC_UTF8.zip

[root@localhost opt]# cd dir_SC_UTF8/

[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/

[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/

#设置属主属组,权限

[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# 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/

#安装社区动力论坛

在浏览器输入"http://20.0.0.10/bbs/install/index.php"

image-20200808123828703

#创建数据库

image-20200808123915046

实验结果

在浏览器上输入"http://20.0.0.10/bbs/index.php"

image-20200808124047529

猜你喜欢

转载自blog.csdn.net/weixin_47153668/article/details/107885945
今日推荐