一.使用 systemd 服务文件
1.在官网找到并且下载安装包
Download - The Apache HTTP Server Project
2.解压
tar xf httpd-2.4.62.tar.gz -C /usr/local/src/
3.安装依赖
[root@localhost ~]# dnf install gcc gcc-c++ make pcre-devel openssl-devel -y
4.编译安装
cd /usr/local/src/httpd-2.4.62/#如果没有APR库需要自己安装
sudo yum install apr-devel apr-util-devel./configure --prefix=/usr/local/apache --enable-so --enable-sslmakemake install
5.创建 systemd 服务文件:
vim /etc/systemd/system/httpd.service[Unit]
Description=The Apache HTTP Server
After=network.target[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
6.启动服务
systemctl daemon-reload
systemctl start httpd
systemctl enable httpd
二.使用二进制方式安装
前面四步和systrmd一样
5.配置http.confd文件
[root@192 homework]# mkdir -pv /etc/httpd/conf/
mkdir: 已创建目录 '/etc/httpd'
mkdir: 已创建目录 '/etc/httpd/conf/'
[root@192 homework]# vim /etc/httpd/conf/http.confServerRoot "/usr/local/apache2"
Listen 80
ServerName localhost:80
DocumentRoot "/usr/local/apache2/htdocs"
6.启动该文件
/usr/local/apache/bin/apachectl start