LAMP
文章目录
- LAMP
- 1. lamp简介
- 2. web服务器工作流程
- 2.1 cgi与fastcgi
- 2.2 httpd与php结合的方式
- 2.3 web工作流程
- 3. LAMP平台构建
- 3.1 安装httpd
- 3.2 安装mysql
- 3.3 安装php
- 3.4 验证
1. lamp简介
有了前面学习的知识的铺垫,今天可以来学习下第一个常用的web架构了。
所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。
2. web服务器工作流程
在说lamp架构平台的搭建前,我们先来了解下什么是CGI,什么是FastCGI,什么是…
web服务器的资源分为两种,静态资源和动态资源
- 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
- 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端
2.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上下文切换而导致耗时
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工作流程
通过上面的图说明一下web的工作流程:
- 客户端通过http协议请求web服务器资源
- web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
- 若是静态资源则直接从本地文件系统取之返回给客户端。
- 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
3. LAMP平台构建
3.1 安装httpd
1.安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make vim
Complete!2.创建系统用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# id apache
uid=991(apache) gid=991(apache) groups=991(apache)3.下载软件包(官网下apache.org)
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.58.tar.gz4.解压软件包
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz httpd-2.4.58.tar.gz
[root@localhost ~]# tar xf apr-1.7.4.tar.gz
[root@localhost ~]# tar xf apr-util-1.6.3.tar.gz
[root@localhost ~]# tar xf httpd-2.4.58.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.7.4 apr-1.7.4.tar.gz apr-util-1.6.3 apr-util-1.6.3.tar.gz httpd-2.4.58 httpd-2.4.58.tar.gz5.编译软件包
//apr-1.7.4
[root@localhost ~]# cd apr-1.7.4
[root@localhost apr-1.7.4]# ls
apr-config.in apr.pc.in buildconf configure encoding libapr.dsp Makefile.in network_io random support tools
apr.dep apr.spec build-outputs.mk configure.in file_io libapr.mak Makefile.win NOTICE README tables user
apr.dsp atomic CHANGES docs helpers libapr.rc memory NWGNUmakefile README.cmake test
apr.dsw build CMakeLists.txt dso include LICENSE misc passwd shmem threadproc
apr.mak build.conf config.layout emacs-mode libapr.dep locks mmap poll strings time
[root@localhost apr-1.7.4]# vim configurecfgfile=${ofile}Ttrap "$RM \"$cfgfile\"; exit 1" 1 2 15# $RM "$cfgfile" //注释这一行[root@localhost apr-1.7.4]# ./configure --prefix=/usr/local/apr
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/apr.h
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@localhost apr-1.7.4]# echo $?
0
[root@localhost apr-1.7.4]# ls //是否生成makefile文件
apr-1-config apr.mak build CMakeLists.txt configure encoding libapr.dsp locks misc passwd shmem threadproc
apr-config.in apr.pc build.conf config.layout configure.in file_io libapr.mak Makefile mmap poll strings time
apr.dep apr.pc.in buildconf config.log docs helpers libapr.rc Makefile.in network_io random support tools
apr.dsp apr.spec build-outputs.mk config.nice dso include libtool Makefile.win NOTICE README tables user
apr.dsw atomic CHANGES config.status emacs-mode libapr.dep LICENSE memory NWGNUmakefile README.cmake test
[root@localhost apr-1.7.4]# make
[root@localhost apr-1.7.4]# echo $?
0
[root@localhost apr-1.7.4]# make install
[root@localhost apr-1.7.4]# echo $?
0//apr-util-1.6.3
[root@localhost ~]# cd apr-util-1.6.3
[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.3]# echo $?
0
[root@localhost apr-util-1.6.3]# make
[root@localhost apr-util-1.6.3]# echo $?
0
[root@localhost apr-util-1.6.3]# make install
[root@localhost apr-util-1.6.3]# echo $?
0//httpd-2.4.58
[root@localhost ~]# cd httpd-2.4.58
[root@localhost httpd-2.4.58]# ./configure --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd24 \ //指定配置文件的位置,也可以不要这
> --enable-so \ //一行,默认就为/usr/local/apache/
> --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
configure: summary of build options:Server Version: 2.4.58Install prefix: /usr/local/apacheC compiler: gccCFLAGS: -g -O2 CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE LDFLAGS: LIBS: C preprocessor: gcc -E
[root@localhost httpd-2.4.58]# echo $?
0
[root@localhost httpd-2.4.58]# make
make[4]: Leaving directory '/root/httpd-2.4.58/modules/mappers'
make[3]: Leaving directory '/root/httpd-2.4.58/modules/mappers'
make[2]: Leaving directory '/root/httpd-2.4.58/modules'
make[2]: Entering directory '/root/httpd-2.4.58/support'
make[2]: Leaving directory '/root/httpd-2.4.58/support'make[1]: Leaving directory '/root/httpd-2.4.58'
[root@localhost httpd-2.4.58]# echo $?
0
[root@localhost httpd-2.4.58]# make install
[root@localhost httpd-2.4.58]# echo $?
06.配置环境变量
[root@localhost ~]# cd /usr/local/apache
[root@localhost apache]# ls
bin build cgi-bin error htdocs icons include logs man manual modules
[root@localhost apache]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost apache]# source /etc/profile.d/httpd.sh
[root@localhost apache]# which httpd
/usr/local/apache/bin/httpd[root@localhost apache]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@localhost apache]# 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
#---------------------------------------------------------7.启动apache
//取消这一行注释
[root@localhost ~]# cd /etc/httpd24/ //进入配置文件存放位置
[root@localhost httpd24]# ls
extra httpd.conf magic mime.types original
[root@localhost httpd24]# vim httpd.conf //编辑配置文件![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/822ee6c6b0f04afc8e041c34b5b4fbf3.png#pic_center)ServerName www.example.com:80
//启动
[root@localhost httpd24]# apachectl start
[root@localhost ~]# 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 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* 8.设置开机自启
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# apachectl stop
[root@localhost system]# 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 [::]:22 [::]:*
[root@localhost system]# vim httpd.service
[root@localhost system]# cat httpd.service
[Unit]
Description=httpd server daemon
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 system]# systemctl daemon-reload
[root@localhost system]# systemctl status httpd
○ httpd.service - httpd server daemonLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)Active: inactive (dead)
[root@localhost system]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost system]# systemctl status httpd
● httpd.service - httpd server daemonLoaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)Active: active (running) since Mon 2023-12-11 14:48:00 CST; 5s agoProcess: 222039 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, status=0/SUCCESS)Main PID: 222042 (httpd)Tasks: 6 (limit: 100179)Memory: 5.4MCPU: 31msCGroup: /system.slice/httpd.service├─222042 /usr/local/apache/bin/httpd -k start├─222043 /usr/local/apache/bin/httpd -k start├─222044 /usr/local/apache/bin/httpd -k start├─222045 /usr/local/apache/bin/httpd -k start├─222046 /usr/local/apache/bin/httpd -k start└─222047 /usr/local/apache/bin/httpd -k startDec 11 14:47:59 localhost.localdomain systemd[1]: Starting httpd server daemon...
Dec 11 14:48:00 localhost.localdomain systemd[1]: Started httpd server daemon.
[root@localhost system]# 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 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
3.2 安装mysql
1.安装依赖包
//mariadb-devel要到pkgs.org上面找这个软件包默认是没有的
[root@localhost ~]# yum -y install https://mirror.stream.centos.org/9-stream/CRB/x86_64/os/Packages/mariadb-devel-10.5.16-2.el9.x86_64.rpm[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake
Complete!2.创建系统用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=990(mysql) gid=990(mysql) groups=990(mysql)3.下载软件包(官网下:mysql.com,下了之后上传)
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.7.4 apr-1.7.4.tar.gz apr-util-1.6.3 apr-util-1.6.3.tar.gz httpd-2.4.58 httpd-2.4.58.tar.gz mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz4.解压软件包
[root@localhost ~]# tar xf mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz -C /usr/local
[root@localhost ~]# cd /usr/local
[root@localhost local]# ls
apache apr apr-util bin etc games include lib lib64 libexec mysql-8.0.35-linux-glibc2.28-x86_64 sbin share src
[root@localhost local]# mv mysql-8.0.35-linux-glibc2.28-x86_64 mysql
[root@localhost local]# ls
apache apr apr-util bin etc games include lib lib64 libexec mysql sbin share src5.配置环境变量
[root@localhost local]# cd mysql
[root@localhost mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@localhost mysql]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost mysql]# source /etc/profile.d/mysql.sh
[root@localhost mysql]# which mysql
/usr/local/mysql/bin/mysql//有include的情况下做软连接
[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql///有lib的情况下编辑文件读取lib库
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost mysql]# ldconfig -v//有man的情况下
[root@localhost mysql]# 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
#---------------------------------------------------------6.修改用户所有者和所属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql
total 296
drwxr-xr-x. 2 mysql mysql 4096 Oct 12 22:11 bin
drwxr-xr-x. 2 mysql mysql 38 Oct 12 22:11 docs
drwxr-xr-x. 3 mysql mysql 4096 Oct 12 22:11 include
drwxr-xr-x. 6 mysql mysql 4096 Oct 12 22:11 lib
-rw-r--r--. 1 mysql mysql 279355 Oct 12 19:45 LICENSE
drwxr-xr-x. 4 mysql mysql 30 Oct 12 22:11 man
-rw-r--r--. 1 mysql mysql 666 Oct 12 19:45 README
drwxr-xr-x. 28 mysql mysql 4096 Oct 12 22:11 share
drwxr-xr-x. 2 mysql mysql 77 Oct 12 22:11 support-files7.初始化
//创建目录并修改所有者和所属组
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll -d /opt/data
drwxr-xr-x. 2 mysql mysql 6 Dec 11 15:22 /opt/data[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data
2023-12-11T07:24:06.252033Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 391579
2023-12-11T07:24:06.263335Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-11T07:24:07.218571Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-11T07:24:08.957491Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ix9-C9/has)B
[root@localhost ~]# echo 'ix9-C9/has)B' > pass
[root@localhost ~]# cat pass
ix9-C9/has)B8.生成配置文件
[root@localhost ~]# vim /etc/my.cnf
[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-resolve9.配置服务启动脚本
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# ls
mysqld_multi.server mysql-log-rotate mysql.server
[root@localhost support-files]# mkdir /etc/init.d
[root@localhost support-files]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/opt/data
[root@localhost ~]# systemctl daemon-reload10.启动服务
//关闭防火墙
[root@localhost ~]# systemctl disable --now firewalld
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
SELINUX=disabled[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS!
[root@localhost ~]# 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 151 *:3306 *:*
LISTEN 0 70 *:33060 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* 11.设置开机自启
//先停掉服务
[root@localhost system]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost system]# 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 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* [root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service mysqld.service
[root@localhost system]# vim mysqld.service
[root@localhost system]# cat mysqld.service
[Unit]
Description=mysql server daemon
After=network.target [Service]
Type=forking
ExecStart=service mysqld start
ExecStop=service mysqld stop
ExecReload=/bin/kill -HUP $MAINPID[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl status mysqld
× mysqld.service - mysql server daemonLoaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: disabled)Active: failed (Result: exit-code) since Mon 2023-12-11 16:01:20 CST; 3min 3s agoDuration: 140msMain PID: 574012 (code=exited, status=1/FAILURE)CPU: 171ms
[root@localhost system]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost system]# systemctl status mysqld
● mysqld.service - mysql server daemonLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)Active: active (running) since Mon 2023-12-11 16:04:47 CST; 4s agoProcess: 590938 ExecStart=service mysqld start (code=exited, status=0/SUCCESS)Main PID: 590955 (mysqld_safe)Tasks: 39 (limit: 100179)Memory: 368.5MCPU: 964msCGroup: /system.slice/mysqld.service
[root@localhost system]# 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 151 *:3306 *:*
LISTEN 0 70 *:33060 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* 12.修改数据库密码
[root@localhost ~]# cat pass
ix9-C9/has)B
[root@localhost ~]# mysql -uroot -p'ix9-C9/has)B'
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 8
Server version: 8.0.35Copyright (c) 2000, 2023, 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> alter user root@localhost identified with mysql_native_password by 'Passw0rd@_';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye//用新密码登入
[root@localhost ~]# mysql -uroot -pPassw0rd@_
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 9
Server version: 8.0.35 MySQL Community Server - GPLCopyright (c) 2000, 2023, 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>
3.3 安装php
1.安装依赖包
[root@localhost ~]# yum list all | grep php | grep mysql
php-mysqlnd.x86_64 8.0.30-1.el9_2 appstream [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 readline readline-devel libxslt libxslt-devel php-mysqlnd
Complete!
[root@localhost ~]# echo $?
02.下载php软件包(官网下最新的:php.net)
[root@localhost ~]# wget https://www.php.net/distributions/php-8.3.0.tar.xz
[root@localhost ~]# ls
anaconda-ks.cfg apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz httpd-2.4.58.tar.gz pass
apr-1.7.4 apr-util-1.6.3 httpd-2.4.58 mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz php-8.3.0.tar.xz3.解压软件包
[root@localhost ~]# tar xf php-8.3.0.tar.xz
[root@localhost ~]# cd php-8.3.0
[root@localhost php-8.3.0]# ls
appveyor buildconf.bat configure.ac EXTENSIONS pear README.REDIST.BINS SECURITY.md UPGRADING
benchmark CODEOWNERS CONTRIBUTING.md LICENSE php.ini-development run-tests.php tests UPGRADING.INTERNALS
build CODING_STANDARDS.md docs main php.ini-production sapi travis win32
buildconf configure ext NEWS README.md scripts TSRM Zend4.编译安装php
[root@localhost php-8.3.0]# ./configure --prefix=/usr/local/php8 \
> --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 \
> --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
configure: WARNING: unrecognized options: --enable-inline-optimization, --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-json, --enable-zip
checking for grep that handles long lines and -e... /usr/bin/grep //开头的警告configure: error: Package requirements (sqlite3 >= 3.7.7) were not met: //结尾的报错
Package 'sqlite3', required by 'virtual:world', not found//解决方案
[root@localhost php-8.3.0]# ./configure --help | grep optimization
[root@localhost php-8.3.0]# ./configure --help | grep gd--with-gdbm[=DIR] DBA: GDBM support--enable-gd Include GD support--with-external-gd Use external libgd--with-avif GD: Enable AVIF support (only for bundled libgd)--with-webp GD: Enable WEBP support (only for bundled libgd)--with-jpeg GD: Enable JPEG support (only for bundled libgd)--with-xpm GD: Enable XPM support (only for bundled libgd)libgd)--enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support (onlyfor bundled libgd)
[root@localhost php-8.3.0]# ./configure --help | grep jpeg--with-jpeg GD: Enable JPEG support (only for bundled libgd)
[root@localhost php-8.3.0]# ./configure --help | grep png
[root@localhost php-8.3.0]# ./configure --help | grep freetype--with-freetype GD: Enable FreeType 2 support (only for bundled
[root@localhost php-8.3.0]#
[root@localhost php-8.3.0]# ./configure --help | grep json
[root@localhost php-8.3.0]# ./configure --help | grep zip--with-zip Include Zip read/write support//修改后重新编译
[root@localhost php-8.3.0]#./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 \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--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
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:
Package 'sqlite3', required by 'virtual:world', not found//解决方案
[root@localhost php-8.3.0]# yum -y install epel-release
[root@localhost php-8.3.0]# yum list all | grep sqlite3
libsqlite3x.x86_64 20071018-31.el9 epel
libsqlite3x-devel.x86_64 20071018-31.el9 epel
preludedb-sqlite3.x86_64 5.2.0-2.el9 epel
rubygem-sqlite3.x86_64 1.4.2-8.el9 epel
rubygem-sqlite3-doc.noarch 1.4.2-8.el9 epel
soci-sqlite3.x86_64 4.0.3-1.el9 epel
soci-sqlite3-devel.x86_64 4.0.3-1.el9 epel
uwsgi-plugin-sqlite3.x86_64 2.0.23-1.el9 epel
zabbix-dbfiles-sqlite3.noarch 1:6.0.22-2.el9 epel
zabbix-proxy-sqlite3.x86_64 1:6.0.22-2.el9 epel
[root@localhost php-8.3.0]# yum -y install libsqlite3x-devel
Complete!//重新编译
[root@localhost php-8.3.0]# ./configure --prefix=/usr/local/php8 \
.........
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found//解决方案
[root@localhost php-8.3.0]# yum list all | grep oniguruma
oniguruma.i686 6.9.6-1.el9.5 appstream
oniguruma.x86_64 6.9.6-1.el9.5 appstream
[root@localhost php-8.3.0]# cd
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
epel-cisco-openh264.repo epel.repo epel-testing.repo rocky-addons.repo rocky-devel.repo rocky-extras.repo rocky.repo
[root@localhost yum.repos.d]# vim rocky-devel.repo
[root@localhost yum.repos.d]# cat rocky-devel.repo
[devel]
name=Rocky Linux $releasever - Devel WARNING! FOR BUILDROOT ONLY DO NOT LEAVE ENABLED
mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=devel-$releasever$rltype
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/devel/$basearch/os/
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[root@localhost yum.repos.d]# yum list all | grep oniguruma
oniguruma.i686 6.9.6-1.el9.5 appstream
oniguruma.x86_64 6.9.6-1.el9.5 appstream
oniguruma.x86_64 6.9.6-1.el9.5 devel
oniguruma-devel.x86_64 6.9.6-1.el9.5 devel
[root@localhost php-8.3.0]# yum -y install oniguruma-devel
Complete!//重新编译
[root@localhost php-8.3.0]# ./configure --prefix=/usr/local/php8 \
........
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met: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@localhost php-8.3.0]# yum list all | grep libzip
libzip.i686 1.7.3-7.el9 appstream
libzip.x86_64 1.7.3-7.el9 appstream
libzip.x86_64 1.7.3-7.el9 devel
libzip-devel.x86_64 1.7.3-7.el9 devel
libzip-tools.x86_64 1.7.3-7.el9 devel
[root@localhost php-8.3.0]# yum -y install libzip-devel
Complete!//重新编译
[root@localhost php-8.3.0]# ./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 \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--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
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@localhost php-8.3.0]# make
[root@localhost php-8.3.0]# echo $?
0
[root@localhost php-8.3.0]# make install
[root@localhost php-8.3.0]# echo $?
05.配置环境变量
[root@localhost ~]# cd /usr/local/php8
[root@localhost php8]# ls
bin etc include lib php sbin var
[root@localhost php8]# echo 'export PATH=/usr/local/php8/bin:/usr/local/php8/sbin:$PATH' > /etc/profile.d/php8.sh
[root@localhost php8]# source /etc/profile.d/php8.sh
[root@localhost php8]# which php
/usr/local/php8/bin/php
[root@localhost php8]# php -v
PHP 8.3.0 (cli) (built: Dec 11 2023 17:25:44) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies6.配置php-fpm
[root@localhost ~]# cd php-8.3.0
[root@localhost php-8.3.0]# ls
appveyor CODEOWNERS configure EXTENSIONS main NEWS README.REDIST.BINS tests win32
benchmark CODING_STANDARDS.md configure.ac include Makefile pear run-tests.php travis Zend
build config.log CONTRIBUTING.md libs Makefile.fragments php.ini-development sapi TSRM
buildconf config.nice docs libtool Makefile.objects php.ini-production scripts UPGRADING
buildconf.bat config.status ext LICENSE modules README.md SECURITY.md UPGRADING.INTERNALS
[root@localhost php-8.3.0]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-8.3.0]#
[root@localhost php-8.3.0]# cd sapi
[root@localhost sapi]# ls
apache2handler cgi cli embed fpm fuzzer litespeed phpdbg
[root@localhost sapi]# cd fpm
[root@localhost fpm]# ls
config.m4 fpm init.d.php-fpm.in Makefile.frag php-fpm.8 php-fpm.conf php-fpm.service status.html tests www.conf.in
CREDITS init.d.php-fpm LICENSE php-fpm php-fpm.8.in php-fpm.conf.in php-fpm.service.in status.html.in www.conf
[root@localhost php-8.3.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.3.0]# chmod +x /etc/init.d/php-fpm
[root@localhost php-8.3.0]# ll -d /etc/init.d/php-fpm
-rwxr-xr-x. 1 root root 2402 Dec 11 17:53 /etc/init.d/php-fpm[root@localhost ~]# cd /usr/local/php8
[root@localhost php8]# ls
bin etc include lib php sbin var
[root@localhost php8]# cd /etc
[root@localhost etc]# mv /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost etc]# mv /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf7.启动php.fpm
[root@localhost ~]# service php-fpm start
Starting php-fpm done
[root@localhost ~]# 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 4096 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 151 *:3306 *:*
LISTEN 0 70 *:33060 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* 8.配置apache
//启用代理模块
[root@localhost ~]# vim /etc/httpd24/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 //取消这一行注释
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
#LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
#LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so//配置虚拟主机测试页面
[root@localhost ~]# cd /usr/local/apache
[root@localhost apache]# ls
bin build cgi-bin error htdocs icons include logs man manual modules
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir test
[root@localhost htdocs]# ls
index.html test
[root@localhost htdocs]# cd test
[root@localhost test]# vim index.php
[root@localhost test]# cat index.php
<?php
phpinfo();
?>
[root@localhost test]# chown -R apache.apache /usr/local/apache/htdocs///设置vhosts
[root@localhost ~]# vim /etc/httpd24/httpd.conf
# Virtual hosts
#Include /etc/httpd24/extra/httpd-vhosts.conf
Include /etc/httpd24/extra/vhosts.conf//添加vhosts
[root@localhost ~]# cd /etc/httpd24/
[root@localhost httpd24]# ls
extra httpd.conf magic mime.types original
[root@localhost httpd24]# cd extra/
[root@localhost extra]# ls
httpd-autoindex.conf httpd-default.conf httpd-languages.conf httpd-mpm.conf httpd-ssl.conf httpd-vhosts.conf
httpd-dav.conf httpd-info.conf httpd-manual.conf httpd-multilang-errordoc.conf httpd-userdir.conf proxy-html.conf
[root@localhost extra]# vim vhosts.conf
[root@localhost extra]# cat vhosts.conf
<VirtualHost *:80>DocumentRoot "/usr/local/apache/htdocs/test"ServerName www.test.comProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1<Directory "/usr/local/apache/htdocs/test">Options noneAllowOverride noneRequire all granted</Directory>
</VirtualHost> //添加php的类型
[root@localhost ~]# vim /etc/httpd24/httpd.conf #AddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType application/x-httpd-php .php //添加这一行AddType application/x-httpd-php-source .phps //添加这一行 #//添加访问文件
[root@localhost ~]# vim /etc/httpd24/httpd.conf (进去之后用/index.html,搜索到指定页面)
#
<IfModule dir_module>DirectoryIndex index.html index.php //添加index.php,在index.html前面和后面添加都可以
</IfModule>//重启apache服务与php-fpm
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done