实现CentOS 7 编译安装基于 fastcgi 模式的多虚拟主机的wordpress和discuz的LAMP架构

实现CentOS 7 编译安装基于 fastcgi 模式的多虚拟主机的wordpress和discuz的LAMP架构

1.环境准备

两台主机:
一台主机:httpd+php(fastcgi模式)
一台主机:mariadb 服务器

软件版本:
mariadb-10.2.27-linux-x86_64.tar.gz 通用二进制格式
apr-1.7.0.tar.bz2
apr-util-1.6.1.tar.bz2
httpd-2.4.41.tar.gz
php-7.3.10.tar.bz2
wordpress-5.3-zh_CN.tar.gz
Discuz_X3.4_SC_UTF8【20190917】.zip

2.实现步骤

2.1二进制安装mariadb
useradd -r -s /sbin/nologin mysql  
tar xvf mariadb-10.2.27-linux-x86_64.tar.gz -C /usr/local  
cd /usr/local  
ls -sv mariadb-10.2.27-linux-x86_64 mysql  
cd mysql  
chown -R root.root ./*  
mkdir /data/mysql -p  
chown -R mysql.mysql /data/mysql  
mkdir /etc/mysql  
cp support-files/my-huge.cnf /etc/mysql/my.cnf  
vim /etc/mysql/my.cnf  
[mysqld]  
#加三行  
datadir =/data/mysql  
skip_name_resolve = ON  
innodb_file_per_table = on #在mariadb5.5以上版的是默认值,可不加  

#准备PATH变量  
vim /etc/profile.d/lamp.sh  
PATH=/usr/local/mysql/bin/:$PATH  
. /etc/profile.d/lamp.sh  
yum install libaio -y  
cd /usr/local/mysql  
scripts/mysql_install_db --user=mysql --datadir=/data/mysql   
cp support-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig --add mysqld    
service mysqld start  

#如果有对应的service 文件可以执行下面  
cp support-files/systemd/mariadb.service /usr/lib/systemd/system/  
systemctl daemon-reload  
systemctl enable --now mariadb  

#为wordprss和discuz应用准备数据库和用户帐号  
mysql -uroot  
mysql> create database wordpress;  
mysql> create database discuz;  
mysql> grant all on wordpress.* to wpuser@'192.168.8.%' identified by "wppass";  
mysql> grant all on discuz.* to discuz@'192.168.8.%' identified by 'dispass';
2.2编译安装 httpd 2.4.41
#安装相关包  
yum install gcc pcre-devel openssl-devel expat-devel -y  

#编译安装httpd  
tar xvf apr-1.7.0.tar.bz2  
tar xvf apr-util-1.6.1.tar.bz2  
tar xf httpd-2.4.41.tar.gz  
mv apr-1.7.0 httpd-2.4.41/srclib/apr  
mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util  
cd httpd-2.4.41/  
./configure \  
--prefix=/app/httpd24 \  
--enable-so \  
--enable-ssl \  
--enable-cgi \  
--enable-rewrite \  
--with-zlib \  
--with-pcre \  
--with-included-apr \  
--enable-modules=most \  
--enable-mpms-shared=all \  
--with-mpm=prefork  

make && make install  

#准备PATH变量  
vim /etc/profile.d/lamp.sh  
PATH=/app/httpd24/bin:$PATH  
. /etc/profile.d/lamp.sh  

#创建和配置用户和组  
useradd -s /sbin/nologin -r -u 88 apache  
vim /app/httpd24/conf/httpd.conf  
user apapche  
group apache  

#修改为event模式  
vim /app/httpd24/conf/httpd.conf  
LoadModule mpm_event_module modules/mod_mpm_event.so  
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so  
#LoadModule mpm_worker_module modules/mod_mpm_worker.so  
httpd -M |grep mpm  
mpm_event_module (shared)  

#设置开机自动启动  
vim /etc/rc.d/rc.local  
/app/httpd24/bin/apachectl start  
chmod +x /etc/rc.d/rc.local  

apachectl start  
2.3编译安装 fastcgi 方式的 php7.4
#php 7.4 相关包
yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel
oniguruma-devel

#php7.4 编译  
tar xvf php-7.4.0.tar.xz  
cd php-7.4.0/  
./configure \  
--prefix=/app/php74 \  
--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  
[root@localhost php-7.4.0]#/app/php74/bin/php --version  
PHP 7.4.0 (cli) (built: Dec 16 2019 16:19:41) ( ZTS )  
Copyright (c) The PHP Group  
Zend Engine v3.4.0, Copyright (c) Zend Technologies   

#准备PATH变量  
vim /etc/profile.d/lamp.sh  
PATH=/app/php73/bin:/app/httpd24/bin:$PATH  
. /etc/profile.d/lamp.sh  

#准备php配置文件和启动文件    
cp php.ini-production /etc/php.ini    
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/  
cd /app/php74/etc  
cp php-fpm.conf.default php-fpm.conf  
cd php-fpm.d/  
cp www.conf.default www.conf  

#修改进程所有者  
vim www.conf  
user apache  
group apache  

#支持status和ping页面  
vim www.conf  
pm.status_path = /status  
ping.path = /ping  

#支持opcache加速  
mkdir /etc/php.d/  
vim /etc/php.d/opcache.ini  
[opcache]  
zend_extension=opcache.so  
opcache.enable=1  

systemctl daemon-reload  
systemctl status php-fpm.service  
systemctl enable --now php-fpm.service  
2.4修改配置httpd 支持php-fpm
vim /app/httpd24/conf/httpd.conf  
#取消下面两行的注释  
LoadModule proxy_module modules/mod_proxy.so  
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so  
#修改下面行  
  
DirectoryIndex index.php index.html  
  
#加下面三行  
AddType application/x-httpd-php .php  
AddType application/x-httpd-php-source .phps  
ProxyRequests Off  

#实现两个虚拟主机  
  
servername wordpress.linux.org  
documentroot /data/wordpress  
  
require all granted  
\  
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1  
#实现status和ping页面  
ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1  
CustomLog "logs/access_wordpress_log" common  
\  
  
servername discuz.linux.org  
documentroot /data/discuz  
  
require all granted  
\  
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1  
CustomLog "logs/access_discuz_log" common  
\  

apachectl restart

2.5准备wordpress和discuz相关文件
#准备wordpress程序文件  
mkdir /data/  
tar xvf wordpress-5.3-zh_CN.tar.gz  
mv wordpress/ /data  
setfacl –R –m u:apache:rwx /data/wordpress/  
#或者chown –R apache.apache /data/wordpress  

#准备discuz程序文件  
unzip Discuz_X3.4_SC_UTF8【20190917】.zip  
mkdir /data/discuz  
mv upload/* /data/discuz  
setfacl -R -m u:apache:rwx /data/discuz/  

注意:要把httpd.conf中加上index.php这样才能识别php文件。

DirectoryIndex index.php index.html

3.测试访问

vim /etc/hosts
192.168.8.100 wordpress.linux.org discuz.linux.org

注意:如果想用windows的浏览器访问,要改写windows自己的hosts文件

你可能感兴趣的:(LAPM,linux,运维,centos)