在CentOS7.7源码编译安装httpd-2.4.41

需要下载的源码编译安装包:
在apache官网(http://www.apache.org/index.html#projects-list)下载下面需要的安装包

httpd-2.4.41.tar.bz2(最小化安装系统需安装bzip2) 
apr-1.7.0.tar.gz  
apr-util-1.6.1.tar.gz

基于最小化安装的centos系统,生产实践,源码编译需要安装下面组件

yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel systemd-devel zlib-devel  vim lrzsz tree screen lsof tcpdump wget  ntpdate net-tools iotop bc  zip unzip nfs-utils bzip2 expat-devel autoconf libtool -y

将三个源码编译压缩文件导入指定目录下,如/data下并解压缩

[root@CentOS7 ~]# cd /data/
[root@CentOS7 data]# ls
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.41.tar.bz2
[root@CentOS7 data]# tar xf apr-1.7.0.tar.bz2
[root@CentOS7 data]# tar xf apr-util-1.6.1.tar.bz2
[root@CentOS7 data]# tar xf httpd-2.4.41.tar.bz2
[root@CentOS7 data]# ls
apr-1.7.0          apr-util-1.6.1          httpd-2.4.41
apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.41.tar.bz2

复制解压文件到同一目录下

[root@CentOS7 data]# cp -r apr-1.7.0 httpd-2.4.41/srclib/apr
[root@CentOS7 data]# cp -r apr-util-1.6.1 httpd-2.4.41/srclib/apr-util

进入http-2.4.41目录下

[root@CentOS7 data]#  cd httpd-2.4.41

编译安装,其中–with-included-apr表示合在一起进行编译安装
指定安装路径

[root@CentOS7 httpd-2.4.41]# ./configure --prefix=/usr/local/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@CentOS7 data]#  make -j 4 && make install 

修改环境变量

vim /etc/profile.d/httpd24.sh
PATH=/usr/local/app/httpd24/bin:$PATH
[root@CentOS7 httpd-2.4.41]# source /etc/profile.d/httpd24.sh

修改完成后. /etc/profile.d/httpd24.sh使之生效
添加apache用户,自动创建组

[root@CentOS7 httpd-2.4.41]# useradd -r -s /sbin/nologin apache

修改配置文件,将默认的用户和组添加为新加的apache用户

[root@CentOS7 httpd-2.4.41]# vim /usr/local/app/httpd24/conf/httpd.conf
User daemon
Group daemon
改为
User apache
Group apache

修改服务启动脚本,将服务设置为开机自启动

vim /etc/rc.d/rc.local
/usr/local/app/httpd24/bin/apachectl start

添加执行权限

[root@CentOS7 httpd-2.4.41]# chmod +x /etc/rc.d/rc.local

启动服务

[root@CentOS7 httpd-2.4.41]# apachectl status

查看服务端口号以及进程

[root@CentOS7 httpd-2.4.41]# ss -ntl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port       
LISTEN      0      100    127.0.0.1:25                        *:*
LISTEN      0      128           *:111                       *:*
LISTEN      0      128           *:22                        *:*
LISTEN      0      100       [::1]:25                     [::]:*
LISTEN      0      128        [::]:111                    [::]:*
LISTEN      0      128        [::]:22                     [::]:*
[root@CentOS7 httpd-2.4.41]# ps -aux
apache    71266  0.0  0.1  99572  1624 ?        S    15:05   0:00 /usr/local/app/ht
apache    71267  0.0  0.1  99572  1624 ?        S    15:05   0:00 /usr/local/app/ht
apache    71268  0.0  0.1  99572  1624 ?        S    15:05   0:00 /usr/local/app/ht
apache    71269  0.0  0.1  99572  1624 ?        S    15:05   0:00 /usr/local/app/ht
apache    71270  0.0  0.1  99572  1624 ?        S    15:05   0:00 /usr/local/app/ht

重启后即可自动启动

[root@CentOS7 httpd-2.4.41]# reboot

网页存放路径为/usr/local/app/httpd24/htdocs/index.html中,编辑即可修改 配置文件在/usr/local/app/httpd24/conf/httpd.conf中,编辑即可修改如修改端口号:添加Listen 8090,修改完成后,执行apachectl restart 重启服务生效,在浏览器中输入IP:端口号即可访问/app/httpd24/htdocs/index.html其中的内容通过ss -ntl查看服务启动后相应端口号是否生成通过ps -aux可查看httpd进程的属主为apache

你可能感兴趣的:(在CentOS7.7源码编译安装httpd-2.4.41)