LAMP

CGI与FASTCGI区别:

CGI:公共网关接口,碰到动态请求,web服务器会fork一个新进程,来运行外部的程序,处理完后的数据返回给web服务器,web服务器把内容发送给用户fork的进程也就退出。不可复用。 请求流程:Client -- (http协议) --> httpd -- (cgi协议) --> application server (program file) -- (mysql协议) -->mysql

fastcgi:收到动态请求后把请求时,web服务器直接把内容传递给这个进程,这个进程收到请求后进程处理,把结果返回给web服务器,然后接着等待下一个请求到来再处理,而不是退出。 请求流程:Client -- (http协议) --> httpd -- (fastcgi协议) --> fastcgi服务器 -- (mysql协议) --> mysql

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

#编译httpd
yum install gcc pcre-devel openssl-devel expat-devel -y
tar xjf apr-1.7.0.tar.bz2
tar xjf apr-util-1.6.1.tar.bz2
tar xjf httpd-2.4.46.tar.bz2
mv apr-1.7.0 httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
cd httpd-2.4.46/
mkdir /apps
./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 -j && make install

cat  /etc/profile.d/lamp.sh
PATH=/apps/httpd24/bin:$PATH

. /etc/profile.d/lamp.sh
useradd -s /sbin/nologin -r  apache

vim /apps/httpd24/conf/httpd.conf
改为 user apache
     group apache

#编写服务脚本
vim /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/apachectl start
#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd24/bin/apachectl graceful
#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target


#编译php
cd
tar zxf php-7.2.34.tar.gz
cd php-7.2.34/
yum -y install php-mcrypt  libmcrypt  libmcrypt-devel php-pear libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/ --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make -j && make install

#生成php和php-fpm的配置文件
cp php.ini-production /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf
mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

#修改进程所有者
sed -i '23c user = apache' /usr/local/php/etc/php-fpm.conf
sed -i '24c group = apache' /usr/local/php/etc/php-fpm.conf

#支持status和ping页面
vim  /usr/local/php/etc/php-fpm.conf
pm.status_path = /fpm_status
ping.path = /ping 

#复制启动脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig  php-fpm on
systemctl start 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
ProxyRequests Off


#实现第一个虚拟主机
<virtualhost *:80>
servername www.wswj.cn
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 blog.wswj.cn
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>


#解压站点文件
cd
tar  zxf wordpress-5.8.1-zh_CN.tar.gz
mkdir /data
mv wordpress /data/
unzip Discuz_X3.4_SC_UTF8_20211022.zip
mv upload /data/discuz

apachectl start

#安装mariadb
yum install mariadb-server.x86_64 -y
systemctl start mariadb.service

#准备项目所需数据库
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]>  create database discuz;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.88.%' identified by "123456";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on discuz.* to wordpress@'192.168.88.%' identified by "123456";
Query OK, 0 rows affected (0.00 sec)


#访问安装