lamp架构

lamp简介

Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序(除了Linux外),但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台

从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案

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

优势:免费和开源

web服务器工作流程

Web资源介绍

html:静态资源 ,可以理解为前端的固定页面,这里面包含HTML、CSS、JS、图片等等,不需要查数据库也不需要程序处理,直接就能够显示的页面,如果想修改内容则必须修改页面,但是访问效率相当高。

JSP/Servlet:动态资源 需要程序处理或者从数据库中读数据,能够根据不同的条件在页面显示不同的数据,内容更新不需要修改页面但是访问速度不及静态页面。(,需要先转换成html,再给浏览器看 )

补充:

xx.php (Linux)
xx.jsp (C++)
xx.do (java)
xx.py (python)
xx.wsgi(python)
在这里插入图片描述

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上下文切换而导致耗时

在这里插入图片描述
批注:较于CGI方式,FastCGI更为常用,很少有人使用CGI方式来加载动态资源

lamp平台构建

环境说明:

IP需要安装的服务
192.168.142.101httpd-2.4 mysql-5.7 php php-mysql

lamp平台软件安装次序:

httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

安装安装包
[root@localhost src ~]# wget http://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz
--2021-09-24 11:50:58--  http://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9421895 (9.0M) [application/x-gzip]
正在保存至: “httpd-2.4.49.tar.gz”

httpd-2.4.49.tar.gz  100%[=====================>]   8.99M  2.83MB/s  用时 3.2s    

2021-09-24 11:51:01 (2.83 MB/s) - 已保存 “httpd-2.4.49.tar.gz” [9421895/9421895])

[root@localhost src ~]# wget http://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
--2021-09-24 11:51:21--  http://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1093896 (1.0M) [application/x-gzip]
正在保存至: “apr-1.7.0.tar.gz”

apr-1.7.0.tar.gz     100%[=====================>]   1.04M  2.03MB/s  用时 0.5s    

2021-09-24 11:51:22 (2.03 MB/s) - 已保存 “apr-1.7.0.tar.gz” [1093896/1093896])

[root@localhost src ~]# wget http://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz
--2021-09-24 11:51:31--  http://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:554301 (541K) [application/x-gzip]
正在保存至: “apr-util-1.6.1.tar.gz”

apr-util-1.6.1.tar.g 100%[=====================>] 541.31K  1.64MB/s  用时 0.3s    

2021-09-24 11:51:32 (1.64 MB/s) - 已保存 “apr-util-1.6.1.tar.gz” [554301/554301])

[root@localhost src ~]# tar xf apr-1.7.0.tar.gz 
[root@localhost src ~]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost src ~]# tar xf httpd-2.4.49.tar.gz 
[root@localhost src ~]# ls
公共  文档  anaconda-ks.cfg   apr-util-1.6.1.tar.gz  lamp
模板  下载  apr-1.7.0         httpd-2.4.49
视频  音乐  apr-1.7.0.tar.gz  httpd-2.4.49.tar.gz
图片  桌面  apr-util-1.6.1    initial-setup-ks.cfg

#安装依赖包
[root@localhost src ~]# yum -y groups mark install 'Development Tools'
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:02:24 前,执行于 20210924日 星期五 120027秒。
依赖关系解决。
===================================================================================
 软件包             架构              版本                仓库                大小
===================================================================================
安装组:
 Development Tools                                                                

事务概要
===================================================================================

完毕!

[root@localhost src ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:03:18 前,执行于 20210924日 星期五 120027秒。
依赖关系解决。
===================================================================================
 软件包                   架构        版本                    仓库            大小
===================================================================================
安装:
 expat-devel              x86_64      2.2.5-3.el8             BaseOS          55 k
 gcc                      x86_64      8.3.1-5.el8             Appstream       23 M
 gcc-c++                  x86_64      8.3.1-5.el8             Appstream       12 M
 libtool                  x86_64      2.4.6-25.el8            Appstream      709 k
 make                     x86_64      1:4.2.1-10.el8          BaseOS         498 k
 openssl-devel            x86_64      1:1.1.1c-15.el8         BaseOS         2.3 M
 pcre-devel               x86_64      8.42-4.el8              BaseOS         551 k
安装依赖关系:
···

[root@localhost src ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure

 cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"    #注释掉

#编译安装
[root@localhost apr-1.7.0]# ./configure --prefix=/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
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.7.0
checking for chosen layout... apr
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed

[root@localhost apr-1.7.0]# make && make install
···
/usr/bin/install -c -m 755 /root/apr-1.7.0/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do \
    /usr/bin/install -c -m 644 /root/apr-1.7.0/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
#进行编译
[root@localhost ~]# cd /usr/src/apr-util-1.6.1/
[root@localhost 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
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
APR-util Version: 1.6.1
checking for chosen layout... apr-util
checking for gcc... gcc

[root@localhost apr-util-1.6.1]# make && make install
···
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config

[root@localhost apr-util-1.6.1]# cd /usr/src/httpd-2.4.49/
[root@localhost httpd-2.4.49]# ./configure --prefix=/usr/local/apache \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
>  --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
checking for chosen layout... Apache
checking for working mkdir -p... yes
···
configure: summary of build options:

    Server Version: 2.4.49
    Install prefix: /usr/local/apache
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

[root@localhost httpd-2.4.49]# make && make install
···
Installing build system files
mkdir /usr/local/apache/build
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: 离开目录“/usr/src/httpd-2.4.49[root@localhost httpd-2.4.49]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man

#去掉注释
[root@localhost httpd-2.4.49]# vim /usr/local/apache/conf/httpd.conf 

ServerName www.example.com:80

#启动apache查看是否开启
[root@localhost httpd-2.4.49]# apachectl start
[root@localhost httpd-2.4.49]# ss -anlt
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*   

[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=Httpd server daemon
Documentation=man:httpd(8)
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status httpd.service 
● httpd.service - Httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:>
   Active: inactive (dead)
     Docs: man:httpd(8)

924 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
924 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
924 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
924 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
924 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
924 12:33:33 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
lines 1-11/11 (END)
[root@localhost ~]# apachectl stop  
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl status httpd.service 
● httpd.service - Httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: >
   Active: active (running) since Fri 2021-09-24 12:36:03 CST; 8s ago
     Docs: man:httpd(8)
  Process: 151521 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, st>
 Main PID: 151524 (httpd)
    Tasks: 6 (limit: 4704)
   Memory: 8.5M
   CGroup: /system.slice/httpd.service
           ├─151524 /usr/local/apache/bin/httpd -k start
           ├─151525 /usr/local/apache/bin/httpd -k start
           ├─151526 /usr/local/apache/bin/httpd -k start
           ├─151527 /usr/local/apache/bin/httpd -k start
           ├─151528 /usr/local/apache/bin/httpd -k start
           └─151529 /usr/local/apache/bin/httpd -k start

安装mysql
[root@localhost ~]#  yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:36:53 前,执行于 20210924日 星期五 120027秒。
软件包 openssl-devel-1:1.1.1c-15.el8.x86_64 已安装。
软件包 openssl-1:1.1.1c-15.el8.x86_64 已安装。
依赖关系解决。
===================================================================================
 软件包                     架构   版本                            仓库       大小
===================================================================================
安装:
 cmake                      x86_64 3.11.4-7.el8                    Appstream 8.1 M
 mariadb-devel              x86_64 3:10.3.17-1.module+el8.1.0+3974+90eded84
                                                                   Appstream 1.0 M
 ncurses-devel              x86_64 6.1-7.20180224.el8              BaseOS    528 k
安装依赖关系:
 cmake-data                 noarch 3.11.4-7.el8                    Appstream 1.3 M

[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

[root@localhost src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql

[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 14 root  root  164 924 12:25 apache
drwxr-xr-x.  6 root  root   58 924 12:09 apr
drwxr-xr-x.  5 root  root   43 924 12:15 apr-util
drwxr-xr-x.  2 root  root    6 812 2018 bin
drwxr-xr-x.  2 root  root    6 812 2018 etc
drwxr-xr-x.  2 root  root    6 812 2018 games
drwxr-xr-x.  2 root  root    6 812 2018 include
drwxr-xr-x.  2 root  root    6 812 2018 lib
drwxr-xr-x.  2 root  root    6 812 2018 lib64
drwxr-xr-x.  2 root  root    6 812 2018 libexec
drwxr-xr-x.  9 mysql mysql 129 924 12:43 mysql
drwxr-xr-x.  2 root  root    6 812 2018 sbin
drwxr-xr-x.  5 root  root   49 916 16:00 share
drwxr-xr-x.  2 root  root    6 812 2018 src

[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql
[root@localhost local]# cd
[root@localhost ~]# vim /etc/man_db.conf 

MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man

[root@localhost ~]# vim /etc/man_db.conf 
[root@localhost ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql/
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib

#初始数据库
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown  -R mysql.mysql /opt/data/
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-09-24T04:46:56.112922Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-24T04:46:56.755191Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-24T04:46:56.819335Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-24T04:46:56.919882Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 726f3b76-1cf2-11ec-8dea-000c29e514ad.
2021-09-24T04:46:56.921213Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-24T04:46:56.922434Z 1 [Note] A temporary password is generated for root@localhost: B#ggxi<fJ3H:

[root@localhost ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
[root@localhost ~]# vim /usr/local/mysql/support-files/mysql.server 

basedir=/usr/local/mysql
datadir=/opt/data

[root@localhost ~]# cp /usr/lib/systemd/system/httpd.service  /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# vim  /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# cat  /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/support-files/mysql.service start
ExecStop=/usr/local/support-files/mysql.service stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

[root@localhost ~]# ps -ef|grep mysql
root      182943  165702  0 12:51 pts/1    00:00:00 grep --color=auto mysql
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*    

[root@localhost ~]# yum -y install ncurses-compat-libs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:51:30 前,执行于 20210924日 星期五 120027秒。
依赖关系解决。
===================================================================================
 软件包                   架构        版本                       仓库         大小
===================================================================================
安装:
 ncurses-compat-libs      x86_64      6.1-7.20180224.el8         BaseOS      331 k

事务概要
===================================================================================
安装  1 软件包

#进入mysql验证

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('1');
Query OK, 0 rows affected, 1 warning (0.09 sec)

安装php
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
上次元数据过期检查:0:54:30 前,执行于 20210924日 星期五 120027秒。
软件包 libxml2-2.9.7-7.el8.x86_64 已安装。
软件包 openssl-1:1.1.1c-15.el8.x86_64 已安装。
软件包 openssl-devel-1:1.1.1c-15.el8.x86_64 已安装。
软件包 bzip2-1.0.6-26.el8.x86_64 已安装。
软件包 libcurl-7.61.1-12.el8.x86_64 已安装。
软件包 libjpeg-turbo-1.5.3-10.el8.x86_64 已安装。
软件包 libpng-2:1.6.34-5.el8.x86_64 已安装。
软件包 pcre-devel-8.42-4.el8.x86_64 已安装。
软件包 freetype-2.9.1-4.el8.x86_64 已安装。
软件包 gmp-1:6.1.2-10.el8.x86_64 已安装。
No match for argument: libmcrypt
No match for argument: libmcrypt-devel
软件包 readline-7.0-10.el8.x86_64 已安装。
软件包 libxslt-1.1.32-4.el8.x86_64 已安装。

[root@localhost ~]#  yum -y install php-mysqlnd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:55:54 前,执行于 20210924日 星期五 120027秒。
依赖关系解决。
===================================================================================
 软件包        架构     版本                                     仓库         大小
===================================================================================
安装:
 php-mysqlnd   x86_64   7.2.24-1.module+el8.2.0+4601+7c76a223    Appstream   191 k
安装依赖关系:
 php-common    x86_64   7.2.24-1.module+el8.2.0+4601+7c76a223    Appstream   662 k
 php-pdo       x86_64   7.2.24-1.module+el8.2.0+4601+7c76a223    Appstream   123 k
启用模块流:

root@localhost src]# tar xf php-8.0.10.tar.xz 


[root@localhost ~]# yum -y install libsqlite3x-devel
[root@localhost php-8.0.10]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm --skip-broken

[root@localhost php-8.0.10]# ./configure --prefix=/usr/local/php8  \
> --with-config-file-path=/etc \
> --enable-fpm \
> --disable-debug \
> --disable-rpath \
> --enable-shared \
> --enable-soap \
> --with-openssl \
> --enable-bcmath \
> --with-iconv \
> --with-bz2 \
> --enable-calendar \
> --with-curl \
> --enable-exif  \
> --enable-ftp \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-zlib-dir \
> --with-freetype-dir \
> --with-gettext \
> --enable-json \
> --enable-mbstring \
> --enable-pdo \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-readline \
> --enable-shmop \
> --enable-simplexml \
> --enable-sockets \
> --enable-zip \
> --enable-mysqlnd-compression-support \
> --with-pear \
> --enable-pcntl \
> --enable-posix

·······················
+--------------------------------------------------------------------+
| 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@localhost php-8.0.10]# make && make install

//安装后配置
[root@localhost ~]#  echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@localhost ~]# source /etc/profile.d/php.sh

[root@localhost php-8.0.10]# cp  php.ini-production /etc/php.ini
cp:是否覆盖'/etc/php.ini'? y
[root@localhost php-8.0.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.0.10]#  chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-8.0.10]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost php-8.0.10]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf


[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
//取消两行注释


[root@localhost ~]# cp /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php server daemon
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop==/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl enable --now php-fpm.service 
[root@localhost ~]# systemctl status php-fpm.service 
● php-fpm.service - php server daemon
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-09-23 12:42:12 EDT; 5s ago
  Process: 124457 ExecStart=/etc/init.d/php-fpm start (code=exited, status=0/SUCCESS)
 Main PID: 124459 (php-fpm)
    Tasks: 3 (limit: 16496)
   Memory: 9.8M
   CGroup: /system.slice/php-fpm.service
           ├─124459 php-fpm: master process (/usr/local/php8/etc/php-fpm.conf)
           ├─124460 php-fpm: pool www
           └─124461 php-fpm: pool www

[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   
LISTEN    0         128              127.0.0.1:9000            0.0.0.0:*                 
LISTEN    0         80                       *:3306                  *:*      
LISTEN    0         128                   [::]:111                [::]:*      
LISTEN    0         128                      *:80                    *:*      
LISTEN    0         128                   [::]:22                 [::]:*      
LISTEN    0         5                    [::1]:631                [::]:* 

[root@localhost ~]# ps -ef|grep php
root      119755    2197  0 12:41 pts/2    00:00:00 systemctl status php-fpm.service
root      124459       1  0 12:42 ?        00:00:00 php-fpm: master process (/usr/local/php8/etc/php-fpm.conf)
nobody    124460  124459  0 12:42 ?        00:00:00 php-fpm: pool www
nobody    124461  124459  0 12:42 ?        00:00:00 php-fpm: pool www
root      134100    2197  0 12:44 pts/2    00:00:00 grep --color=auto php

[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir test
[root@localhost htdocs]# vim test/index.php
[root@localhost htdocs]# cat test/index.php 
<?php
   phpinfo();
?>


[root@localhost apache]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost apache]# vim conf/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        #添加此行

//加在最后
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test"
    ServerName www.yy.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/yy.com/$1
    <Directory "/usr/local/apache/htdocs/yy.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>


<IfModule dir_module>
    DirectoryIndex index.php index.html     //添加index.php
</IfModule>

[root@localhost ~]# systemctl restart httpd.service 

验证

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值