lamp架构

#lamp架构

文章目录


##lamp简介
所谓lamp,其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。

##wep服务器工作流程
web服务器的资源分为两种,静态资源和动态资源

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

###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上下文切换而导致耗时

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

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

##lamp平台建构
环境说明
|系统平台|IP|需要安装的服务|
|-|
|centos7 redhat7|172.16.12.128|httpd-2.4 mysql-5.7 php php-mysql|

lamp平台软件安装次序:
httpd --> mysql —> php
注意:php要去httpd使用prefork MPM

###安装httpd
yum源配置

下载安装包

[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   9746      0 --:--:-- --:--:-- --:--:--  9708

[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

下载wget

[root@localhost ~]# yum install -y wget vim

下载epel

[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Last metadata expiration check: 0:05:23 ago on Tue 02 Aug 2022 04:35:22 PM CST.
epel-release-latest-8.noarch.rpm                 49 kB/s |  24 kB     00:00    
Dependencies resolved.
================================================================================
 Package             Architecture  Version            Repository           Size
================================================================================
Installing:
 epel-release        noarch        8-16.el8           @commandline         24 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : epel-release-8-16.el8.noarch                           1/1 
  Running scriptlet: epel-release-8-16.el8.noarch                           1/1 
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.

  Verifying        : epel-release-8-16.el8.noarch                           1/1 
Installed products updated.

Installed:
  epel-release-8-16.el8.noarch                                                  

Complete!

查看下载内容

[root@localhost yum.repos.d]# ls
CentOS-Base.repo   epel.repo                  epel-testing.repo
epel-modular.repo  epel-testing-modular.repo

安装开发工具包

[root@localhost yum.repos.d]# yum groups mark install 'Development Tools'
Extra Packages for Enterprise Linux Modular 8 -  96 kB/s | 1.0 MB     00:10    
Extra Packages for Enterprise Linux 8 - x86_64  692 kB/s |  13 MB     00:18    
Last metadata expiration check: 0:00:02 ago on Tue 02 Aug 2022 04:49:09 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]
Dependencies resolved.
================================================================================
 Package           Architecture     Version             Repository         Size
================================================================================
Installing Groups:
 Development Tools                                                             

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

Is this ok [y/N]: y
Complete!

创建apache服务的用户和组

[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# id apache 
uid=974(apache) gid=973(apache) groups=973(apache)

安装依赖包

[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++

[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.6.5.tar.bz2
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.bz2
[root@localhost src]# dnf install -y bzip2
[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
[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]# ls
apr-1.6.5          apr-util-1.6.1          debug                 kernels
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.54.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]# dnf -y install make
[root@localhost apr-1.6.5]# make && make install

[root@localhost apr-1.6.5]# 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-1.6.5]# make && make install


编译安装httpd

[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.bz2
[root@localhost src]# ls
apr-1.6.5          apr-util-1.6.1          debug         httpd-2.4.54.tar.bz2
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.54  kernels
[root@localhost src]# tar xf httpd-2.4.54.tar.bz2 
[root@localhost src]# ls
apr-1.6.5          apr-util-1.6.1          debug         httpd-2.4.54.tar.bz2
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.54  kernels
[root@localhost src]# cd httpd-2.4.54
[root@localhost 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 ~]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# cd 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 apachectl
/usr/local/apache/bin/apachectl
[root@localhost apache]# ln -s /usr/local/apache/include/ /usr/include/httpd
[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

取消ServerName前面的注释

[root@localhost apache]# vim /etc/httpd24/httpd.conf 
ServerName www.example.com:80
[root@localhost apache]# httpd -t
Syntax OK

配置用systemctl启动apache

[root@localhost ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim httpd.service 
[root@localhost system]# cat httpd.service 
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
//重新加载文件
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# cd 
[root@localhost ~]# systemctl status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost ~]# systemctl start httpd
[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          128                        *:80                      *:*                  
LISTEN     0          128                     [::]:22                   [::]:*    

//设置开启自启              
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

关闭防火墙

[root@localhost ~]# systemctl start firewalld
[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 ~]# vim /etc/selinux/config 
SELINUX=disabled
[root@localhost ~]# setenforce 0

###安装mysql

安装依赖包

[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake

创建用户和组

[root@localhost ~]# useradd -r -M -s /sbin/nologin  mysql
[root@localhost ~]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)

下载二进制格式的mysql软件包

[root@localhost ~]# cd /usr/src/
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# ls
apr-1.6.5          apr-util-1.6.1.tar.bz2  httpd-2.4.54.tar.bz2
apr-1.6.5.tar.bz2  debug                   kernels
apr-util-1.6.1     httpd-2.4.54            mysql-5.7.37-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 src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ll
total 0
drwxr-xr-x. 13 root root 152 Aug  2 16:44 apache
drwxr-xr-x.  6 root root  58 Aug  2 16:34 apr
drwxr-xr-x.  5 root root  43 Aug  2 16:36 apr-util
drwxr-xr-x.  2 root root   6 May 19  2020 bin
drwxr-xr-x.  2 root root   6 May 19  2020 etc
drwxr-xr-x.  2 root root   6 May 19  2020 games
drwxr-xr-x.  2 root root   6 May 19  2020 include
drwxr-xr-x.  2 root root   6 May 19  2020 lib
drwxr-xr-x.  3 root root  17 Jul 13 20:28 lib64
drwxr-xr-x.  2 root root   6 May 19  2020 libexec
lrwxrwxrwx.  1 root root  36 Aug  2 19:10 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 root root 129 Aug  2 19:09 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root root   6 May 19  2020 sbin
drwxr-xr-x.  5 root root  49 Jul 13 20:28 share
drwxr-xr-x.  2 root root   6 May 19  2020 src
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll
total 0
drwxr-xr-x. 13 root  root  152 Aug  2 16:44 apache
drwxr-xr-x.  6 root  root   58 Aug  2 16:34 apr
drwxr-xr-x.  5 root  root   43 Aug  2 16:36 apr-util
drwxr-xr-x.  2 root  root    6 May 19  2020 bin
drwxr-xr-x.  2 root  root    6 May 19  2020 etc
drwxr-xr-x.  2 root  root    6 May 19  2020 games
drwxr-xr-x.  2 root  root    6 May 19  2020 include
drwxr-xr-x.  2 root  root    6 May 19  2020 lib
drwxr-xr-x.  3 root  root   17 Jul 13 20:28 lib64
drwxr-xr-x.  2 root  root    6 May 19  2020 libexec
lrwxrwxrwx.  1 mysql mysql  36 Aug  2 19:10 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x.  9 mysql mysql 129 Aug  2 19:09 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root  root    6 May 19  2020 sbin
drwxr-xr-x.  5 root  root   49 Jul 13 20:28 share
drwxr-xr-x.  2 root  root    6 May 19  2020 src

配置环境变量

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

[root@localhost bin]# cd ..
[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@localhost mysql]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig 
[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 19:27 data

配置mysql

[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

配置用systemctl启动mysql

[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/mysqld
datadir=/opt/data/

[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=mysqld server daemon
Documentation=man:sshd(8) man:sshd_config(5)
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
[root@localhost ~]# systemctl daemon-reload

启动mysql

[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:sshd(8)
           man:sshd_config(5)
[root@localhost ~]# systemctl start mysqld
[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          80                         *:3306                    *:*                  
LISTEN     0          128                        *:80                      *:*                  
LISTEN     0          128                     [::]:22                   [::]:*     

//设置开机自启             
[root@localhost ~]# 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 ~]# dnf install -y ncurses-compat-libs
[root@localhost ~]# cat passwd 
s&T*_,;6D=ke
[root@localhost ~]# mysql -uroot -ps&T*_,;6D=ke
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 2
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> 

设置新密码

mysql>  set password = password('1123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

###安装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 ~]# wget https://www.php.net/distributions/php-7.4.30.tar.xz

编译安装php

[root@localhost src]# ls
apr-1.6.5               debug                 mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.bz2       httpd-2.4.54          php-7.4.30.tar.xz
apr-util-1.6.1          httpd-2.4.54.tar.bz2
apr-util-1.6.1.tar.bz2  kernels
[root@localhost src]# tar xf php-7.4.30.tar.xz 
[root@localhost src]# cd php-7.4.30
下载oniguruma-devel
[root@localhost php-7.4.30]# yum install -y http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

[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 (sqlite3 > 3.7.4) were not met:

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

安装后配置

[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=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php7]# ln  -s /usr/local/php7/include /usr/include/php
[root@localhost php7]# echo '/var/local/php7/lib' > /etc/ld.so.conf.d/php.conf

配置php-fpm

[root@localhost php7]# cd /usr/src/php-7.4.30
[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/rc.d/init.d/php-fpm
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.30]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

配置用systemctl启动mysql

[root@localhost php-7.4.30]# cd /usr/lib/systemd/system/
[root@localhost system]# cp mysqld.service php-fpm.service
[root@localhost system]# vim php-fpm.service
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl restart php-fpm.service
[root@localhost system]# cat 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 start php-fpm
[root@localhost system]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
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                   [::]:*                  

//设置开启自启
[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.

###配置apache
####启用代理模块

[root@localhost ~]# vim /etc/httpd24/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
[root@localhost ~]# httpd -t
Syntax OK

####配置虚拟主机


[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir phpcs
[root@localhost htdocs]# vim phpcs/index.php
[root@localhost htdocs]# cat phpcs/index.php
<?php
   phpinfo();
?>
[root@localhost htdocs]# ls
phpcs
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/
[root@localhost htdocs]# vim /etc/httpd24/httpd.conf
Include /etc/httpd24/extra/httpd-vhosts.conf //去掉注释

//搜索AddType,添加以下内容
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    //增加以下两行
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps 

<IfModule dir_module>
    DirectoryIndex  index.php index.html   //修改此行
</IfModule>

[root@localhost htdocs]# httpd -t
Syntax OK
[root@localhost htdocs]# systemctl restart httpd

[root@localhost htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf 
[root@localhost htdocs]# httpd -t
Syntax OK
[root@localhost htdocs]# cat /etc/httpd24/extra/httpd-vhosts.conf 
# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/phpcs"
    ServerName phpcs.example.com
    ErrorLog "logs/phpcs.example.com-error_log"
    CustomLog "logs/phpcs.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/phpcs/$1
    <Directory "/usr/local/apache/htdocs/phpcs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

###验证
关闭防火墙

[root@localhost system]# systemctl stop firewalld
[root@localhost system]# systemctl disable firewalld
[root@localhost system]# vim /etc/selinux/config 
SELINUX=disabled 
[root@localhost system]# setenforce 0

![在这里插入图片描述](https://img-blog.csdnimg.cn/2da8c0d945924c3fa24a8a5a803fc1e0.png#pic_center)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值