安装httpd
1.源码编译安装
//下载依赖包
[root@openEulter-1 ~]# dnf -y install gcc gcc-c++ make apr-* pcre-devel redhat-rpm-config
...安装过程省略...
Complete!
//下载软件包
[root@openEulter-1 ~]# wget https://archive.apache.org/dist/httpd/httpd-2.4.58.tar.gz
...安装过程省略...
//解压软件包
[root@openEulter-1 ~]# tar xf httpd-2.4.58.tar.gz
[root@openEulter-1 ~]# ls
anaconda-ks.cfg httpd-2.4.58 httpd-2.4.58.tar.gz
//配置相关选项,并生产makefile
[root@openEulter-1 ~]# cd httpd-2.4.58
[root@openEulter-1 httpd-2.4.58]# ./configure --prefix=/opt/httpd-2.4.58
...过程省略...
configure: summary of build options:
Server Version: 2.4.58
Install prefix: /opt/httpd-2.4.58
C compiler: gcc
CFLAGS:
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
//验证命令是否成功
[root@openEulter-1 httpd-2.4.58]# echo $?
0
//编译并安装
[root@openEulter-1 httpd-2.4.58]# make
[root@openEulter-1 httpd-2.4.58]# make install
//建立软链接
[root@openEulter-1 httpd-2.4.58]# ln -s /opt/httpd-2.4.58 /opt/httpd
//设置环境变量
[root@openEulter-1 ~]# echo 'export PATH=/opt/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
//刷新当前的shell环境,脚本立即生效
[root@openEulter-1 ~]# source /etc/profile.d/httpd.sh
//查看命令执行文件的位置
[root@openEulter-1 ~]# which httpd
/opt/httpd/bin/httpd
//修改配置文件,确定域名
[root@openEulter-1 ~]# vim /opt/httpd-2.4.58/conf/httpd.conf
#ServerName www.example.com:80
改为
ServerName localhost:80
(不修改的话,启动httpd会显“httpd: Could not reliably determine the server’s fully qualified domain name”的一个报错)
//启动服务,并查看端口号
[root@openEulter-1 ~]# httpd
[root@openEulter-1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 511 *:80 *:*
2.dnf方式安装
[root@openEulter-1 ~]# dnf install httpd -y
[root@openEulter-1 ~]# systemctl start httpd
[root@openEulter-1 ~]# ps -ef | grep httpd
root 33101 1 0 19:07 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 33102 33101 0 19:07 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 33103 33101 0 19:07 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 33104 33101 0 19:07 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 33105 33101 0 19:07 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 33284 2067 0 19:08 pts/1 00:00:00 grep --color=auto httpd