LAMP架构(编译)

LAMP

文章目录

    • LAMP
      • 一、Linux
      • 二、Apache
      • 三、Mysql
      • 四、PHP

LMAP即Linux+Apache+Mysql/MariaDB+Perl/PHP/Python的首字母缩写。这是一组常用来搭建动态网站或者服务器的开源软件。它们本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案。

LAMP流程

1.用户发送http请求到达httpd服务器

2.httpd解析url获取需要的资源路径,通过内核空间读取硬盘资源,如果是静态资源,则构建响应报文,发回给用户

3.如果是动态资源,将资源地址发给php解析器,解析php程序文件,解析完毕将内容发回给httpd,httpd构建响应报文,发回给用户

4.如果涉及到数据库操作,则利用php-mysql驱动,获取数据库数据,返回给PHP解析器

LAMP架构(编译)_第1张图片

配置网络源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

搭建过程中涉及编译

先安装以下工具

dnf -y install  Tools gcc gcc-c++ make pcre-devel expat-devel perl openssl-devel libtool
yum groups mark install 'Development Tools'

一、Linux

Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的UNIX工具软件、应用程序和网络协议。它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。

二、Apache

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。

Apache的主程序名叫httpd。

下载

Apr https://mirrors.tuna.tsinghua.edu.cn/apache/apr/

Httpd https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/

[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.48.tar.gz
[root@localhost ~]# 
[root@localhost src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.48.tar.gz  kernels

//安装依赖包

yum -y install openssl-devel pcre-devel expat-devel libtool 

//创建apache服务的用户和组

[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache 

//安装apr、apr-util

[root@localhost src]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# ls
apr-config.in  build.conf        dso         libapr.rc     NOTICE         support
apr.dep        buildconf         emacs-mode  LICENSE       NWGNUmakefile  tables
apr.dsp        build-outputs.mk  encoding    locks         passwd         test
apr.dsw        CHANGES           file_io     Makefile.in   poll           threadproc
apr.mak        CMakeLists.txt    helpers     Makefile.win  random         time
apr.pc.in      config.layout     include     memory        README         tools
apr.spec       configure         libapr.dep  misc          README.cmake   user
atomic         configure.in      libapr.dsp  mmap          shmem
build          docs              libapr.mak  network_io    strings
[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
配置过程略...
[root@localhost apr-1.7.0]# make && make install
编译安装过程略...

[root@localhost apr-1.7.0]# 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
配置过程略...
[root@localhost apr-util-1.6.1]# make && make install
编译安装过程略...

//编译安装httpd

[root@localhost src]# tar xf httpd-2.4.48.tar.gz
[root@localhost src]# cd httpd-2.4.48/
[root@localhost httpd-2.4.48]# ./configure --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd24 \
> --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@localhost httpd-2.4.48]# make && make install
编译安装过程略...

//配置环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh

//链接

[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config

//取消ServerName前面的注释

[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf 

//关闭防火墙

[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

//启动服务

[root@localhost ~]# apachectl start
[root@localhost ~]# ss -anlt
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*        
LISTEN      0           128                          *:80                        *:*        
LISTEN      0           128                       [::]:22                     [::]:*        

//测试

LAMP架构(编译)_第2张图片

//配置service文件

[root@localhost ~]# cat /usr/lib/systemd/system/sshd.service > /usr/lib/systemd/system/httpd.service
[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service 
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service 
[Unit]
Description=OpenSSH 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@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# apachectl stop
[root@localhost ~]# ss -anlt
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*        
LISTEN      0           128                       [::]:22                     [::]:*    

三、Mysql

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。

MariaDB为MySQL的一个分支软件。

下载

wget https://downloads.mysql.com/archives/get/file/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz

//安装依赖包

yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组

[root@localhost local]# groupadd -r -g 306 mysql
[root@localhost local]#  useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql

//解压至/usr/local

[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz /usr/src/
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls
debug  kernels  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.35-linux-glibc2.12-x86_64  share
[root@localhost local]# ln -sv  mysql-5.7.35-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.35-linux-glibc2.12-x86_64/'
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root   6 8月  12 2018 bin
drwxr-xr-x. 2 root root   6 8月  12 2018 etc
drwxr-xr-x. 2 root root   6 8月  12 2018 games
drwxr-xr-x. 2 root root   6 8月  12 2018 include
drwxr-xr-x. 2 root root   6 8月  12 2018 lib
drwxr-xr-x. 2 root root   6 8月  12 2018 lib64
drwxr-xr-x. 2 root root   6 8月  12 2018 libexec
lrwxrwxrwx. 1 root root  36 9月  23 19:47 mysql -> mysql-5.7.35-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 9月  23 19:46 mysql-5.7.35-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 8月  12 2018 sbin
drwxr-xr-x. 5 root root  49 9月   2 09:41 share
drwxr-xr-x. 2 root root   6 8月  12 2018 src

//修改目录/usr/local/mysql的属主属组

[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql -d

//添加环境变量

[root@localhost local]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//建立数据存放目录

[root@localhost local]# mkdir -p /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost local]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 9月  23 19:52 data

//配置mysql

[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig      

//初始化数据库

[root@localhost local]# mysqld --initialize-insecure --user=mysql --datadir=/opt/data
2021-09-23T11:58:03.537145Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-23T11:58:03.843259Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-23T11:58:03.902159Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-23T11:58:03.980673Z 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: 81fdb57a-1c65-11ec-ae36-000c29e544fe.
2021-09-23T11:58:03.983002Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-23T11:58:05.645966Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-09-23T11:58:05.646015Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-09-23T11:58:05.647642Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-23T11:58:06.131398Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

//生成配置文件

[root@localhost local]# 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
> EOF

//配置service文件

[root@localhost local]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd//system/mysqld.server
[root@localhost localvim /usr/lib/systemd//system/mysqld.server

[Unit]
Description=Mysql server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
[root@localhost support-files]# vim /usr/local/mysql/support-files/mysql.server 

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

//指定路径
basedir= /usr/local/mysql
datadir=/opt/data

//设置开机自启

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start mysqld 
[root@localhost ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port 
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*    
LISTEN 0      80                 *:3306             *:*    
LISTEN 0      128                *:80               *:*    
LISTEN 0      128             [::]:22            [::]:* 

//设置密码
mysql> set password = password("xu1");
Query OK, 0 rows affected, 1 warning (0.00 sec)

四、PHP

PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。

//进入官方下载PHP8.0.10源码包

PHP

[root@localhost ~]# ls
anaconda-ks.cfg  php-8.0.10.tar.gz
[root@localhost ~]# mv php-8.0.10.tar.gz /usr/src/
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  php-8.0.10.tar.gz

//安装依赖包

 yum -y installyum -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.x86_64

//编译安装PHP

[root@localhost src]# tar xf php-8.0.10.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/php-8.0.10/
[root@localhost php-8.0.10]# 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

编译过程中的4个问题

1.报错 sqlite3 版本过低

checking whether to enable the SQLite3 extension... yes
checking for sqlite3 > 3.7.4... no
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

Package 'sqlite3', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

// 过滤出版本大于 3.7.4的sqlite

[root@localhost php-8.0.10]# yum list all | grep sqlite3
libsqlite3x.x86_64                                                20071018-26.el8                                   epel         
libsqlite3x-devel.x86_64                                          20071018-26.el8                                   epel         
preludedb-sqlite3.x86_64                                          5.2.0-1.el8                                       epel         
rubygem-sqlite3.x86_64                                            1.4.2-2.el8                                       epel         
rubygem-sqlite3-doc.noarch                                        1.4.2-2.el8                                       epel         
soci-sqlite3.x86_64                                               4.0.0-2.el8                                       epel         
soci-sqlite3-devel.x86_64                                         4.0.0-2.el8                                       epel         
zabbix40-dbfiles-sqlite3.noarch                                   4.0.29-1.el8                                      epel         
zabbix40-proxy-sqlite3.x86_64                                     4.0.29-1.el8                                      epel         

//找到并安装

yum -y install libsqlite3x-devel.x86_64

2.configure: WARNING: unrecognized options: --enable-inline-optimization, --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-json, --enable-zip (无法识别选项)

原因是因为PHP源码包版本更新后,选项会有变动

//使用 ./configure --help|grep命令过滤 选项关键字,可以搜索到的保留,搜索不到的剔除

[root@localhost php-8.0.10]# ./configure --help|grep inline-optimization
[root@localhost php-8.0.10]# 剔除

[root@localhost php-8.0.10]# ./configure --help|grep gd
  --with-gdbm[=DIR]       DBA: GDBM support
  --enable-gd             Include GD support
// 保留--enable-gd

[root@localhost php-8.0.10]# ./configure --help|grep jpeg
  --with-jpeg             GD: Enable JPEG support (only for bundled libgd)
// 保留 --with-jpeg

[root@localhost php-8.0.10]# ./configure --help|grep png
[root@localhost php-8.0.10]# 
//剔除

[root@localhost php-8.0.10]# ./configure --help|grep freetype
  --with-freetype         GD: Enable FreeType 2 support (only for bundled
//保留 --with-freetype

[root@localhost php-8.0.10]#  ./configure --help|grep json
[root@localhost php-8.0.10]# 
//剔除

[root@localhost php-8.0.10]#  ./configure --help|grep zip
  --with-zip              Include Zip read/write support
//保留 --with-zip 

将编译命令中的选项进行修改

./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

3.Package ‘libzip’, required by ‘virtual:world’, not found

未找到“virtual:world”所需的包“libzip”

解决依赖

//使用 yum list all | grep 过滤出所需的依赖包

[root@localhost ~]# yum list all | grep libzip
libzip.x86_64                                                     1.5.1-2.module_el8.2.0+313+b04d0a66               AppStream    
libzip-devel.x86_64                                               1.5.1-2.module_el8.2.0+313+b04d0a66               AppStream    
libzip-tools.x86_64                                               1.5.1-2.module_el8.2.0+313+b04d0a66               AppStream    

//下载

yum -y install libzip-devel.x86_64

4.package ‘oniguruma’ required by ‘virtual:word’,not found

‘virtual:word’ 需要的包 ‘oniguruma’,未找到

解决依赖

oniguruma-devel-6.8.2-2.el8.x86_64.rpm

// 下载安装

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

//执行修改后的编译命令 直至出现以下回显即可make


+--------------------------------------------------------------------+
| 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.

// make 编译 && 安装

[root@localhost php-8.0.10 ]# make
·····
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorygraphiterator.inc
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
phar.inc

Build complete.
Don't forget to run 'make test'.



[root@localhost php-8.0.10 ]# make install
·····
/usr/local/php-8.0.10/build/shtool install -c ext/phar/phar.phar /usr/local/php8/bin/phar.phar
ln -s -f phar.phar /usr/local/php8/bin/phar
Installing PDO headers:           /usr/local/php8/include/php/ext/pdo/

//配置环境变量

[root@localhost local]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@localhost local]# source /etc/profile.d/php8.sh

//配置php-fpm

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

//取消httpd.conf的注释

[root@localhost fpm]# vim /usr/local/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

//编写index.php测试文件

[root@localhost apache]# cat htdocs/test/index.php

[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/

//配置虚拟主机
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
//在配置文件的最后加入以下内容

    DocumentRoot "/usr/local/apache/htdocs/test"
    ServerName www.xu.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
    
        Options none
        AllowOverride none
        Require all granted
    
  

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
//搜索AddType,添加以下内容
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        #添加此行
    AddType application/x-httpd-php-source .phps        #添加此行
    
[root@localhost ~]# sed -i '/    DirectoryIndex/s/index.html/index.php index.html/g'  /usr/local/apache/conf/httpd.conf 

//启动php httpd
[root@localhost php-fpm.d]# service php-fpm start
[root@localhost apache]# systemctl restart httpd 
[root@localhost php-fpm.d]# 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      128          0.0.0.0:22         0.0.0.0:*    
LISTEN 0      80                 *:3306             *:*    
LISTEN 0      128                *:80               *:*    
LISTEN 0      128             [::]:22            [::]:* 


//测试

LAMP架构(编译)_第3张图片

你可能感兴趣的:(php,perl,mysql)