0.准备工作
mysql服务器安装 此处略:详见 https://blog.csdn.net/qq_29974229/article/details/120329530 需要配置epel源,详见 https://blog.csdn.net/qq_29974229/article/details/119447901
序号 | 服务器IP | 作用 | 安装软件 |
---|
1 | 192.168.31.61 | 数据库服务器 | MariaDB 10.4.21 | 2 | 192.168.31.71 | HTTP服务器 | httpd-2.4.49,php-7.4.24,WordPress 5.8.1,Discuz_X3.4 |
1. DB-server服务器搭建
1.1 mysql服务器安装
此处略:详见 https://blog.csdn.net/qq_29974229/article/details/120329530
1.2 创建数据库及账号并授权
create database blog;
create database bbs;
create user blog@'192.168.31.%' identified by 'Pana#123';
create user bbs@'192.168.31.%' identified by 'Pana#123';
grant all on blog.* to blog@'192.168.31.%';
grant all on bbs.* to bbs@'192.168.31.%';
2. Httpd-server服务器搭建
2.1 编译安装httpd
yum -y install apr-devel.x86_64 apr-util-devel.x86_64 gcc pcre-devel.x86_64 openssl-devel.x86_64 lrzsz redhat-rpm-config-125-1.el8.noarch make libxml2-devel bzip2-devel
wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.49.tar.bz2
mkdir -p /app
tar xf httpd-2.4.49.tar.bz2
cd httpd-2.4.49
./configure --prefix=/app/httpd-2.4.49 --enable-ssl
make -j 4
make install
cd /app/
ln -sf httpd-2.4.49 httpd
echo "PATH=/app/httpd/bin/:$PATH" >/etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
id apache &> /dev/null || useradd -r -u 80 -d /var/www -s /sbin/nologin apache
sed -Ei 's#(^User).*#\1 apache#' /app/httpd/conf/httpd.conf
sed -Ei 's#(^Group).*#\1 apache#' /app/httpd/conf/httpd.conf
2.2 编译安装php
2.2.1 前置yum包和oniguruma安装
yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar xf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install
下载地址 https://www.php.net/downloads.php
2.2.2 编译PHP
cd
tar xf php-7.4.24.tar.xz
cd php-7.4.24/
./configure \
--prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
make -j 4 && make install
2.2.3 配置hp环境变量
echo "PATH=/app/php/bin/:/app/php/sbin/:$PATH" >/etc/profile.d/php.sh
. /etc/profile.d/php.sh
php --version
PHP 7.4.24 (cli) (built: Sep 24 2021 08:20:52) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
2.3 配置文件修改
2.3.1 http配置文件修改
sed -Ei 's/^#(.*mod_proxy.so)/\1/' /app/httpd/conf/httpd.conf
sed -Ei 's/^#(.*proxy_fcgi.so)/\1/' /app/httpd/conf/httpd.conf
sed -Ei 's#(.*DirectoryIndex )(index.html)#\1index.php \2#' /app/httpd/conf/httpd.conf
echo "AddType application/x-httpd-php .php" >> /app/httpd/conf/httpd.conf
echo "ProxyRequests Off" >> /app/httpd/conf/httpd.conf
2.3.2 php配置文件修改
cp /root/php-7.4.24/php.ini-production /app/php/php.ini
service文件
cp /root/php-7.4.24/sapi/fpm/php-fpm.service /lib/systemd/system/
mv /app/php/etc/php-fpm.conf{.default,}
mv /app/php/etc/php-fpm.d/www.conf{.default,}
sed -Ei 's#^(user = ).*#\1apache#' /app/php/etc/php-fpm.d/www.conf
sed -Ei 's#^(group = ).*#\1apache#' /app/php/etc/php-fpm.d/www.conf
sed -Ei 's#^;(.* /)(status)$#\1fpm_\2#' /app/php/etc/php-fpm.d/www.conf
sed -Ei 's#;(.*ping$)#\1#' /app/php/etc/php-fpm.d/www.conf
2.4 启用Opcache加速
2.4.1 脚本安装替换Opcache
yum -y install php-opcache
cat >> /etc/php.d/opcache.ini <<EOF
[opcache]
zend_extension=opcache.so
opcache.enable=1
EOF
systemctl daemon-reload
systemctl enable --now php-fpm.service
2.4.2 手动替换配置文件
(手动和自动任意执行一个就可以了)
vim /app/httpd/conf/httpd.conf
3. 配置Wordpress+Discuz环境
3.1 配置虚拟主机
cat >> /app/httpd/conf/httpd.conf <<EOF
<virtualhost *:80>
servername blog.pana.net
documentroot /data/blog
<directory /data/blog>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/blog/$1
#实现status和ping页面
ProxyPassMatch ^/(fpm_status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_blog_log" common
</virtualhost>
<virtualhost *:80>
servername bbs.pana.net
documentroot /data/bbs
<directory /data/bbs>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/bbs/$1
CustomLog "logs/access_bbs_log" common
</virtualhost>
EOF
3.2 安装Wordpress
下载wordpress https://wordpress.org/
mkdir /data/{blog,bbs} -p
cd /data/
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar xf latest-zh_CN.tar.gz
mv wordpress/* /data/bbs/
3.3 安装Discuz
下载discuz https://www.discuz.net/
unzip Discuz_X3.4_SC_GBK_20210917.zip -d Discuz
mv Discuz/upload/* bbs/
chown -R apache.apache /data/
chown -R apache.apache /app/
3.4 启动apache
apachectl start
4. 验证
4.1 验证Opcache加速是否打开
9000端口已经运行
cat /data/bbs/info.php
<?php phpinfo() ?>
4.2 验证Wordpress环境
4.3 验证Discuz环境
5.搭建过程中的错误
5.1 错误1:
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
解决方法:
yum install -y redhat-rpm-config-125-1.el8.noarch
5.2 错误2:
Package 'oniguruma', required by 'virtual:world', not found
解决方法:
yum install autoconf automake libtool -y
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar xf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install
再次编译php,不再报错
|