lamp架构

1.lamp简介

lamp动态网站部署架构是一套由Linux + Nginx + MySQL + PHP组成的动态网站系统解决方案,具有免费、高效、扩展性强且资源消耗低等优良特性。

2. web服务器工作流程

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

  • 静态资源:指的是当客户端访问服务器的资源时,所获得结果与服务器本地存储的源文件内容一致,则称为静态资源
  • 动态资源:指的是当客户端访问服务器的资源时,所获得的结果是服务器本地存储的源文件执行后的结果,其输出的结果与源文件内容不一致,则称之为动态资源。

那么web服务器如何执行程序并将结果返回给客户端呢?这里就会用到fastCGI,在fastCGI之前还有一个叫做CGI,那么,什么又是CGI和fastCGI呢?

2.1.web的工作流程
  • 客户端通过HTTP协议向web服务器发送访问请求
  • 当服务器收到访问请求后检测客户端想要访问的是静态资源还是动态资源
  • 如果访问的是静态资源,则web服务器会从本地文件系统内提取文件返回给客户端
  • 如果访问的是动态资源,则web服务器会通过fastCGI协议访问PHP服务器,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序的时候若需要获得数据库的资源时,由Php服务器通过mysql协议与MySQL/MariaDB(centos7和Redhat7默认)服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
2.2.CGI和fastCGI

CGI(Common Gateway Interface),公共网关接口,它是Web服务器与外部应用程序(CGI程序)之间传递信息的接口标准。通过CGI接口,Web服务器就能够获取客户端提交的信息,并转交给服务器端的CGI程序处理,最后返回结果给客户端。

CGI程序的工作方式:
Web服务器一般只处理静态文件请求(如 jpg、htm、html),如果碰到一个动态脚本请求(如php),web服务器主进程,就fork出一个新的进程来启动CGI程序,也就是说将动态脚本请求交给CGI程序来处理。启动CGI程序需要一个过程,比如,读取配置文件,加载扩展等。CGI程序启动后,就会解析动态脚本,然后将结果返回给Web服务器,最后Web服务器再将结果返回给客户端,刚才fork的进程也会随之关闭。
这样,每次用户请求动态脚本,Web服务器都要重新fork一个新进程,去启动CGI程序,由CGI程序来处理动态脚本,处理完后进程随之关闭。这种工作方式的效率是非常低下的。

FastCGI程序也可以和Web服务器分别部署在不同的主机上,它还可以接受来自其他Web服务器的请求。
FastCGI也是语言无关的。其主要行为是将CGI解释器进程保持在内存中并因此获得高效的性能。众所周知,CGI解释器的反复加载是CGI性能低下的主要原因。
FastCGI是一种进程管理工具,它可以在内存中管理CGI进程。
FastCGI进程管理器需要单独启动。启动FastCGI后,会生成一个FastCGI主进程和多个子进程(子进程其实就是CGI解释器进程)。
当客户端请求Web服务器上的动态脚本时,Web服务器会将动态脚本通过TCP协议交给FastCGI主进程,FastCGI主进程根据情况,安排一个空闲的子进程来解析动态脚本,处理完成后将结果返回给Web服务器,Web服务器再将结果返回给客户端。该客户端请求处理完毕后,FastCGI子进程并不会随之关闭,而是继续等待主进程安排工作任务。

2.3.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.lamp平台搭建

  • lamp平台软件安装次序:

    httpd --> mysql --> php

  • 需要安装的服务:

httpd-2.4
mysql-5.7
php-7.2
php-mysql

注意:php要求httpd使用prefork MPM

3.1.编译安装httpd
//安装开发工具包
root@localhost ~]# yum groups list
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
可用的环境分组:
   最小安装
   基础设施服务器
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成
[root@localhost ~]# yum groups mark install '开发工具'
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Marked install: 开发工具
[root@localhost ~]# yum groups list
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
可用的环境分组:
   最小安装
   基础设施服务器
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
已安装的组:
   开发工具
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成
//创建apache服务的用户和组
[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache
[root@localhost ~]# id apache
uid=997(apache) gid=995(apache) 组=995(apache)
//安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
......
已安装:
  expat-devel.x86_64 0:2.1.0-10.el7_3           openssl-devel.x86_64 1:1.0.2k-8.el7           pcre-devel.x86_64 0:8.32-17.el7          

作为依赖被安装:
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7      krb5-devel.x86_64 0:1.15.1-8.el7          libcom_err-devel.x86_64 0:1.42.9-10.el7     
  libkadm5.x86_64 0:1.15.1-8.el7                libselinux-devel.x86_64 0:2.5-11.el7      libsepol-devel.x86_64 0:2.5-6.el7           
  libverto-devel.x86_64 0:0.2.5-4.el7           zlib-devel.x86_64 0:1.2.7-17.el7         

完毕!
//下载和安装apr以及apr-util
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.bz2 https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2 https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.37.tar.bz2
[root@localhost src]# yum -y install bzip2
[root@localhost src]# ls
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.37.tar.bz2  kernels
[root@localhost src]# tar -xf apr-1.6.5.tar.bz2 
[root@localhost src]# tar -xf apr-util-1.6.1.tar.bz2 
[root@localhost src]# tar -xf httpd-2.4.37.tar.bz2 
[root@localhost src]# ls
apr-1.6.5  apr-1.6.5.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.37  httpd-2.4.37.tar.bz2  kernels
[root@localhost apr-1.6.5]# vim configure
 cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    $RM "$cfgfile"
#  $RM "$cfgfile"    //将此行加上注释,或者删除此行
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make
[root@localhost apr-1.6.5]# make install
[root@localhost apr-1.6.5]# cd ..
[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
[root@localhost apr-util-1.6.1]# make install
//编译安装httpd
[root@localhost apr-util-1.6.1]# cd ..
[root@localhost src]# cd httpd-2.4.37
[root@localhost httpd-2.4.37]# ./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.37]# make
[root@localhost httpd-2.4.37]# make install
//安装后配置
[root@localhost ~]# vim /etc/profile.d/httpd.sh
[root@localhost ~]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s include/ /usr/include/httpd
[root@localhost local]# vim /etc/man.config
[root@localhost local]# cat /etc/man.config
NPATH /usr/local/apache/man
//取消ServerName前面的注释
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#ServerName www.example.com:80
  ServerName www.example.com:80
//启动apache
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                                     :::80                                                  :::*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
3.2.安装mysql
//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g 306 mysql
[root@localhost ~]# id mysql
uid=996(mysql) gid=306(mysql) 组=306(mysql)
//下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
apr-1.6.5          apr-util-1.6.1          debug         httpd-2.4.37.tar.bz2  mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.37  kernels
//解压软件至/usr/local/
[root@localhost src]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.23-linux-glibc2.12-x86_64  sbin  share  src
//修改目录/usr/local/mysql的属主属组
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.23-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.23-linux-glibc2.12-x86_64/"
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 2月  20 15:55 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/
//添加环境变量
[root@localhost ~]# vim /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
//建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll /tmp/data -d
drwxr-xr-x. 2 mysql mysql 6 2月  20 16:01 /opt/data
//初始化数据库
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data
//配置mysql
2019-02-20T08:01:57.365613Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-20T08:02:02.649657Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-02-20T08:02:03.188376Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-02-20T08:02:03.261018Z 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: cec3e17c-34e5-11e9-9b0d-000c295aa226.
2019-02-20T08:02:03.264743Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-02-20T08:02:03.267878Z 1 [Note] A temporary password is generated for root@localhost: GSfIupL4jt?C
//请注意,这个命令的最后会生成一个临时密码,此处密码是GSfIupL4jt?C,一定要记住,登录数据库时会用到

//配置mysql
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost ~]# ldconfig
//生成配置文件
[root@localhost ~]# mv /etc/my.cnf /opt/
[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-resolve
//配置服务启动脚本
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/tmp/data		//在这两行的=后面添加内容,原本=后面没有内容
//启动mysql
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                                     :::80                                                  :::*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
LISTEN     0      80                                      :::3306                                                :::*                  
//修改密码
//使用临时密码登录
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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('zml123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@localhost ~]# mysql -uroot -pzml123!
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.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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
//安装yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *]
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# yum -y install epel-release
[root@localhost yum.repos.d]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//安装依赖包
[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  libpcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72w-mysqlnd
//下载php
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
//编译安装php
[root@localhost src]# tar xf php-7.2.8.tar.xz
[root@localhost src]# cd php-7.2.8
[root@localhost php-7.2.8]# ./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
[root@localhost php-7.2.8]# make
[root@localhost php-7.2.8]# make install
//安装后配置
[root@localhost ~]# vim /etc/profile.d/php7.sh
[root@localhost ~]# cat /etc/profile.d/php7.sh
export PATH=/usr/local/php7/bin:$PATH
[root@localhost ~]# source /etc/profile.d/php7.sh
[root@localhost ~]# echo $PATH
/usr/local/php7/bin:/usr/local/mysql/bin:/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# php -v
PHP 7.2.8 (cli) (built: Feb 20 2019 16:56:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
//配置php-fpm
[root@localhost ~]# cd /usr/src/
[root@localhost src]# cd php-7.2.8
[root@localhost php-7.2.8]# mv /etc/php.ini /opt/
[root@localhost php-7.2.8]# \cp php.ini-production /etc/php.ini
[root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.2.8]# 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@localhost ~]# vim /usr/local/php7/etc/php-fpm.conf
......
;  - the global prefix if it's been set (-p argument)
;  - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50    //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5    //启动时启动5个进程
pm.min_spare_servers = 2    //最小空闲进程数
pm.max_spare_servers = 8    //最大空闲进程数
//启动php-fpm
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
//默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                              127.0.0.1:9000                                                 *:*                  
LISTEN     0      128                                     :::80                                                  :::*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
LISTEN     0      80                                      :::3306                                                :::*                  
3.4.配置apache
3.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
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
......
3.4.2 配置虚拟主机

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

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

以上设置表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。

//创建虚拟主机目录并生成php测试页面
[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]# mkdir zml.com
[root@localhost htdocs]#cd ..
[root@localhost apache]# chown -R apache.apache htdocs/
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# ll
总用量 4
-rw-r--r--. 1 apache apache 45 6月  12 2007 index.html
drwxr-sr-x. 2 apache apache 23 2月  20 17:25 zml.com
[root@localhost htdocs]# cd zml.com/
[root@localhost zml.com]# vim index.php
[root@localhost zml.com]# cat index.php 
<?php
   phpinfo();
?>
//在配置文件的最后加入以下内容
[root@localhost ~]# vim /etc/httpd24/httpd.conf
[root@localhost ~]# tail -12 /etc/httpd24/httpd.conf

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zml.com"
    ServerName www.zml.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zml.com/$1
    <Directory "/usr/local/apache/htdocs/zml.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>  
//搜索AddType,添加以下内容
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        //添加此行
    AddType application/x-httpd-php-source .phps        //添加此行
//重启apache服务
[root@localhost ~]# apachectl stop
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                              127.0.0.1:9000                                                 *:*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
LISTEN     0      80                                      :::3306                                                :::*                  
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                              127.0.0.1:9000                                                 *:*                  
LISTEN     0      128                                     :::80                                                  :::*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
LISTEN     0      80                                      :::3306                                                :::*                  
3.5.验证

1.修改/etc/hosts文件,添加域名与IP的映射
2.在浏览器上使用域名访问,若看到以下界面则表示lamp架构搭建成功,否则请检查你的操作
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值