在 CentOS 8 上面编译安装 http 服务
从官网下载好必要的软件包:
[root@CentOS8Test ~]# mkdir package
[root@CentOS8Test ~]# cd package/
[root@CentOS8Test package]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.46.tar.gz
验证软件包:
[root@CentOS8Test package]# tar -zxf apr-1.7.0.tar.gz
[root@CentOS8Test package]# tar -zxf apr-util-1.6.1.tar.gz
[root@CentOS8Test package]# tar -zxf httpd-2.4.46.tar.gz
[root@CentOS8Test package]# ls
apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz httpd-2.4.46 httpd-2.4.46.tar.gz
准备编译环境:
[root@CentOS8Test package]# yum install -y gcc make pcre-devel openssl-devel expat-devel
编译安装apr
[root@CentOS8Test package]# cd apr-1.7.0/
[root@CentOS8Test apr-1.7.0]# ./configure --prefix=/etc/apr
[root@CentOS8Test apr-1.7.0]# make
[root@CentOS8Test apr-1.7.0]# make install
* 在进行编译安装时,我们可以通过 ./configure --help 获取编译配置的帮助,–prefix 指定安装目录,默认是 /usr/local
编译安装apr-util
[root@CentOS8Test apr-1.7.0]# cd ..
[root@CentOS8Test package]# cd apr-util-1.6.1/
[root@CentOS8Test apr-util-1.6.1]# ./configure --prefix=/etc/apr-util --with-apr=/etc/apr/
[root@CentOS8Test apr-util-1.6.1]# make
[root@CentOS8Test apr-util-1.6.1]# make install
* –with-package 指定依赖包
编译安装 http
[root@CentOS8Test apr-util-1.6.1]# cd ..
[root@CentOS8Test package]# cd httpd-2.4.46/
[root@CentOS8Test httpd-2.4.46]# ./configure --prefix=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/etc/apr/ --with-apr-util=/etc/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@CentOS8Test httpd-2.4.46]# make
[root@CentOS8Test httpd-2.4.46]# make install
* http 的编译选项,可以根据实际情况进行选择
创建 Apache 账户
[root@CentOS8Test ~]# useradd -s /sbin/nologin -r apache
指定以 Apache 账户运行 httpd 服务
[root@CentOS8Test ~]# vim /etc/httpd24/conf/httpd.conf
[root@CentOS8Test ~]# cat /etc/httpd24/conf/httpd.conf | grep -e "^User" -e "^Group"
User apache
Group apache
配置环境变量
[root@CentOS8Test httpd-2.4.46]# vim /etc/profile.d/httpd24.sh
[root@CentOS8Test httpd-2.4.46]# cat /etc/profile.d/httpd24.sh
PATH=/app/httpd24/bin:$PATH
设置开机启动:
[root@CentOS8Test httpd-2.4.46]# cat /etc/rc.d/rc.local | grep -Ev "^$|#"
touch /var/lock/subsys/local
/etc/httpd24/bin/apachectl start
[root@CentOS8Test ~]# ls -l /etc/rc.d/rc.local
-rw-r--r--. 1 root root 506 Mar 23 11:55 /etc/rc.d/rc.local
[root@CentOS8Test ~]# chmod a+x /etc/rc.d/rc.local
[root@CentOS8Test ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 128 [::]:111 [::]:*
重启服务器后,查看监听的端口:
[root@CentOS8Test ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [::1]:6010 [::]:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128
配置防火墙
[root@CentOS8Test ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@CentOS8Test ~]# firewall-cmd --reload
success
现在,你可以在另一台机器上通过浏览器访问了。