lnmp部署

编译安装httpd

编译安装apache需要三个源码包
安装顺序为: apr apr-util httpd
准备工作

[root@localhost ~]# yum groups mark install "Development Tools"  //安装开发工具包
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache  //创建一个系统用户 不生成家目录 拒绝登录/sbin/nologin 
[root@localhost ~]# id apache 
uid=975(apache) gid=973(apache)=973(apache)
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool    //安装依赖包
[root@localhost ~]# yum - y install make  //编译需要make命令
//依赖包要提前装进去
//apr的依赖包要在httpd包之前装上去,编译安装的时候会引用进去,要不然就会报错。报错就只能重新装apache了

下载源码包并解压
源码包地址:https://downloads.apache.org/

//wget命令下载
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz

//解压
[root@localhost ~]# tar -xf apr-1.7.0.tar.gz  
[root@localhost ~]# tar -xf apr-util-1.6.5.tar.gz 
[root@localhost ~]# tar -xf httpd-2.4.53.tar.gz 

编译安装apr-1.7.0

[root@localhost apr-1.7.0]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure

    $RM "$cfgfile"
    //注释或者删除这个
[root@localhost apr-1.7.0]#   ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install

编译安装apr-util-1.6.1

[root@localhost apr-util-1.6.1]# cd apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr   //apr-util是apr的子包 所以需要指定指定主包的位置
[root@localhost apr-util-1.6.1]# make make && install


#子包指定主包
–with-apr=/usr/local/apr

编译安装httpd源码包

[root@localhost ~]# cd httpd-2.4.53/
[root@localhost httpd-2.4.53]#  ./configure --prefix=/usr/local/apache \
--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 ~]# ls /usr/local/   //此目录就是安装三个源码包的位置
apache  apr-util  etc    include  lib64    sbin   src
apr     bin       games  lib      libexec  share
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls   //环境变量的目录
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules

//创建环境变量后httpd和apachectl命令就可以使用了
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh 
[root@localhost ~]# source /etc/profile.d/apache.sh 
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
[root@localhost ~]# which apachectl 
/usr/local/apache/bin/apachectl

//   /usr/local/apache/ 目录下常用目录解释
bin 命令
conf 配置文件
htdocs 网站
logs 日志
include 头文件
man 帮助文档

配置映射关系

[root@localhost ~]# ls /usr/local/apache/   //有头文件include所以需要做链接
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache

配置man文档

[root@localhost ~]# vim /etc/man_db.conf  //添加下面一条
MANDATORY_MANPATH                       /usr/local/share/apache 

配置防火墙 Selinux httpd

[root@localhost ~]#  systemctl disable --now firewalld.service   //关闭防火墙
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0  //关闭selinux  当前生效
[root@localhost ~]# getenforce 
Permissive
[root@localhost ~]# vim /etc/selinux/config   //永久关闭
SELINUX=disabled  //第一个修改为disabled

#提前关闭告警信息
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# cd conf/   //进到配置文件目录 
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@localhost conf]# vim httpd.conf   //将下面一行的注释取消掉
ServerName www.example.com:80


//开启80端口号
[root@localhost ~]# ss -antl   //查看端口号80是否开启
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*       
[root@localhost ~]# apachectl start  //开启80端口号
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message  //警告信息可以无视

[root@localhost ~]# ss -antl  //再次查看80端口已经开启了
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*   

设置开机自启

[root@localhost ~]# cd /usr/lib/systemd/system   
[root@localhost system]# ls sshd.service 
sshd.service
[root@localhost system]# cp sshd.service httpd.service  //复制一份这个文件改名为httpd.service
[root@localhost system]# vim httpd.service   //编辑这个文件
[root@localhost system]# cat httpd.service 
[Unit]
Description=httpd server daemon   //修改为httpd
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start   //更改为apachectl的路径   开启
ExecStop=/usr/local/apache/bin/apachectl stop   //关闭
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload   //重启让其生效


2进制安装MySQL

[root@localhost src]# useradd -r -M -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=975(myaql) gid=973(myaql)=973(myaql)
[root@localhost src]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[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]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share
[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
//修改目录账户属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll -d mysql/
drwxr-xr-x. 9 mysql mysql 129 628 15:41 mysql/
//添加环境变量,叫他在那个目录找MySQL
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
//读取
[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql

有特定的目录的时候,要修改
include(头文件)
man(帮助文档)
lib(库)
bin(主程序)

//设置软链接,里面有多个文件,以后好直接删除目录

[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
//告诉他头文件库在那个地方
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[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
//告诉他man文档在那个地方
[root@localhost mysql]# vim /etc/man_db.conf 
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
//加上这一行
MANDATORY_MANPATH                       /usr/local/mysql/man
#---------------------------------------------------------
# set up PATH to MANPATH mapping
# ie. what man tree holds man pages for what binary directory.
//建立数据存放目录
在企业,设置数据存放目录要放在存储空间大的目录
[root@localhost ~]# mkdir -p /opt/data
[root@localhost  ]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 628 18:39 /opt/data/
//mysqld 系统知道mysql在哪就不用加路径
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T10:40:51.279183Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T10:40:52.695768Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T10:40:52.909685Z 1 [Note] A temporary password is generated for root@localhost: jysro6OtPi)o
[root@localhost ~]#  echo "jysro6OtPi" > pass
[root@localhost ~]# 
//生成配置文件
[root@localhost】 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
#  sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# file mysql.server 
mysql.server: POSIX shell script, ASCII text executable
[root@localhost support-files]# ll
总用量 24
-rw-r--r--. 1 mysql mysql   773 11月 30 2021 magic
-rwxr-xr-x. 1 mysql mysql  1061 1130 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 1130 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 1130 2021 mysql.server
[root@localhost support-files]# cp mysql.server mysqld
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 11月 30 2021 magic
-rwxr-xr-x. 1 root  root  10576 628 18:57 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 1130 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 1130 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 1130 2021 mysql.server
[root@localhost support-files]# chown -R mysql.mysql mysqld
[root@localhost support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql   773 11月 30 2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 628 18:57 mysqld
-rwxr-xr-x. 1 mysql mysql  1061 1130 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 1130 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 1130 2021 mysql.server
[root@localhost support-files]# vim mysqld

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
//改这个地方
basedir=/usr/local/mysql
datadir=/opt/data

[root@localhost ~]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/localhost.err'.
 SUCCESS! 
[root@localhost ~]# ss -antl
State    Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   
LISTEN   0         128                0.0.0.0:111             0.0.0.0:*      
LISTEN   0         32           192.168.122.1:53              0.0.0.0:*      
LISTEN   0         128                0.0.0.0:22              0.0.0.0:*      
LISTEN   0         5                127.0.0.1:631             0.0.0.0:*      
LISTEN   0         80                       *:3306                  *:*      
[root@localhost ~]# ps -ef|grep mysqld
root      411797       1  0 19:01 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/localhost.pid
//报错缺少东西
[root@localhost ~]# mysql -uroot -p'jysro6OtPi'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//查找东西来源那个包
[root@localhost ~]# dnf provides libncurses.so.5
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:40:31 前,执行于 20220628日 星期二 182534秒。
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
仓库        :base
匹配来源:
提供    : libncurses.so.5
//安装包
[root@localhost ~]# dnf -y install ncurses-compat-libs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:42:51 前,执行于 20220628日 星期二 182534秒。

[root@localhost ~]# cat pass
x7GkcGDZ0h(d
[root@localhost ~]# mysql -uroot -p'x7GkcGDZ0h(d'
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> set password = password('runtime123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p'runtime123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
//设置开机自启
//关闭selinux
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# ll -Z /usr/lib/systemd/system/{sshd.service,mysqld.service}
//admin_home报文 selinux无法识别,所以会报错,所有要关闭selinux
-rw-r--r--. 1 root root unconfined_u:object_r:admin_home_t:s0 283 6月  28 20:27 /usr/lib/systemd/system/mysqld.service
-rw-r--r--. 1 root root system_u:object_r:sshd_unit_file_t:s0 456 1月   9 2020 /usr/lib/systemd/system/sshd.service


[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HDP $MATNPID

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor >
   Active: inactive (dead)
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor >
   Active: active (running) since Tue 2022-06-28 20:49:53 CST; 1s ago
  Process: 512182 ExecStart=/usr/local/mysql/support-files/mysqld start (cod>
[root@localhost ~]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

设置免密码隐藏登录

//必须要在家目录下创建
[root@localhost ~]# vim .my.cnf
[root@localhost ~]# cat .my.cnf 
[client]
user = root
password = runtime123
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.37 MySQL Community Server (GPL)

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> quit
Bye

编译安装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 sqlite-devel libzip-devel

[root@localhost ~]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz     //下载此包 后续编译php需要
[root@localhost ~]# tar -zxf oniguruma-6.9.4.tar.gz  //解压
[root@localhost ~]# cd oniguruma-6.9.4 
[root@localhost ~]# ./autogen.sh && ./configure --prefix=/usr  //设置存放位置  
[root@localhost ~]# make && make install  //make编译
//d太慢了,直接网页里下载放进去
[root@localhost ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz 

[root@localhost ~]# tar xf php-7.4.29.tar.xz 
[root@localhost ~]# cd php-7.4.29/
./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

[root@localhost ~]# make
[root@localhost ~]# make install   //make编译
[root@localhost ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh  //使php命令可以使用
[root@localhost ~]# source /etc/profile.d/php7.sh    //读取 让其生效
[root@localhost ~]# which php
/usr/local/php7/bin/php
[root@localhost ~]# cd php-7.4.29/
[root@localhost php-7.4.29]# cp php.ini-production /etc/php.ini  //将生产环境文件 复制到etc下 
[root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# chmod +x /etc/rc.d/init.d/php-fpm  //此文件需要执行权限所以复制过去要看是否有执行(x)权限
[root@localhost php-7.4.29# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf   //将php-fpm.conf.default 复制一份名为php-fpm.conf
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf    //将www.conf.default 复制一份名为www.conf
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl  //php-fpm 的默认端口为9000
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:111               0.0.0.0:*   
[root@localhost ~]# ps -ef |grep php  //查看php的进程
root      681716       1  0 19:57 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    681717  681716  0 19:57 ?        00:00:00 php-fpm: pool www
nobody    681718  681716  0 19:57 ?        00:00:00 php-fpm: pool www
root      689388  362392  0 19:59 pts/1    00:00:00 grep --color=auto php
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl  //php-fpm 的默认端口为9000
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:111               0.0.0.0:*   
[root@localhost ~]# ps -ef |grep php  //查看php的进程
root      681716       1  0 19:57 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    681717  681716  0 19:57 ?        00:00:00 php-fpm: pool www
nobody    681718  681716  0 19:57 ?        00:00:00 php-fpm: pool www
root      689388  362392  0 19:59 pts/1    00:00:00 grep --color=auto php

配置apache
创建测试文件

[root@localhost ~]# cd /usr/local/apache/htdocs/   //进入网页目录
[root@localhost htdocs]# mkdir test.com   //创建存放网页的目录
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/   //设置apache下的文件目录属组属主都为apache
[root@localhost htdocs]# cd test.com/
[root@localhost test.com]# vim index.php   //创建一个index.php的测试文件
[root@localhost test.com]# cat index.php 
<?php
   phpinfo();
?>
[root@localhost test.com]# cd ..
[root@localhost htdocs]# ll   //查看属组属主是否变更
总用量 4
-rw-r--r--. 1 apache apache 45 6月  12 2007 index.html
drwxr-xr-x. 2 apache apache 23 421 21:57 test.com

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

[root@localhost ~]# cd /usr/local/apache/conf/
[root@localhost conf]# vim httpd.conf 
LoadModule proxy_module modules/mod_proxy.so   //将这两行注释取消 启动这两个模块
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

配置虚拟主机

#搜索AddType后添加两行 
[root@localhost conf]# vim httpd.conf
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php  //添加这两行   //让apache支持php的页面
AddType application/x-httpd-php-source .phps //添加这两行



#搜索index.html 
[root@localhost conf]# vim httpd.conf  
<IfModule dir_module>
    DirectoryIndex index.php index.html   //在其前面添加index.php 让网站能够访问到php类型
</IfModule>





#在文件最后添加
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test.com"   //网站位置
    ServerName test.example.com  //域名
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/$1  //网站位置
    <Directory "/usr/local/apache/htdocs/test.com">  //网站位置
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

windows操作
为真机的host文件添加ip对应的域名做映射

重启服务

[root@localhost htdocs]# apachectl stop
[root@localhost htdocs]# apachectl start
[root@localhost htdocs]# 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:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         80                         *:3306                    *:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*    

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值