【Linux系统环境中使用二进制包安装Apache】

Linux系统环境中使用二进制包安装Apache

创建系统用户及用户组

复制代码
	groupadd -r -g 48 apache
	useradd -r -u 48 -g 48 -c "Apache server" -s /sbin/nologin apache

方法一:使用系统安装脚本(推荐)

复制代码
    [官方源码包下载链接](https://downloads.apache.org/httpd/httpd-2.4.62.tar.gz)
  1. 准备编译工具,下载安装包并解压

    准备编译工具

    复制代码
    yum install gcc gcc-c++ make -y

    下载apache二进制安装包,依赖后续安装

    复制代码
    wget -P /usr/local/src https://downloads.apache.org/httpd/httpd-2.4.62.tar.gz

    解压二进制包

    复制代码
    tar xf /usr/local/src/httpd-2.4.62.tar.gz -C /usr/local/src/

    进入解压的二进制包

    复制代码
    cd /usr/local/src/httpd-2.4.62
  2. 下载所需依赖并编译安装

    使用官方的配置脚本将Apache安装到指定路径(没安装依赖运行会报错,可以先安装依赖再执行)

    复制代码
     ./configure --prefix=/usr/local/apache

    下载相关依赖

    复制代码
     yum list | grep -i apr
     	yum install apr-devel.x86_64 -y
     	yum install apr-util-devel.x86_64 -y
     yum list | grep -i pcre
     	yum install pcre-devel.x86_64 -y

    下载完依赖后再次编译安装(如果先前安装过所需依赖只要安装一次即可)

    复制代码
     ./configure --prefix=/usr/local/apache
     make && make install	
  • make:编译源代码并生成可执行文件或库文件,按照 Makefile 中的规则执行编译。
  • make install:将已编译的文件安装到系统中指定的目录,通常需要管理员权限。
  • 如果没有安装依赖,会报出如图错误



    按照错误提示安装所需依赖即可,部分版本可能会在编译时需要依赖,同理根据提示安装相应依赖即可
  • 编译完成
  1. 准备启动脚本

    复制代码
     cd /usr/local/apache/bin

    拷贝官方启动脚本

    复制代码
     cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

    检查拷贝的文件是否有执行权限

    复制代码
     ll /etc/init.d/httpd

    编辑拷贝的文件,添加如下两行

    复制代码
     vim /etc/init.d/httpd
     	# chkconfig: 35 85 15
     	# description:  Apache is an HTTP(S) server
  2. 修改文件后添加系统应用并设置开机自启动

    复制代码
     chkconfig --level 35 --add httpd
     chkconfig --level 35 httpd on
     chkconfig --list httpd

    启动服务&查看状态、端口

    复制代码
     systemctl start httpd
     systemctl status httpd
     netstat -lnupt grep 80
  • 通过浏览器访问虚拟机IP地址:

方法二:自行编辑脚本

复制代码
   #  创建脚本文件
       vim /usr/lib/systemd/system/httpd.service
  • 脚本内容
bash 复制代码
# See httpd.service(8)for more information on using the httpd service.
# Modifying this file in-place is not recommended,because changes
# will be overwritten during package upgrades.To customize the
# behaviour,run "systemctl edit httpd"to create an override unit.
       
# For example,to pass additional options (such as -D definitions)to
# the httpd binary at startup,create an override unit (as is done by
# systemctl edit)and enter the following:
       
# 		[Service]
# 		Environment=OPTIONS=-DMY_DEFINE
[Unit]
Description=The Apache HTTP Server
Wants=httpd-init.service
After=network.target remote-fs.target nss-lookup.target httpd-init.service
Documentation=man:httpd.service(8)
       
[Service]
Type=forking
PIDFile=/usr/local/apache/logs/httpd.pid
ExecStart=/usr/local/apache/bin/httpd -k start
ExecReload=/usr/local/apache/bin/httpd -k restart
ExecStop=/usr/local/apache/bin/httpd -k stop
PrivateTmp=true
       
[Install]
WantedBy=multi-user.target
  • 语法检测及修改用户及用户组
bash 复制代码
# 语法检测(以下两个一致)
   /usr/local/apache/bin/httpd -t
   /usr/local/apache/bin/apachectl -t
# 修改配置文件
   vim /usr/local/apache/conf/httpd.conf
   	把user和group改成apache

删除安装方法一所做配置:

  • 由于我是在同一台虚拟机上安装的,所以在进行第二种安装方式之前先将方法一所作的操作删除
bash 复制代码
	# 删除httpd的系统服务   
			systemctl stop httpd
			chkconfig --level 35 httpd off
        	chkconfig --list httpd
        	chkconfig --level 35 --del httpd
	# 检查是否删除
        	ll /etc/rc.d/rc3.d/
	# 以上仅删除系统服务,没有删除文件
        	ll /etc/init.d/
        	rm -f /etc/init.d/httpd
相关推荐
yunwei376 分钟前
eBPF 教程:追踪 CUDA GPU 操作
linux·后端·性能优化
Android系统攻城狮9 分钟前
Linux Gstreamer深度解析之gst_audio_channel_reorder_map调用流程与实战(十八)
linux·运维·服务器·音视频进阶·gstreamer音视频进阶
新时代牛马29 分钟前
docker run 起不来?从dockerd、containerd 到runc 一条线讲透
运维·docker·容器
TomEval38 分钟前
【App 自动化】14 - App 自动化基础与环境
运维·自动化
新时代牛马1 小时前
Linux 防火墙:nftables 与iptables 兼容层
linux·运维·服务器
xhbh6661 小时前
中小企业 Redis 运维,如何安全归档 RDB、AOF 备份文件?
运维·数据库·缓存·数据备份·文件备份·同步备份·号码备份
是逍遥子没错1 小时前
一个斜杠,击穿整座网关:API网关路径前缀绕过认证实战
运维·服务器·web安全·网络安全·渗透测试·系统安全
其实防守也摸鱼2 小时前
每天一个知识点——RCE漏洞
运维·服务器·数据库·windows·安全·github·漏洞
努力努力再努力wz2 小时前
【Docker 入门系列】:从 Namespace、CGroup 到 LXC:理解容器运行时、rootfs 与 LXC 实战
运维·docker·容器
ao-weilai2 小时前
Linux网络编程:网络知识基础
linux·网络·php