LAMP 架构介绍及环境搭建

1、LAMP 架构介绍及环境搭建

1.LAMP分别代表什么?

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

LAMP 架构介绍及环境搭建

2.web服务器工作流程介绍

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

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

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

LAMP 架构介绍及环境搭建

如图所示

  • ①显示的是 httpd服务器(即apache)和php服务器通过FastCGI协议进行通信,且php作为独立的服务进程运行
  • ②显示的是 php程序和mysql数据库间通过mysql协议进行通信。php与mysql本没有什么联系,但是由Php语言写成的程序可以与mysql进行数据交互。同理perl和python写的程序也可以与mysql数据库进行交互

2.1cgi与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平台构建

环境说明:

系统平台 IP 需要安装的服务 centos8 192.168.111.138 httpd-2.4 mysql-5.7 php php-mysql

lamp平台软件安装次序:

    httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

3.1 安装httpd

##配置centos源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

##配置epel源
[root@100 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@100 ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@100 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

##安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools'

##创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

##安装依赖包
[root@localhost ~]# yum -y install bzip2 make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel

##下载源码包
[root@localhost ~]# cd /usr/src/
[root@localhost src]#wget https://downloads.apache.org/apr/apr-1.6.5.tar.bz2
[root@localhost src]#wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.bz2
[root@localhost src]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.bz2
[root@localhost src]#ls
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54.tar.bz2  kernels

##安装apr
[root@localhost src]#tar -xf apr-1.6.5.tar.bz2
[root@localhost src]#cd apr-1.6.5/
[root@localhost apr-1.6.5]#vim configure
    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行
[root@localhost apr-1.6.5]#./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install

##安装apr-util
[root@localhost src]#tar -xf apr-util-1.6.1.tar.bz2
[root@localhost src]#cd 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@study src]#tar -xf httpd-2.4.54.tar.bz2
[root@study src]#cd httpd-2.4.54/
[root@study httpd-2.4.54]#./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.54]# make && make install

##安装后配置
[root@localhost httpd-2.4.54]# echo "export PATH=$PATH:/usr/local/apache/bin" > /etc/profile.d/httpd.sh
[root@localhost httpd-2.4.54]# source /etc/profile.d/httpd.sh
[root@localhost httpd-2.4.54]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost httpd-2.4.54]# vim /etc/man_db.conf
.....

MANDATORY_MANPATH                       /usr/local/apache/man
.....

##取消ServerName前面的注释
[root@localhost httpd-2.4.54]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf

##systemctl管理httpd服务
[root@localhost httpd-2.4.54]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim httpd.service
[Unit]
Description=apache 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 system]# systemctl start httpd
[root@localhost system]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

[root@localhost system]# ss -anlt | grep 80
LISTEN 0      128                *:80              *:*

访问

安装完成之后,访问Apache服务,出现默认首页,说明安装成功。

LAMP 架构介绍及环境搭建

3.2 安装mysql

##安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake

##创建mysql用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

##下载二进制格式的mysql软件包
[root@localhost ~]#wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

##解压软件至/usr/local/
[root@localhost src]# tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

##设置软链接并修改属主和属组
[root@localhost usr]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll -d mysql*
lrwxrwxrwx. 1 mysql mysql  36 Aug  2 21:08 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Aug  2 21:05 mysql-5.7.37-linux-glibc2.12-x86_64

##添加环境变量
[root@localhost mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost mysql]# source /etc/profile.d/mysql.sh
[root@localhost mysql]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin
#头文件—include
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql

#库文件—lib
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/
[root@localhost mysql]# ldconfig

#man文件路径
[root@localhost mysql]# vim /etc/man_db.conf
......

MANDATORY_MANPATH                       /usr/local/mysql/man
......

##建立数据存放目录
[root@localhost mysql]# mkdir /opt/data
[root@localhost mysql]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug  2 21:16 data

##初始化数据库
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2022-08-02T13:17:30.732811Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2022-08-02T13:17:30.907500Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T13:17:30.932432Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2022-08-02T13:17:30.997587Z 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: 76a6881f-1265-11ed-8422-000c29e16842.

2022-08-02T13:17:30.998294Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2022-08-02T13:17:31.495168Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.

2022-08-02T13:17:31.495186Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.

2022-08-02T13:17:31.495869Z 0 [Warning] CA certificate ca.pem is self signed.

2022-08-02T13:17:31.601283Z 1 [Note] A temporary password is generated for root@localhost: o!Ki52Mu_hhh
//请注意,这个命令的最后会生成一个临时密码,此处密码是o!Ki52Mu_hhh
//再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到
[root@localhost mysql]# echo 'o!Ki52Mu_hhh' > passwd

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

##生成配置文件
[root@localhost mysql]# 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@localhost mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data
[root@localhost mysql]# cd /usr/lib/systemd/system
[root@localhost system]# cp httpd.service mysqld.service
[root@localhost system]# vim mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target

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

[Install]
WantedBy=multi-user.target

##启动mysql
[root@localhost system]# systemctl start mysqld
[root@localhost system]# systemctl enable mysqld
Synchronizing state of mysqld.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.

Executing: /usr/lib/systemd/systemd-sysv-install enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

[root@localhost system]# ss -anlt | grep 3306
LISTEN 0      80                 *:3306            *:*

##修改密码
[root@localhost mysql]# mysql -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//解决办法
[root@localhost mysql]# yum whatprovides libncurses.so.5
Last metadata expiration check: 1:12:26 ago on Tue 02 Aug 2022 08:23:55 PM CST.

Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : base
Matched from:
Provide    : libncurses.so.5

[root@localhost mysql]# yum -y install ncurses-compat-libs
//进入数据库设置新密码
[root@localhost ~]# mysql -uroot -p'o!Ki52Mu_hhh'
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 3
Server version: 5.7.37

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('Passwd123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
//开启远程访问权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH  PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

3.3 安装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 php-mysqlnd

##下载php并解压
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
[root@localhost src]# tar -xf php-7.4.30.tar.xz

##编译安装php
[root@study src]#cd php-7.4.30/
[root@localhost 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 \
--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: error: Package requirements (sqlite3 > 3.7.4) were not met:
Package ‘sqlite3’, required by ‘virtual:world’, not found

[root@localhost php-7.4.30]# yum -y install sqlite-devel

configure: error: Package requirements (oniguruma) were not met:
Package ‘oniguruma’, required by ‘virtual:world’, not found

[root@localhost php-7.4.30]# 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

configure: error: Package requirements (libcurl >= 7.15.5) were not met:
Package ‘libcurl’, required by ‘virtual:world’, not found

[root@localhost php-7.4.30]# yum install -y libcurl-devel.x86_64

error: Please reinstall readline – I cannot find readline.h

[root@localhost php-7.4.30]# yum -y install readline-devel

当出现如图所示情况

LAMP 架构介绍及环境搭建
//因版本过新导致可选编译项名称不一致
[root@localhost php-7.4.30]# ./configure --help | grep gd
  --with-gdbm[=DIR]       DBA: GDBM support
  --enable-gd             Include GD support
  --with-external-gd      Use external 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 (only
                          for bundled libgd)
[root@localhost php-7.4.30]# ./configure --help | grep jpeg
  --with-jpeg             GD: Enable JPEG support (only for bundled libgd)
[root@localhost php-7.4.30]# ./configure --help | grep png
[root@localhost php-7.4.30]# ./configure --help | grep freetype
  --with-freetype         GD: Enable FreeType 2 support (only for bundled
[root@localhost php-7.4.30]# ./configure --help | grep zip
  --with-zip              Include Zip read/write support

##找到相应的可选编译项后,继续编译
[root@localhost 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
//报错
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-7.4.30]# yum -y install libzip-devel

如图表示PHP模块启用成功

LAMP 架构介绍及环境搭建

继续编译安装

[root@localhost php-7.4.30]# make && make install

安装后配置

[root@localhost php-7.4.30]# cd /usr/local/php7/
[root@localhost php7]# ls
bin  etc  include  lib  php  sbin  var
[root@localhost php7]# echo 'export PATH=$PATH:/usr/local/php7/bin' > /etc/profile.d/php7.sh
[root@localhost php7]# source /etc/profile.d/php7.sh
[root@localhost php7]# ln -s /usr/local/php7/include/ /usr/include/php7
[root@localhost php7]# echo '/usr/local/php7/lib/' > /etc/ld.so.conf.d/php7.conf
[root@localhost php7]# ldconfig

##配置php-fpm
[root@localhost php7]# cd /usr/src/php-7.4.30
[root@localhost php-7.4.30]# cp php.ini-production /etc/php.ini
[root@localhost php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.30]# chmod +x /etc/init.d/php-fpm
[root@study /usr/src/php-7.4.30]#cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@study /usr/src/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-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
//配置fpm的相关选项为你所需要的值:
[root@study /usr/src/php-7.4.30]#vim /usr/local/php7/etc/php-fpm.conf
.....

.....

pm.max_children = 50    ;最多同时提供50个进程提供50个并发服务
pm.start_servers = 5    ;启动时启动5个进程
pm.min_spare_servers = 2    ;最小空闲进程数
pm.max_spare_servers = 8    ;最大空闲进程数

##启动 php
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp httpd.service php-fpm.service
[root@localhost system]# vim php-fpm.service
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.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 system]# systemctl daemon-reload
[root@localhost system]# systemctl start php-fpm
[root@localhost system]# systemctl enable php-fpm
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.

Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

[root@localhost system]# ss -anlt | grep 9000
LISTEN 0      128        127.0.0.1:9000      0.0.0.0:*

4.配置 apache

4.1启用代理模块

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

  • LoadModule proxy_module modules/mod_proxy.so
  • LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
##启用httpd的相关模块
[root@localhost ~]# vim /etc/httpd24/httpd.conf
//取消以下两行内容的注释
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

4.2 配置虚拟主机

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

ProxyRequests Off       //关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1

例如:

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/$1

注意:

这里写的/var/www/html/是yum源安装方式生成的网页存放目录,这里必须改成你编译安装指定的网页存放路径,禁止直接复制我这里的路径
这里的idfsoft.com是域名,你必须改成你所使用的域名,禁止直接复制此处的域名
这里的$1表示匹配所有以.php结尾的http请求

##创建虚拟主机目录并生成php测试页面
[root@localhost ~]# mkdir /usr/local/apache/htdocs/runtime
[root@localhost ~]# vim /usr/local/apache/htdocs/runtime/index.php

[root@localhost ~]#chown -R apache.apache /usr/local/apache/htdocs/runtime/
[root@localhost ~]#vim /etc/httpd24/httpd.conf
Virtual hosts
Include /etc/httpd24/extra/httpd-vhosts.conf  #取消注释
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf

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

        Options none
        AllowOverride none
        Require all granted

[root@localhost ~]# vim /etc/httpd24/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        #添加此行

//搜索dir_module,添加index.php

    DirectoryIndex index.php index.html

[root@localhost ~]# httpd -t
Syntax OK
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -anlt
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         128                   [::]:22                   [::]:*
LISTEN    0         80                       *:3306                    *:*
LISTEN    0         128                      *:80                      *:*

5.验证

修改/etc/hosts文件,添加域名与 IP 的映射。
将 Windows 系统下的C:\Windows\System32\drivers\etc\hosts文件移至桌面,使用记事本打开,添加192.168.111.138 runtime.example.com,再移回。

在浏览器上使用域名访问,若看到以下界面则表示 lamp 架构搭建成功

LAMP 架构介绍及环境搭建

Original: https://www.cnblogs.com/Alone-8712/p/16663262.html
Author: Alone-林
Title: LAMP 架构介绍及环境搭建

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

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

(0)

大家都在看

  • 从前端走向后端

    每次过年回老家聚会,遇到不熟悉的亲戚朋友,经常被问到职业是什么。一开始,我总是很认真的回答这个问题,结果常常引出一番尴尬的问答。 “你&…

    Linux 2023年6月6日
    093
  • 【PHP】浅谈php实现订阅发布模式及redis的实现

    订阅发布应用场景: 1、广告推送 2、游戏公告 3、广播–短信、邮件 4、跨应用推送–使用同一个redis实例,net发布publish,php常驻内存订阅subscribe处…

    Linux 2023年5月28日
    069
  • windows系统命令行cmd查看显卡驱动版本号CUDA

    好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/16656547.html 关于…

    Linux 2023年6月14日
    0106
  • 001 研发同学必学哪些 Linux 命令?

    身为研发同学,Linux 是绕不过去的一个小山包,不是说要掌握的十分精通,在程序员界里做个极客,也不是说要抢了 Devops 同学的饭碗,但至少要做到摆脱对 Linux 命令认知的…

    Linux 2023年5月27日
    082
  • 保姆教程系列三、Nacos Config–服务配置

    前言: 请各大网友尊重本人原创知识分享,谨记本人博客:南国以南i 上篇我们介绍到 保姆教程系列二、Nacos实现注册中心 配置中心原理 一、 服务配置中心介绍 首先我们来看一下,微…

    Linux 2023年6月14日
    092
  • Linux 下 xargs 命令

    xargs 常常被大家忽略的一个命令,对它的一些用法很多人可能不熟悉,其实它是一个功能强大的命令,特别是在结合管道进行批量处理方面 语法 xargs 语法格式如下 xargs [O…

    Linux 2023年6月13日
    0107
  • c++模板类的使用,编译的问题

    前两天在写代码时,把模板类的声明和分开放在两个文件中了,类似于下面这样: stack.hpp: #ifndef _STACK_HPP #define _STACK_HPP temp…

    Linux 2023年6月14日
    093
  • 【原创】Linux虚拟化KVM-Qemu分析(十一)之virtqueue

    背景 Read the fucking source code! –By 鲁迅 A picture is worth a thousand words. –…

    Linux 2023年6月8日
    081
  • 07_Linux基础-计划任务-备份脚本-变量定义和使用

    07_Linux基础-计划任务-备份脚本-变量定义和使用 一. 计划任务 主要内容:周期性的计划任务crontab/var/spool/cron/ 统一存放计划任务的目录/var/…

    Linux 2023年6月6日
    080
  • [20220104]in list 几种写法性能测试.txt

    [20220104]in list 几种写法性能测试.txt –//以前写过几种in list的写法,从来没有测试过这几种方法的性能测试看看. 1.环境:SCOTT@b…

    Linux 2023年6月13日
    055
  • DNS Rebinding漏洞原理

    DNS Rebinding 广泛用于 绕过同源策略、SSRF过滤等。 背景 为什么需要SSRF过滤器?• 由于一些业务的需要,他们就是需要让用户输入URL,然后进行跳转,如果过滤得…

    Linux 2023年6月6日
    0112
  • 玩转redis-简单消息队列

    使用 go语言基于 redis写了一个简单的消息队列源码地址使用demo redis的 list 非常的灵活,可以从左边或者右边添加元素,当然也以从任意一头读取数据 添加数据和获取…

    Linux 2023年5月28日
    093
  • Cookie

    题目如下 打开靶机 根据提示,需要admin登录才能得到flag,题目介绍为Cookie欺骗,认证,伪造 打开burpsuite进行抓包,HTTP数据包是可以修改cookie值的 …

    Linux 2023年6月7日
    073
  • 缓冲区溢出二:从缓冲区溢出到获取反弹shell实例

    一、说明 之前写过一篇”缓冲区溢出一:函数调用过程中的堆栈变化及缓冲区溢出利用原理“,道理讲得还可以,但现在看还是需要一个示例来讲解从攻击角度如何实现返回地…

    Linux 2023年5月28日
    0106
  • Nuget私服老是弹输入用户名密码框

    先把vs中私服删除,然后,控制面板\用户帐户\凭据管理器,删除私服 最后输入命令: NuGet.exe Sources Update -Name <feedname> …

    Linux 2023年6月13日
    0101
  • 每天一个 HTTP 状态码 200

    200 OK 表示请求成功,一切安好… 200 OK 话不多说,这个状态码应该是最最最常用的了,无人不知,无人不晓;就是表示请求成功的意思, 你若安好,便是晴天。 摘自…

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