apache安装

环境准备

apache优点: 可以设定编译参数按需安装、选择需要安装的版本、灵活性大,更新速度快
缺点:编译较麻烦、需要解决依赖关系且相对耗时

[root@localhost ~]# yum -y install gcc*   ##准备编译器
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
……开始编译安装
Dependency Updated:
  glibc.x86_64 0:2.17-326.el7_9      glibc-common.x86_64 0:2.17-326.el7_9    libgcc.x86_64 0:4.8.5-44.el7    libgomp.x86_64 0:4.8.5-44.el7   
  libstdc++.x86_64 0:4.8.5-44.el7   

Complete!  ###安装成功
[root@localhost ~]# yum -y install apr-util-devel pcre-devel  ##准备依赖库
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn
Resolving Dependencies
…………
Dependency Updated:
  cyrus-sasl-lib.x86_64 0:2.1.26-24.el7_9   expat.x86_64 0:2.1.0-15.el7_9   libdb.x86_64 0:5.3.21-25.el7   libdb-utils.x86_64 0:5.3.21-25.el7  
  openldap.x86_64 0:2.4.44-25.el7_9        

Complete!

编译安装apache源码包

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

[root@localhost ~]#  tar zxf httpd-2.4.25.tar.gz -C /usr/src   ##解包
[root@localhost ~]#  cd /usr/src/httpd-2.4.25/
[root@localhost httpd-2.4.25]#  ./configure --prefix=/usr/local/httpd --enable-so  --enable-rewrite --enable-charset-lite --enable-cgi
checking for chosen layout... Apache
checking for working mkdir -p... yes
…………
[root@localhost httpd-2.4.25]# make && make install

–prefix:指定将 httpd 服务程序安装到哪个目录下,如/usr/local/httpd。
–enable-so:启用动态加载模块支持,使 httpd 具备进一步扩展功能的能力。
–enable-rewrite:启用网页地址重写功能,用于网站优化及目录迁移维护。
–enable-charset-lite:启用字符集支持,以便支持使用各种字符集编码的网页。
–enable-cgi:启用 CGI 脚本程序支持,便于扩展网站的应用访问能力。

[root@localhost httpd-2.4.25]# ls /usr/local/httpd  ##确认安装结果
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

/bin:存放 httpd 服务的各种可执行程序文件,包括主程序 httpd、服务控制工具 apachectl 等
/conf:存放 httpd 服务的各种配置文件,包括主配置文件 httpd.conf、增强配置子目录 extra 等
/htdocs:存放网页文档,包括默认首页文件 index.html 等
/logs:存放 httpd 服务的日志文件
/modules:存放 httpd 服务的各种模块文件。
/cgi-bin:存放各种 CGI 程序文件

设置环境变量

[root@localhost httpd-2.4.25]# ln -s /usr/local/httpd/bin/* /usr/local/bin
[root@localhost httpd-2.4.25]# ap  创建环境变量后httpd和apachectl命令就可以使用了
apachectl           applygnupgdefaults  apr-1-config        apropos             apu-1-config        apxs 

添加 httpd 系统服务

[root@localhost httpd-2.4.25]# vim /lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart= /usr/local/bin/apachectl $OPTIONS
ExecReload= /bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
##保存退出
[root@localhost httpd-2.4.25]# systemctl daemon-reload
[root@localhost httpd-2.4.25]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. ##设置开机启动

Web 网站的部署过程

1.确定网站名称、IP 地址

[root@localhost httpd-2.4.25]# vi /usr/local/httpd/conf/httpd.conf
ServerName www.aaa.com:80  ##200行去掉#号,更改域名
##保存退出
[root@localhost httpd-2.4.25]# httpd -t  ##检测语法
Syntax OK
[root@localhost httpd-2.4.25]# systemctl start httpd  ##启动服务
[root@localhost httpd-2.4.25]# ss -tnl
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                                                     :::*                  
[root@localhost httpd-2.4.25]# vim /usr/local/httpd/htdocs/index.html  ##设置网站网页
aaaa
[root@localhost httpd-2.4.25]# vi /etc/hosts ##修改hosts文件
192.168.10.114 www.aaa.com
[root@localhost httpd-2.4.25]# curl www.aaa.com  ##访问网站
aaaa


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值