软件包百度云连接:https://pan.baidu.com/s/1gI6Q2qJHmQUIqJVqut_AXA
准备软件包如下:
一、搭建 Nginx
(1)解压压缩包
tar zxvf nginx-1.12.2.tar.gz -C /opt/
//解压到/opt/目录下
(2)创建用户,且不允许登录系统
useradd -M -s /sbin/nologin nginx
(3)安装编译工具、环境(在nginx-1.12.2/路径下)
yum install gcc gcc-c++ pcre-devel zlib-devel -y
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
(4)安装
make && make install
(5)为了方便管理,可以给nginx创建一个软连接
cd /lib/systemd/system/
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
(6)编写一个脚本,可以用 systemctl 工具控制其开启、关闭、重载
cd /lib/systemd/system/
1、vim 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
2、添加权限
chmod 754 nginx.service
systemctl start nginx.service //开启nginx服务
systemctl stop firewalled.service //关闭防火墙
setenforce 0 //安全性功能关闭
3、在客户机上验证,访问官网是否能成功
二、搭建 Mysql
(1)解压压缩包
tar zxvf mysql-boost-5.7.20.tar.gz -C /opt/ //解压到/opt/目录下
(2)安装工具,环境
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
(3)创建用户
useradd -s /sbin/nologin mysql
(4)编译
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 \
-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
(5)安装
make && make install
(6)设置权限
cd /usr/local/
chown -R mysql.mysql mysql/
(7)调整配置文件:
vim /etc/my.cnf
删掉/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
(8)设置环境变量:
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
启动:
source /etc/profile
(9)初始化数据库:
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
(10)保持路径不变,将服务复制到 /lib/systemd/system/路径下,可以用systemctl控制管理
cp usr/lib/systemd/system/mysqld.service /lib/systemd/system/
(11)检测mysql 服务是否成功
systemctl start mysqld.service //开启mysql服务
netstat -natp | grep 3306 //查看端口是否正常开启
(12)设置 mysql 密码:
默认密码没有,直接回传即可,输入新密码
mysqladmin -u root -p password
(13)登录数据库:
mysql -u root -p
三、安装 PHP
(1)安装环境依赖包
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
(2)解压文件:
cd /opt/
tar xjvf php-7.1.10.tar.bz2
(3)configure编译
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
(4)安装
make && make install
(5)修改配置文件:
cp php.ini-development /usr/local/php/lib/php.ini //先复制一份到lib路径下
vim /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock //指定路径
date.timezone = Asia/Shanghai //指定时区
(6)验证安装模块
/usr/local/php/bin/php -m
四、配置及优化 FPM 模块
(1)
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf //复制一份到 php-fpm.conf
vim php-fpm.conf //进入文件
pid = run/php-fpm.pid //开启pid(去掉行首的注释符即可)
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf //复制扩展包
(2)启动 PHP
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
检测是否成功:
netstat -napt | grep 9000
(3)创建软连接,便于系统识别:
ln -s /usr/local/php/bin/* /usr/local/bin/
五、让 nginx 支持 PHP
(1)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;
}
(2)重启nginx服务
systemctl restart nginx
(3)创建PHP首页
vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
(4)网站访问PHP首页
另:安装论坛
第一步:进数据库创建用户、密码、终端
mysql -u root -p //进入数据库(密码就是我们之前设置的abc123)
第二步:添加以下代码一键完成
CREATE DATABASE bbs;
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
第三步:解压 Discuz 论坛文件
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/ //解压到/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/
第五步:访问网址
填好数据库名称和密码之后,就可以进入首页了