LAMP 架构介绍及环境搭建

7 篇文章 0 订阅

LAMP 架构介绍及环境搭建

1.LAMP

LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。

2. LAMP分别代表什么?

  • L代表服务器操作系统使用Linux
  • A代表网站服务使用的是Apache软件基金会中的httpd软件
  • M代表网站后台使用的数据库是MySQL数据库
  • P代表网站是使用PHP/Perl/Python等语言开发

3. web服务器工作流程

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

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

  • 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
  • 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端

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

查看源图像****

3.1 cgi与fastcgi

上图阶段①中提到了FastCGI,下面我们来了解下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上下文切换而导致耗时

3.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方式来加载动态资源

3.3 web工作流程

通过上面的图说明一下web的工作流程:

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

4. lamp平台构建

环境说明:

系统平台IP安装的服务
CentOS8192.168.159.167httpd-2.4 mysql-5.7 php php-mysql

4.1 安装httpd

//关闭防火墙与SELinux
[root@167 ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled  
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@167 ~]# 
[root@167 ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enab>
   Active: inactive (dead)
     Docs: man:firewalld(1)

Jul 21 08:49:34 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall dae>
Jul 21 08:49:35 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daem>
Jul 21 08:49:36 localhost.localdomain firewalld[938]: WARNING: AllowZoneDrifting is enabled>
Aug 02 21:46:52 167 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Aug 02 21:46:52 167 systemd[1]: firewalld.service: Succeeded.
Aug 02 21:46:52 167 systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@167 ~]# getenforce 
Enforcing
[root@167 ~]# 

//配置YUM源
[root@167 ~]# 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   4103      0 --:--:-- --:--:-- --:--:--  4103
[root@167 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@167 ~]# dnf -y install epel-release

//创建apache服务的用户与组
[root@167 ~]# useradd -Mrs /sbin/nologin apache
[root@167 ~]# id apache 
uid=994(apache) gid=991(apache) groups=991(apache)
[root@167 ~]# 

//安装开发工具包及依赖包
[root@167 ~]# dnf groups mark install 'Development Tools'
Repository extras is listed more than once in the configuration
Extra Packages for Enterprise Linux 8 - Next - x86_64        16 kB/s | 593 kB     00:37    
Last metadata expiration check: 0:00:01 ago on Tue 02 Aug 2022 09:56:25 PM CST.
Dependencies resolved.
============================================================================================
 Package              Architecture        Version                Repository            Size
============================================================================================
Installing Groups:
 Development Tools                                                                         

Transaction Summary
============================================================================================

Is this ok [y/N]: y
Complete!
[root@167 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++

//下载和安装apr和apr-util以及httpd
[root@167 ~]# wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
--2022-08-02 22:00:59--  https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.19.224.242, 111.19.224.243, 111.19.224.244, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.19.224.242|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/octet-stream]
Saving to: ‘apr-1.7.0.tar.gz’
apr-1.7.0.tar.gz       100%[============================>]   1.04M  6.03MB/s    in 0.2s    
2022-08-02 22:01:00 (6.03 MB/s) - ‘apr-1.7.0.tar.gz’ saved [1093896/1093896]

[root@167 ~]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
--2022-08-02 22:01:08--  https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.19.224.242, 111.19.224.243, 111.19.224.244, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.19.224.242|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/octet-stream]
Saving to: ‘apr-util-1.6.1.tar.gz’
apr-util-1.6.1.tar.gz  100%[============================>] 541.31K  3.47MB/s    in 0.2s    
2022-08-02 22:01:09 (3.47 MB/s) - ‘apr-util-1.6.1.tar.gz’ saved [554301/554301]

[root@167 ~]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
--2022-08-02 22:02:57--  https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.19.224.239, 111.19.224.240, 111.19.224.241, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.19.224.239|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/octet-stream]
Saving to: ‘httpd-2.4.54.tar.gz’
httpd-2.4.54.tar.gz    100%[============================>]   9.29M  14.0MB/s    in 0.7s    
2022-08-02 22:02:58 (14.0 MB/s) - ‘httpd-2.4.54.tar.gz’ saved [9743277/9743277]
[root@167 ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz  test.sh

//把源码包移至/usr/local/src位置下并解压
[root@167 ~]# mv apr* /usr/local/src/
[root@167 ~]# mv httpd-2.4.54.tar.gz /usr/local/src/
[root@167 ~]# cd /usr/local/src/
[root@167 src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@167 src]# tar -xf apr-1.7.0.tar.gz
[root@167 src]# tar -xf apr-util-1.6.1.tar.gz
[root@167 src]# tar -xf httpd-2.4.54.tar.gz
[root@167 src]# ls
apr-1.7.0         apr-util-1.6.1         httpd-2.4.54
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@167 src]# 

//编译安装apr与apr-util
[root@167 apr-1.7.0]# vi configure
cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
   # $RM "$cfgfile"   //将此行加上注释
[root@167 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@167 apr-1.7.0]# make && make install
[root@167 apr-1.7.0]# cd /usr/local/src/apr-util-1.6.1/
[root@167 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@167 apr-util-1.6.1]# make && make install
[root@167 src]# cd httpd-2.4.54/
[root@167 httpd-2.4.54]# ./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
[root@167 httpd-2.4.54]# make && make install

//安装后配置。映射头文件,库文件,man手册文件
[root@167 ~]# echo 'export PATH=$PATH:/usr/local/apache/bin/' > /etc/profile.d/httpd.sh
[root@167 ~]# source /etc/profile.d/httpd.sh
[root@167 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@167 ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config

//取消ServerName前面的注释
[root@167 ~]# sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf

//配置httpd开机自启的脚本
[root@167 ~]# vim /usr/lib/systemd/system/httpd.service
[root@167 ~]# cat /usr/lib/systemd/system/httpd.service 
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.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@167 ~]# 
[root@167 ~]# systemctl daemon-reload   //重载生效配置
[root@167 ~]# systemctl restart httpd.service   
[root@167 ~]# systemctl enable httpd.service   //httpd设为开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@167 ~]# ss -antl  //查看80端口是否打开
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                      *:80                      *:*                  
LISTEN    0         128                   [::]:22                   [::]:*                  
[root@167 ~]# 

4.2 安装mysql

//安装依赖包
[root@167 ~]# dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@167 ~]# useradd -Mrs /sbin/nologin mysql
[root@167 ~]# id mysql 
uid=993(mysql) gid=990(mysql) groups=990(mysql)
[root@167 ~]# 

//下载mysql二进制包,解压包
[root@167 src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@167 src]# ls
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
apr-util-1.6.1    httpd-2.4.54.tar.gz
[root@167 src]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@167 src]# cd /usr/local/
[root@167 local]# mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql
[root@167 local]# ls
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src
[root@167 local]# 

//修改目录的属主属组为mysql
[root@167 local]# chown -R mysql.mysql /usr/local/mysql/
[root@167 local]# ll
total 0
drwxr-xr-x. 14 root  root  164 Aug  2 23:07 apache
drwxr-xr-x.  6 root  root   58 Aug  2 22:52 apr
drwxr-xr-x.  5 root  root   43 Aug  2 22:54 apr-util
drwxr-xr-x.  2 root  root   21 Jun 28 09:36 bin
drwxr-xr-x.  2 root  root    6 Jun 22  2021 etc
drwxr-xr-x.  2 root  root    6 Jun 22  2021 games
drwxr-xr-x.  2 root  root    6 Jun 22  2021 include
drwxr-xr-x.  2 root  root    6 Jun 22  2021 lib
drwxr-xr-x.  3 root  root   17 Jun 27 20:10 lib64
drwxr-xr-x.  2 root  root    6 Jun 22  2021 libexec
drwxr-xr-x.  9 mysql mysql 129 Aug  2 23:20 mysql
drwxr-xr-x.  2 root  root    6 Jun 22  2021 sbin
drwxr-xr-x.  5 root  root   49 Jun 27 20:10 share
drwxr-xr-x.  5 root  root  195 Aug  2 23:19 src
[root@167 local]# 

//添加环境变量,映射头文件、库文件、man手册
[root@167 local]# cd mysql/
[root@167 mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@167 mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@167 mysql]# source /etc/profile.d/mysql.sh
[root@167 mysql]# ln -s /usr/local/mysql/include/ /usr/local/include/mysql
[root@167 mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@167 mysql]# ldconfig 
[root@167 mysql]# echo 'MANPATH /usr/local/mysql/man' >> /etc/man.config
[root@167 mysql]# 

//创建数据存放目录,并修改属主属组为mysql
[root@167 ~]# mkdir /opt/data
[root@167 ~]# chown -R mysql.mysql /opt/data/
[root@167 ~]# cd /opt/
[root@167 opt]# ll
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug  2 23:23 data
[root@167 opt]# 

//初始化数据库
[root@167 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-02T15:25:53.910357Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T15:25:54.116440Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T15:25:54.146527Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T15:25:54.204207Z 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: 661e950b-1277-11ed-9aa1-000c29e0e485.
2022-08-02T15:25:54.205156Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T15:25:54.416477Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T15:25:54.416495Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T15:25:54.416982Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T15:25:54.475531Z 1 [Note] A temporary password is generated for root@localhost: 2Y)yyE>*?;Q<
[root@167 ~]# 

//添加配置文件
[root@167 ~]# vim /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@167 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@167 ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@167 ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

//启动mysql
[root@167 ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/167.err'.
 SUCCESS! 
[root@167 ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process    
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@167 ~]# 

//修改数据库密码
[root@167 ~]# 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.38

Copyright (c) 2000, 2022, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
[root@167 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> quit
Bye
[root@167 ~]# 

mysql可能出现的错误及解决办法

[root@167 ~]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@167 ~]# 
[root@167 ~]# dnf provides libncurses.so.5
Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:40:59 ago on Tue 02 Aug 2022 10:53:10 PM CST.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : baseos
Matched from:
Provide    : libncurses.so.5

ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : base
Matched from:
Provide    : libncurses.so.5

ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : baseos
Matched from:
Provide    : libncurses.so.5

[root@167 ~]# dnf -y install ncurses-compat-libs

4.3 安装php

//从php官网下载php7的源码包
[root@167 ~]# wget https://www.php.net/distributions/php-7.4.30.tar.gz
--2022-08-02 23:38:43--  https://www.php.net/distributions/php-7.4.30.tar.gz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16866315 (16M) [application/octet-stream]
Saving to: ‘php-7.4.30.tar.gz’

php-7.4.30.tar.gz      100%[============================>]  16.08M  50.3KB/s    in 7m 30s  

2022-08-02 23:46:15 (36.6 KB/s) - ‘php-7.4.30.tar.gz’ saved [16866315/16866315]
//把这跟php官网的做对比如果一样就说明是完整的
[root@167 ~]# sha256sum php-7.4.30.tar.gz
e37ea37e0f79109351ac615da85eb7c2c336101fc5bc802ee79a124a4310dc10  php-7.4.30.tar.gz
[root@167 ~]# 

//安装依赖包
[root@167 ~]# dnf -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 php-mysqlnd

//解压源码包
[root@167 ~]# mv php-7.4.30.tar.gz /usr/local/src/
[root@167 ~]# cd /usr/local/src/
[root@167 src]# tar -xf php-7.4.30.tar.gz
[root@167 src]# 

//编译安装php
[root@167 php-7.4.30]# yum -y install libzip-devel
[root@167 php-7.4.30]# dnf -y install  libsqlite3x-devel
[root@167 php-7.4.30]# 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
[root@167 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 --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif  --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-json --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix
[root@167 php-7.4.30]# make install

//配置环境变量
[root@167 ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@167 ~]# source /etc/profile.d/php7.sh
[root@167 ~]# which php		//验证php的环境变量是否配置成功
/usr/local/php7/bin/php
[root@167 ~]# php -v			//查看php的版本信息
PHP 7.4.30 (cli) (built: Aug  2 2022 19:38:49) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

//配置php-fpm
[root@167~]# cd /usr/local/src/php-7.4.30/
[root@167 php-7.4.30]# cp php.ini-production /etc/php.ini
[root@167 php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@167 php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@167 php-7.4.30]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@167 php-7.4.30]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

//启动php
[root@167 php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@167 php-fpm.d]# service php-fpm status
php-fpm (pid 209351) is running...
[root@167 php-fpm.d]# ss -antl
State       Recv-Q       Send-Q             Local Address:Port             Peer Address:Port      Process
LISTEN      0            128                      0.0.0.0:22                    0.0.0.0:*
LISTEN      0            128                    127.0.0.1:9000                  0.0.0.0:*
LISTEN      0            80                             *:3306                        *:*
LISTEN      0            128                            *:80                          *:*
LISTEN      0            128                         [::]:22                       [::]:*
//报错信息
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
Package 'sqlite3', required by 'virtual:world', not found
解决方式:
[root@167 php-7.4.30]# dnf -y install  libsqlite3x-devel

//报错信息
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found
解决方式:
[root@167 php-7.4.30]# 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

//报错信息
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
解决方式:
[root@167 php-7.4.30]# yum -y install libzip-devel

5. 配置 apache

5.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
//启用httpd的相关模块
[root@167 ~]# sed -i '/proxy_module/s/#//g' /usr/local/apache/conf/httpd.conf
[root@167 ~]# sed -i '/proxy_fcgi_module/s/#//g' /usr/local/apache/conf/httpd.conf

5.2 配置虚拟主机

在需要使用fcgi的虚拟主机中添加类似如下两行:

ProxyRequests Off       //关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
[root@167 extra]# pwd
/usr/local/apache/conf/extra
[root@167 extra]# vim httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zwl"
    ServerName zwl.example.com
    ErrorLog "zwl.example.com-error_log"
    CustomLog "zwl.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zwl/$1  
    <Directory "/usr/local/apache/htdocs/zwl">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

[root@167 htdocs]# pwd
/usr/local/apache/htdocs
[root@167 htdocs]# mkdir zwl
[root@167 htdocs]# vim zwl/index.php
[root@167 htdocs]# cat zwl/index.php
<?php
    phpinfo();
?>

[root@167 conf]# pwd
/usr/local/apache/conf
//搜索AddType,添加以下内容
[root@167 conf]# vim httpd.conf
    AddType application/x-httpd-php .php  
    AddType application/x-httpd-php-source .phps
[root@167 conf]# sed -i '/    DirectoryIndex/s/index.html/index.php index.html/g' /usr/local/apache/conf/httpd.conf
[root@167 conf]# systemctl restart httpd.service

5.3 验证

在这里插入图片描述

6. 安装phpmyadmin

//下载phpmyadmin包
[root@167 ~]# wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip
[root@167 ~]# mv phpMyAdmin-5.2.0-all-languages.zip /usr/local/apache/htdocs/zwl/
[root@167 ~]# cd /usr/local/apache/htdocs/zwl/
[root@167 zwl]# unzip phpMyAdmin-5.2.0-all-languages.zip
//把目录的名字改为phpmyadmin
[root@167 zwl]# mv phpMyAdmin-5.2.0-all-languages/ phpmyadmin
[root@167 zwl]# cd phpmyadmin/
//复制样本配置文件到config.inc.php文件
[root@167 phpmyadmin]# cp config.sample.inc.php config.inc.php
[root@167 phpmyadmin]# systemctl restart httpd.service

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值