APR 下载网址:
http://apr.apache.org/download.cgi
#下载bz2 的因为这个包相对来说小一点
Apache 下载网址:
http://httpd.apache.org/download.cgi#apache24
总共下了这三个包
apr-util-1.6.1.tar.bz
apr-1.7.0.tar.bz2
httpd-2.4.46.tar.bz2
useradd -s /sbin/nologin -r apache
先创建个Apache nologin的系统用户吧,不然后面启动的时候会卡主的
一、解压缩到当前目录下(gz后缀的就用gz的解压命令)
1 tar xf apr-1.7.0.tar.bz2 ;tar xf apr-util-1.6.1.tar.bz2 ;tar xf httpd-2.4.46.tar.bz2
如果提示报错,可以确认是否安装了bz2的包:yum -y install bzip2
二、将解压缩完的apr包,合并到httpd的包的srclib里面,分别更改名字为apr和apr-util(此处也可以用mv 移动)
1 cp -r apr-1.7.0 httpd-2.4.46/srclib/apr 2 cp -r apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
三、安装编译需要的依赖包
yum install gcc pcre-devel openssl-devel expat-devel -y
四、进入刚刚解压缩的httpd目录里
cd httpd-2.4.46
五、生成Makefile 文件,安装路径 app/httpd24,现在是不存在的,等会会自动创建
./configure \ --prefix=/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
六、编译
1 make && make install
或者,表示多核一起编译(下面的数字8取决于CPU核数)
make -j 8 && make install
七、进入刚刚存放路径的位置
cd /app/httpd24/
八、修改PATH变量,
echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
PATH变量修改错了,点击此处补救 (#不要问我为什么,因为我刚经历过)
这里用单引号而不是用双引号是因为双引号生成会重复,如下
单引号:
PATH=/app/httpd24/bin:$PATH
双引号
PATH=/app/httpd24/bin:/app/httpd24/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
九、让刚刚生成的PATH变量生效
. /etc/profile.d/httpd24.sh
十、启动服务
1 apachectl start 2 #按步骤启动后的提示暂时问题不大,可以不管,只是个提示 3 apachect stop 4 #关闭服务 5 apachect restart 6 #重启服务 7 #编译或者非编译安装的都可以用这个管理,当然这个管理了。systemctl status httpd 也看不到现在的状态,systemctl 只能查看到通过这个命令开启关闭的信息
建议将用户和组修改为apache
1 vim /app/httpd24/conf/httpd.conf 2 #通过/User 可以快速定位到用户这行, 3 User apache 4 Group apache 5 #将默认的用户修改为apache
十一、这里存放的路径不在/var/www/html/下 ,自己编译的存放网页的默认路径是/app/httpd24/htdocs/
十二、编译的配置文件在/app/httpd24/conf/httpd.conf
十三、开机自启动httpd
vim /etc/rc.local /app/httpd24/bin/apachectl start #这个文件没有执行权限,而且是个软连接,需要对他原本的文件添加执行权限 chmod +x rc.d/rc.local
重启系统之后,确认是否开机自启动,因为不是通过systemctl管理的,所以不能通过systemctl status 查看状态,不过可以通过ss -ntl |grep 80 查看80端口是否打开,打开则表示可以正常访问
到此就完成了编译安装httpd2.4
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
如果需要systemctl 管理httpd的话,需要做如下操作
/etc/sysconfig/httpd ,必须要这个文件,yum安装的有这个,自己编译的没有这个
cat /etc/sysconfig/httpd
#
# This file can be used to set additional environment variables for
# the httpd process, or pass additional options to the httpd
# executable.
#
# Note: With previous versions of httpd, the MPM could be changed by
# editing an "HTTPD" variable here. With the current version, that
# variable is now ignored. The MPM is a loadable module, and the
# choice of MPM can be changed by editing the configuration file
# /etc/httpd/conf.modules.d/00-mpm.conf.
#
#
# To pass additional options (for instance, -D definitions) to the
# httpd binary at startup, set OPTIONS here.
#
#OPTIONS=
#
# This setting ensures the httpd process is started in the "C" locale
# by default. (Some modules will not behave correctly if
# case-sensitive string comparisons are performed in a different
# locale.)
#
LANG=C
2、
cat /usr/lib/systemd/system/httpd24.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
将这两个配置文件添加到对应的路径,cat 后面是绝对路径,
十四、将刚刚修改的生效
systemctl daemon-reload
此时通过systemctl start httpd24 就可以开启和关闭了