方法一:使用 systemd 服务文件
sudo yum install gcc make autoconf apr-devel apr-util-devel pcre-devel
1.下载源码
wget https://archive.apache.org/dist/httpd/httpd-2.4.46.tar.gz
2.解压源码
tar -xzf httpd-2.4.46.tar.gz
如果没有安装tar 记得先安装
sudo yum install tar
cd httpd-2.4.46
3.编译安装
./configure --prefix=/usr/local/apache --enable-so --enable-ssl
make
make install
4.创建 systemd 服务文件:
创建 /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