zl程序教程

您现在的位置是:首页 >  系统

当前栏目

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

2023-06-13 09:15:41 时间

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

两台主机:

一台主机: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.4.3.tar.xz 或 php-7.3.10.tar.bz2 wordpress-5.3.2-zh_CN.tar.gz Discuz_X3.4_SC_UTF8【20191201】.zip 二进制安装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 

#准备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 

#为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 
编译安装 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=/apps/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=event

make make install 

#准备PATH变量

vim /etc/profile.d/lamp.sh

PATH=/apps/httpd24/bin:PATH

 . /etc/profile.d/lamp.sh

#创建和配置用户和组

useradd -s /sbin/nologin -r -u 88 apache

vim /apps/httpd24/conf/httpd.conf

user apache

group apache

#修改为event模式,编译时已指定,此项不再需修改,可选项

vim /apps/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)

apachectl start

[root@centos7 ~]#cat /usr/lib/systemd/system/httpd.service

[Unit]

Description=The Apache HTTP Server

After=network.target remote-fs.target nss-lookup.target

Documentation=man:httpd(8)

Documentation=man:apachectl(8)

[Service]

Type=forking

#EnvironmentFile=/etc/sysconfig/httpd

ExecStart=/apps/httpd24/bin/httpdOPTIONS -k start

ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful

ExecStop=/apps/httpd24/bin/apachectl stop

KillSignal=SIGCONT

PrivateTmp=true

[Install]

WantedBy=multi-user.target
编译安装 fastcgi 方式的 php 7.4
#安装相关包,依赖EPEL源

#php 7.4 相关包

yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel

#php 7.3 相关包

yum install gcc libxml2-devel bzip2-devel libmcrypt-devel 

#php7.4 编译

tar xvf php-7.4.3.tar.xz 

cd php-7.4.3/

./configure /

--prefix=/apps/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

#编译安装php 7.3

tar xvf php-7.3.10.tar.bz2

cd php-7.3.10

./configure --prefix=/apps/php73 /

--enable-mysqlnd /

--with-mysqli=mysqlnd /

--with-pdo-mysql=mysqlnd /

--with-openssl /

--with-freetype-dir /

--with-jpeg-dir /

--with-png-dir /

--with-zlib /

--with-libxml-dir=/usr /

--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

#准备PATH变量

vim /etc/profile.d/lamp.sh

PATH=/apps/php74/bin:/apps/httpd24/bin:PATH

 . /etc/profile.d/lamp.sh

vim /etc/profile.d/lamp.sh

PATH=/apps/php73/bin:/apps/httpd24/bin:PATH

 . /etc/profile.d/lamp.sh

[root@centos7 ~]#php --version

PHP 7.4.3 (cli) (built: Mar 11 2020 15:06:53) ( ZTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

[root@websrv ~]#/apps/php73/bin/php --version

PHP 7.3.12 (cli) (built: Dec 14 2019 10:20:40) ( ZTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies

#准备php配置文件和启动文件

cp php.ini-production /etc/php.ini

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

cd /apps/php73/etc

cp php-fpm.conf.default php-fpm.conf

cd php-fpm.d/

cp www.conf.default www.conf

#修改进程所有者

vim /apps/php74/etc/php-fpm.d/www.conf

user apache

group apache 

#支持status和ping页面

pm.status_path = /fpm_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 
修改配置httpd 支持php-fpm
vim /apps/httpd24/conf/httpd.conf

#取消下面两行的注释

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

#修改下面行

 IfModule dir_module 

DirectoryIndex index.php index.html

 /IfModule 

#加下面三行

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

ProxyRequests Off

#实现两个虚拟主机

 virtualhost *:80 

servername wordpress.magedu.org

documentroot /data/wordpress

 directory /data/wordpress 

require all granted

 /directory 

ProxyPassMatch ^/(.*/.php)fcgi://127.0.0.1:9000/data/wordpress/1

#实现status和ping页面

ProxyPassMatch ^/(fpm_status|ping)fcgi://127.0.0.1:9000/1 

CustomLog logs/access_wordpress_log common

 /virtualhost 

 virtualhost *:80 

servername discuz.magedu.org

documentroot /data/discuz

 directory /data/discuz/ 

require all granted

 /directory 

ProxyPassMatch ^/(.*/.php)fcgi://127.0.0.1:9000/data/discuz/1

CustomLog logs/access_discuz_log common

 /virtualhost 

apachectl restart
准备wordpress和discuz! 相关文件
#准备wordpress程序文件

mkdir /data/

tar xvf wordpress-5.3.2-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【20191201】.zip 

mkdir /data/discuz

mv upload/* /data/discuz

setfacl -R -m u:apache:rwx /data/discuz/
vim /etc/hosts

192.168.100.100 wordpress.magedu.org discuz.magedu.org

打开浏览器访问 http://wordpress.magedu.net 和http://discuz.magedu.net 分别进行初始化和安装

修改成UDS模式
vim /apps/php/etc/php-fpm.d/www.conf

;listen = 127.0.0.1:9000

listen = /run/php-fpm.sock

listen.owner = apache

listen.group = apache 

listen.mode = 0660

systemctl restart php-fpm

ll /run/php-fpm.sock 

srw-rw---- 1 apache apache 0 Dec 14 11:11 /run/php-fpm.sock

vim /apps/httpd24/conf/httpd.conf

 virtualhost *:80 

servername wordpress.magedu.org

documentroot /data/wordpress

 directory /data/wordpress 

require all granted

 /directory 

#ProxyPassMatch ^/(.*/.php)fcgi://127.0.0.1:9000/data/wordpress/1

ProxyPassMatch ^/(.*/.php) unix:/run/php-fpm.sock|fcgi://localhost/data/wordpress/ 

#ProxyPassMatch ^/(status|ping) fcgi://127.0.0.1:9000/1

ProxyPassMatch ^/(status|ping) unix:/run/php-fpm.sock|fcgi://localhost/ 

CustomLog logs/access_wordpress_log common

 /virtualhost 

 virtualhost *:80 

servername wordpress.magedu.org

documentroot /data/wordpress

 directory /data/wordpress 

require all granted

 /directory 

#ProxyPassMatch ^/(.*/.php)fcgi://127.0.0.1:9000/data/discuz/1

ProxyPassMatch ^/(.*/.php) unix:/run/php-fpm.sock|fcgi://localhost/data/discuz/ 

#ProxyPassMatch ^/(status|ping) fcgi://127.0.0.1:9000/1

ProxyPassMatch ^/(status|ping) unix:/run/php-fpm.sock|fcgi://localhost/ 

CustomLog logs/access_wordpress_log common

 /virtualhost 

apachectl restart

本文链接:http://www.yunweipai.com/36114.html

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/52452.html

apachecentosLAMPlinuxmysqlphpwordpress