lamp

lamp

有了前面学习的知识的铺垫,今天可以来学习下第一个常用的web架构了。

所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。

  1. web服务器工作流程

在说lamp架构平台的搭建前,我们先来了解下什么是CGI,什么是FastCGI,什么是……

web服务器的资源分为两种,静态资源和动态资源

  • 静态资源是指静态内容,客户端从服务器获取的资源表示方式与原始文件相同。它可以简单地理解为直接存储在文件系统中的资源。
    [En]

    static resources refer to static content, and the resources obtained by the client from the server are represented in the same way as the original files. It can be simply understood as resources stored directly in the file system.*

  • 动态资源通常是程序文件,需要在服务器执行后返回给客户端
    [En]

    dynamic resources are usually program files, which need to be returned to the client after the server executes*

那么web服务器如何执行程序并将结果返回给客户端呢?下面通过一张图来说明一下web服务器如何处理客户端的请求

lamp

阶段①显示的是httpd服务器(即apache)和php服务器通过FastCGI协议进行通信,且php作为独立的服务进程运行

阶段②显示的是php程序和mysql数据库间通过mysql协议进行通信。php与mysql本没有什么联系,但是由Php语言写成的程序可以与mysql进行数据交互。同理perl和python写的程序也可以与mysql数据库进行交互

2.1 cgi与fastcgi

CGI(Common Gateway Interface,通用网关接口),CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。

FastCGI(Fast Common Gateway Interface)是CGI的改良版,CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,即启动一个master主进程,然后根据配置启动几个worker进程,当请求进来时,master会从worker进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时

2.2 httpd与php结合的方式

httpd与php结合的方式有以下三种:

  • modules:php将以httpd的扩展模块形式存在,需要加载动态资源时,httpd可以直接通过php模块来加工资源并返回给客户端
  • httpd prefork:libphp5.so(多进程模型的php)
  • httpd event or worker:libphp5-zts.so(线程模型的php)
  • CGI:httpd需要加载动态资源时,通过CGI与php解释器联系,获得php执行的结果,此时httpd负责与php连接的建立和断开等
  • FastCGI:利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信

较于CGI方式,FastCGI更为常用,很少有人使用CGI方式来加载动态资源

2.3 web工作流程

  • 客户端通过http协议请求web服务器资源
  • web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
  • 若是静态资源则直接从本地文件系统取之返回给客户端。
  • 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。

  • lamp平台搭建

环境说明:

系统平台 IP 需要安装的服务 centos7 redhat7 172.16.12.128 httpd-2.4 mysql-5.7 php php-mysql

lamp平台软件安装次序:
httpd –> mysql –> php

3.1 安装httpd

[root@mr ~]# cd /etc/yum.repos.d/
[root@mr yum.repos.d]# ls
CentOS-Stream-AppStream.repo  CentOS-Stream-Extras.repo            CentOS-Stream-PowerTools.repo
CentOS-Stream-BaseOS.repo     CentOS-Stream-HighAvailability.repo  CentOS-Stream-RealTime.repo
CentOS-Stream-Debuginfo.repo  CentOS-Stream-Media.repo
[root@mr yum.repos.d]# rm -rf *
[root@mr yum.repos.d]# ls
[root@mr yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  15993      0 --:--:-- --:--:-- --:--:-- 16096
[root@mr yum.repos.d]# ls
CentOS-Base.repo
[root@mr yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@mr yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
CentOS-8.5.2111 - Base - mirrors.aliyun.com                              144 kB/s | 3.9 kB     00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                             69 kB/s | 1.5 kB     00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                         176 kB/s | 4.3 kB     00:00
epel-release-latest-8.noarch.rpm                                         449 kB/s |  24 kB     00:00
Dependencies resolved.

=========================================================================================================
 Package                    Architecture         Version                Repository                  Size
=========================================================================================================
Installing:
 epel-release               noarch               8-16.el8               @commandline                24 k

Transaction Summary
=========================================================================================================
Install  1 Package

Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.

Running transaction test
Transaction test succeeded.

Running transaction
  Preparing        :                                                                                 1/1
  Installing       : epel-release-8-16.el8.noarch                                                    1/1
  Running scriptlet: epel-release-8-16.el8.noarch                                                    1/1
Many EPEL packages require the CodeReady Builder (CRB) repository.

It is recommended that you run /usr/bin/crb enable to enable the CRB repository.

  Verifying        : epel-release-8-16.el8.noarch                                                    1/1
Installed products updated.

Installed:
  epel-release-8-16.el8.noarch

Complete!

[root@mr yum.repos.d]#
[root@mr yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@mr yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@mr yum.repos.d]# ls
CentOS-Base.repo  epel-modular.repo  epel.repo  epel-testing-modular.repo  epel-testing.repo
[root@mr yum.repos.d]# cd
[root@mr ~]# dnf clean all
37 files removed
[root@mr ~]#
[root@mr ~]# dnf makecache
CentOS-8.5.2111 - Base - mirrors.aliyun.com                               10 MB/s | 4.6 MB     00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                            104 kB/s |  10 kB     00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                          11 MB/s | 8.4 MB     00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64                   3.2 MB/s | 1.0 MB     00:00
Extra Packages for Enterprise Linux 8 - x86_64                            10 MB/s |  13 MB     00:01
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Metadata cache created.

[root@mr ~]# dnf -y install
openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make vim wget
......

  perl-threads-shared-1.58-2.el8.x86_64
  pkgconf-1.4.2-1.el8.x86_64
  pkgconf-m4-1.4.2-1.el8.noarch
  pkgconf-pkg-config-1.4.2-1.el8.x86_64
  zlib-devel-1.2.11-17.el8.x86_64

Complete!

[root@mr ~]# [root@mr ~]# useradd -r -M -s /sbin/nologin apache
[root@mr ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
--2022-08-02 19:20:01--  https://downloads.apache.org/apr/apr-1.7.0.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f9:3a:2c57::2, ...

Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... connected.

HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/x-gzip]
Saving to: 'apr-1.7.0.tar.gz'

apr-1.7.0.tar.gz           100%[=====================================>]   1.04M  15.8KB/s    in 54s

2022-08-02 19:20:56 (19.9 KB/s) - 'apr-1.7.0.tar.gz' saved [1093896/1093896]

[root@mr~]#https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
......

--2022-08-02 19:21:15--  https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f9:3a:2c57::2, ...

Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... connected.

HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/x-gzip]
Saving to: 'apr-util-1.6.1.tar.gz'

apr-util-1.6.1.tar.gz      100%[=====================================>] 541.31K  4.23KB/s    in 2m 13s

2022-08-02 19:23:29 (4.08 KB/s) - 'apr-util-1.6.1.tar.gz' saved [554301/554301]

[root@mr ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
--2022-08-02 19:25:49--  https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f9:3a:2c57::2, ...

Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.

HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/x-gzip]
Saving to: 'httpd-2.4.54.tar.gz'

httpd-2.4.54.tar.gz        100%[=====================================>]   9.29M  48.2KB/s    in 4m 57s

2022-08-02 19:30:47 (32.0 KB/s) - 'httpd-2.4.54.tar.gz' saved [9743277/9743277]
[root@mr ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@mr ~]# tar xf apr-1.7.0.tar.gz
[root@mr ~]# tar xf apr-util-1.6.1.tar.gz
[root@mr ~]# ls
anaconda-ks.cfg  apr-1.7.0  apr-1.7.0.tar.gz  apr-util-1.6.1  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@mr ~]# cd apr-1.7.0
[root@mr apr-1.7.0]# ls
apr-config.in  atomic            config.layout  file_io     LICENSE       network_io     README.cmake  time
apr.dep        build             configure      helpers     locks         NOTICE         shmem         tools
apr.dsp        build.conf        configure.in   include     Makefile.in   NWGNUmakefile  strings       user
apr.dsw        buildconf         docs           libapr.dep  Makefile.win  passwd         support
apr.mak        build-outputs.mk  dso            libapr.dsp  memory        poll           tables
apr.pc.in      CHANGES           emacs-mode     libapr.mak  misc          random         test
apr.spec       CMakeLists.txt    encoding       libapr.rc   mmap          README         threadproc
[root@mr apr-1.7.0]# vim configure

  # $RM "$cfgfile"        //将此行加上注释,或者删除此行
 [root@mr apr-1.7.0]# ./configure --prefix=/usr/local/apr
 ......

config.status: creating build/apr_rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating apr-1-config
config.status: creating apr.pc
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
[root@mr apr-1.7.0]# make
......

/unix -I/root/apr-1.7.0/include/arch/unix -I/root/apr-1.7.0/include -I/root/apr-1.7.0/include/private -I/root/apr-1.7.0/include/private  export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> apr.exp
sed 's,^\(location=\).*$,\1installed,' < apr-1-config > apr-config.out
sed -e 's,^\(apr_build.*=\).*$,\1/usr/local/apr/build-1,' -e 's,^\(top_build.*=\).*$,\1/usr/local/apr/build-1,' < build/apr_rules.mk > build/apr_rules.out
make[1]: Leaving directory '/root/apr-1.7.0'
[root@mr apr-1.7.0]# make install
......

/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@mr apr-1.7.0]# cd ../apr-util-1.6.1
[root@mr apr-util-1.6.1]# ls
aprutil.dep     apu-config.in     CHANGES         dbd                include         LICENSE       NWGNUmakefile    strmatch
aprutil.dsp     buckets           CMakeLists.txt  dbm                ldap            Makefile.in   README           test
aprutil.dsw     build             config.layout   docs               libaprutil.dep  Makefile.win  README.cmake     uri
aprutil.mak     build.conf        configure       encoding           libaprutil.dsp  memcache      README.FREETDS   xlate
apr-util.pc.in  buildconf         configure.in    export_vars.sh.in  libaprutil.mak  misc          redis            xml
apr-util.spec   build-outputs.mk  crypto          hooks              libaprutil.rc   NOTICE        renames_pending
[root@mr apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
......

config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@mr apr-util-1.6.1]# make && make install
......

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

Total                                                                                        2.5 MB/s | 1.6 MB     00:00
Running transaction check
Transaction check succeeded.

Running transaction test
Transaction test succeeded.

Running transaction
  Preparing        :                                                                                                     1/1
  Upgrading        : sqlite-libs-3.26.0-15.el8.x86_64                                                                    1/6
  Installing       : sqlite-3.26.0-15.el8.x86_64                                                                         2/6
  Installing       : sqlite-devel-3.26.0-15.el8.x86_64                                                                   3/6
  Installing       : libsqlite3x-20071018-26.el8.x86_64                                                                  4/6
  Installing       : libsqlite3x-devel-20071018-26.el8.x86_64                                                            5/6
  Cleanup          : sqlite-libs-3.26.0-13.el8.x86_64                                                                    6/6
  Running scriptlet: sqlite-libs-3.26.0-13.el8.x86_64                                                                    6/6
  Verifying        : sqlite-3.26.0-15.el8.x86_64                                                                         1/6
  Verifying        : sqlite-devel-3.26.0-15.el8.x86_64                                                                   2/6
  Verifying        : libsqlite3x-20071018-26.el8.x86_64                                                                  3/6
  Verifying        : libsqlite3x-devel-20071018-26.el8.x86_64                                                            4/6
  Verifying        : sqlite-libs-3.26.0-15.el8.x86_64                                                                    5/6
  Verifying        : sqlite-libs-3.26.0-13.el8.x86_64                                                                    6/6
Installed products updated.

Upgraded:
  sqlite-libs-3.26.0-15.el8.x86_64

Installed:
  libsqlite3x-20071018-26.el8.x86_64       libsqlite3x-devel-20071018-26.el8.x86_64       sqlite-3.26.0-15.el8.x86_64
  sqlite-devel-3.26.0-15.el8.x86_64

Complete!

[root@master ~]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
......

 Verifying        : oniguruma-6.8.2-2.el8.x86_64                                                                        1/2
  Verifying        : oniguruma-devel-6.8.2-2.el8.x86_64                                                                  2/2
Installed products updated.

Installed:
  oniguruma-6.8.2-2.el8.x86_64                               oniguruma-devel-6.8.2-2.el8.x86_64

Complete!

[root@master ~]# ls
anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.54.tar.gz                         php-7.4.30.tar.xz
apr-1.7.0         apr-util-1.6.1.tar.gz  mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.54           pass
[root@master ~]# dnf -y install libzip-devel
 Verifying        : libzip-devel-1.5.1-2.module_el8.2.0+313+b04d0a66.x86_64                         2/2
Installed products updated.

Installed:
  libzip-1.5.1-2.module_el8.2.0+313+b04d0a66.x86_64
  libzip-devel-1.5.1-2.module_el8.2.0+313+b04d0a66.x86_64

Complete!

[root@master ~]#

[root@master ~]# tar xf php-7.4.30.tar.xz
[root@master ~]# cd php-7.4.30
[root@master php-7.4.30]# ./configure --prefix=/usr/local/php7  \
> --with-config-file-path=/etc \
> --enable-fpm \
> --enable-inline-optimization \
> --disable-debug \
> --disable-rpath \
> --enable-shared \
> --enable-soap \
> --with-openssl \
> --enable-bcmath \
......

config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

[root@master php-7.4.30]# make
......

pharcommand.inc
invertedregexiterator.inc
directorytreeiterator.inc
directorygraphiterator.inc
phar.inc

Build complete.

Don't forget to run 'make test'.

[root@master php-7.4.30]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
......

/root/php-7.4.30/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin/phar.phar
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/
[root@master php-7.4.30]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@master php-7.4.30]#  source /etc/profile.d/php7.sh
[root@master php-7.4.30]#  which php
/usr/local/php7/bin/php
[root@master php-7.4.30]# php -v
PHP 7.4.30 (cli) (built: Aug  3 2022 00:00:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@master php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@master php-7.4.30]# cd sapi/
[root@master sapi]# ls
apache2handler  cgi  cli  embed  fpm  litespeed  phpdbg
[root@master sapi]# cd fpm/
[root@master fpm]# ls
config.m4       init.d.php-fpm.in  php-fpm.8        php-fpm.service     tests
CREDITS         LICENSE            php-fpm.8.in     php-fpm.service.in  www.conf
fpm             Makefile.frag      php-fpm.conf     status.html         www.conf.in
init.d.php-fpm  php-fpm            php-fpm.conf.in  status.html.in
[root@master fpm]# file init.d.php-fpm
init.d.php-fpm: POSIX shell script, ASCII text executable
[root@master fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@master fpm]# chmod +x /etc/init.d/php-fpm
[root@master fpm]# cd
[root@master ~]# service php-fpm status
php-fpm is stopped
[root@master ~]# cd /usr/local/php7/
[root@master php7]# ls
bin  etc  include  lib  php  sbin  var
[root@master php7]# cd etc/
[root@master etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@master etc]# cp php-fpm.conf.default php-fpm.conf
[root@master etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@master etc]# cd php-fpm.d/
[root@master php-fpm.d]# ls
www.conf.default
[root@master php-fpm.d]# cp www.conf.default www.conf
[root@master php-fpm.d]# ls
www.conf  www.conf.default
[root@master php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@master php-fpm.d]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process
LISTEN      0           128                  127.0.0.1:9000                0.0.0.0:*
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*
LISTEN      0           80                           *:3306                      *:*
LISTEN      0           128                          *:80                        *:*
LISTEN      0           128                       [::]:22                     [::]:*
[root@master php-fpm.d]#
[root@master php-fpm.d]# cd
[root@master ~]# chkconfig --add php-fpm
[root@master ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.

      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@master ~]#

3.4 配置apache

3.4.1 启用代理模块

在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:

  • LoadModule proxy_module modules/mod_proxy.so
  • LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
[root@master ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process
LISTEN      0           128                  127.0.0.1:9000                0.0.0.0:*
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*
LISTEN      0           80                           *:3306                      *:*
LISTEN      0           128                          *:80                        *:*
LISTEN      0           128                       [::]:22                     [::]:*
[root@master ~]# cd /usr/local/apache/conf/
[root@master conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@master conf]# vim httpd.conf
loadmodule proxy_module modules/mod_proxy.so
loadmodule proxy_fcgi_module modules/mod_proxy_fcgi.so(取消这两行注释)

3.4.2 配置虚拟主机

在需要使用fcgi的虚拟主机中添加类似如下两行:ProxyRequests Off //关闭正向代理
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1

[root@master conf]# ls /usr/local/apache/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@master conf]# ls /usr/local/apache/htdocs/
index.html
[root@master conf]# mkdir -p /usr/local/apache/htdocs/runtime
[root@master conf]# vim /usr/local/apache/htdocs/runtime/index.php

[root@master conf]# ll /usr/local/apache/htdocs/
total 4
-rw-r--r--. 1  504 games 45 Jun 12  2007 index.html
drwxr-xr-x  2 root root  23 Aug  4 08:46 runtime
[root@master conf]# ll /usr/local/apache/htdocs/runtime/
total 4
-rw-r--r-- 1 root root 23 Aug  4 08:46 index.php
[root@master conf]#  ls
extra  httpd.conf  magic  mime.types  original
[root@master conf]# cd extra/
[root@master extra]# ls
httpd-autoindex.conf  httpd-info.conf       httpd-mpm.conf                 httpd-userdir.conf
httpd-dav.conf        httpd-languages.conf  httpd-multilang-errordoc.conf  httpd-vhosts.conf
httpd-default.conf    httpd-manual.conf     httpd-ssl.conf                 proxy-html.conf
[root@master extra]#
[root@master extra]# vim httpd-vhosts.conf

    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName dummy-host.example.com
    ErrorLog "logs/runtime.example.com-error_log"
    CustomLog "logs/runtime.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/runtime/$1

        Options none
        AllowOverride none
        Require all granted

[root@master extra]# ls
httpd-autoindex.conf  httpd-info.conf       httpd-mpm.conf                 httpd-userdir.conf
httpd-dav.conf        httpd-languages.conf  httpd-multilang-errordoc.conf  httpd-vhosts.conf
httpd-default.conf    httpd-manual.conf     httpd-ssl.conf                 proxy-html.conf
[root@master extra]# cd ..

[root@master conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@master conf]# vim httpd.conf
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php    #添加此行
AddType application/x-httpd-php-source .phps#添加此行
Include conf/extra/httpd-vhosts.conf(取消注释)

    DirectoryIndex index.php index.html
(添加index.php)
[root@master conf]# systemctl restart httpd
[root@master conf]# systemctl status httpd
● httpd.service - web server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-08-04 09:07:27 CST; 29s ago
     Docs: man:httpd(5)
  Process: 142048 ExecStop=/usr/local/apache/bin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 142053 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 142057 (httpd)
    Tasks: 6 (limit: 24717)
   Memory: 5.9M
   CGroup: /system.slice/httpd.service
           ├─142057 /usr/local/apache/bin/httpd -k start
           ├─142058 /usr/local/apache/bin/httpd -k start
           ├─142059 /usr/local/apache/bin/httpd -k start
           ├─142060 /usr/local/apache/bin/httpd -k start
           ├─142061 /usr/local/apache/bin/httpd -k start
           └─142062 /usr/local/apache/bin/httpd -k start

Aug 04 09:07:12 master systemd[1]: Starting web server daemon...

Aug 04 09:07:27 master apachectl[142053]: AH00558: httpd: Could not reliably determine the server's full>
Aug 04 09:07:27 master systemd[1]: Started web server daemon.

lines 1-20/20 (END)

以上设置表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
注意:
这里写的/var/www/html/是yum源安装方式生成的网页存放目录,这里必须改成你编译安装指定的网页存放路径,禁止直接复制我这里的路径,这里的idfsoft.com是域名,你必须改成你所使用的域名,禁止直接复制此处的域名

这里的$1表示匹配所有以.php结尾的http请求

3.5 验证

lamp

Original: https://www.cnblogs.com/marymary/p/16545634.html
Author: 溜溜威
Title: lamp

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/505103/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 为什么说不变模式可以提高性能

    在Java中基础类型的包装类都是不可变的类,如Boolean、Byte、Character、Double、Float、Integer、Long、Short,另外还有String。这…

    数据库 2023年6月16日
    089
  • Typora + PicGo + Gitee 解放你对图片的管理

    计算机环境准备 Typora PicGo nodejs Typora官网: https://typora.io/ PicGo官网: https://picgo.github.io/…

    数据库 2023年6月9日
    073
  • MySQL45讲之InnoDB刷脏策略

    本文介绍 InnoDB 的刷脏控制策略,它是如何控制刷脏速率的,以及一些相关参数。 了解 MySQL 的刷脏策略有什么意义? 当一条正确的 SQL 执行时偶尔延迟较高,无法复现场景…

    数据库 2023年5月24日
    063
  • 常见的限流算法

    通过限制并发访问数或者限制一个时间窗口内允许处理的请求数量来保护系统,例如,通过限流,你可以过滤掉产生流量峰值的客户和服务。 令牌桶算法 令牌桶算法是常见的一种限流算法。假设有一个…

    数据库 2023年6月16日
    073
  • 操作线程的方法

    操作线程的方法操作线程有很多方法,这些方法可以使线程从某一种状态过渡到另一种状态。 线程的休眠能控制线程行为的方法之一是调用sleep()方法,sleep()方法可以指定线程休眠的…

    数据库 2023年6月16日
    073
  • 关于ThreadLocal的一道面试题

    问:上面这段代码会输出什么?为什么? 为什么输出1然后空指针了? 输出1是没有任何问题的。那空指针是为什么呢? 因为这是两个线程,子线程和主线程。子线程设置1,主线程肯定拿不到啊。…

    数据库 2023年6月16日
    091
  • Java学习-第一部分-第二阶段-第八节:IO流

    IO流 笔记目录:(https://www.cnblogs.com/wenjie2000/p/16378441.html) IO流体系图 文件 什么是文件 文件.对我们并不陌生,文…

    数据库 2023年6月11日
    082
  • 1001-MySQL学习-第一节自习课

    MySQL学习(第一节自习课) 一. 软件下载、安装 下载地址:https://dev.mysql.com/downloads/installer/ 位置:mysql->in…

    数据库 2023年5月24日
    086
  • mysql8使用tmpfs内存磁盘当内存数据库的配置方法

    内存关系数据库没有找到开源好用的,很多都是商用。虽然mysql有memory引擎,但写是整体锁表,没法用。 一直想将mysql放入内存中,搜索n次资料,没找到合适的,可能之前思路不…

    数据库 2023年5月24日
    095
  • MySQL函数学习(五)—–流程控制函数

    md函数笔记五 注:笔记旨在记录 五、MySQL 流程控制函数 0. 表 0.1 num表: 1. IF() — 条件判断 1.1. 函数: 1.2. sql示例: 2…

    数据库 2023年6月16日
    097
  • 设计模式之(9)——适配器模式

    定义:适配器模式是将一个类的接口转换成客户希望的另一个接口,适配器模式使得原本由于接口不兼容而不能一起工作的类可以一起工作,在软件设计中我们需要将一些”现存的对象&#8…

    数据库 2023年6月14日
    041
  • springcloud~nacos通过@refreshScope进行配置热更新

    配置类 @Data @ConfigurationProperties("auth") public class AuthProperties { private…

    数据库 2023年6月6日
    069
  • Tomcat8下的Redis会话共享

    前言: 最近在做网站的升级,从 Tomcat7升级到 Tomcat8版本,因为没接触过,就以为升级下Tomcat的版本就万事大吉,可是天不如人愿,很顺利的将应用升级到了Tomcat…

    数据库 2023年6月14日
    0100
  • django-Celery分布式队列简单使用

    介绍: Celery 是一个简单、灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必需工具。 它是一个专注于实时处理的任务队列,同时也支持任务调度。 worker…

    数据库 2023年6月6日
    091
  • fiddler的mock数据与二次开发示例

    fiddler的使用记录 fiddler了解 上官网下载工具,然后安装使用,https://www.telerik.com/fiddler,如果对该工具不熟悉,还有直白的教程,看过…

    数据库 2023年6月6日
    0102
  • FTP文件上传

    一、配置FTP文件服务器 以Ubuntu为例 FTP两种模式简介 PORT(主动模式)第一步FTP客户端首先随机选择一个大于1024的端口p1,并通过此端口发送请求连接到FTP服务…

    数据库 2023年6月6日
    085
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球