方法一、
1、安裝開發環境包組及相關包:
yum groupinstall “Development Tools”
yum install pcre-devel openssl-devel expat-devel
2、下載源代碼並解壓縮:
rz 導入源代碼
tar xvf httpd-2.4.28.tar.bz2 解壓縮
tar xvf apr-1.6.2.tar.bz2
tar xvf apr-util-1.6.0.tar.bz2
3、安裝apr-1.6.2
①cd apr-1.6.2
②./configure --prefix=/app/apr 指定配置文件路徑
③make && make install
4、安裝apr-util-1.6.0
①cd ~/apr-util-1.6.0
②./configure --prefix=/app/apr-util --with-apr=/app/apr/ 編譯apr-util時需要調用apr
③make && make install
5、編譯安裝httpd-2.4.28
①cd ~/httpd-2.4.28
②./configure --prefix=/app/httpd24 \ 啓用一些特定的功能模塊
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/app/apr/ \
--with-apr-util=/app/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
③make -j 4 && make install -j 4表示使用四個處理器同時編譯
測試:cd /app/httpd24/bin
apachectl start 啓動服務
ss -ntl 查看80端口已打開
6、爲了方便使用,可以配置PATH變量以及服務腳本
①添加PATH變量:
vim /etc/profile.d/path.sh
PATH=/app/httpd24/bin:$PATH
執行腳本生效 . /etc/profile.d/path.sh
②vim /app/httpd24/conf/httpd.conf 修改如下兩行表示以apache身份運行httpd服務
User apache
Group apache
③配置服務腳本:
cp /etc/init.d/httpd /etc/init.d/httpd24
vim /etc/init.d/httpd24 修改如下四行
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
④chkconfig --add httpd24 添加服務腳本
⑤service httpd24 restart 重新啓動服務
7、測試:
方法二、
與方法一大致一樣,只是編譯的時候不一樣
1 、安裝開發環境包組及相關包:
yum groupinstall "development tools"
yum install openssl-devel pcre-devel expat-devel
2 、下載源代碼並解壓縮:
rz 導入源代碼
tar xvf apr-1.6.2.tar.gz
tar xvf apr-util-1.6.0.tar.gz
tar xvf httpd-2.4.28.tar.bz2
3、將apr和apr-util都放到httpd-2.4.28/srclib/下,並且改名
cp -a apr-1.6.2 httpd-2.4.28/srclib/apr
cp -a apr-util-1.6.0 httpd-2.4.28/srclib/apr-util
4、編譯安裝
cd httpd-2.4.28
./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
make -j 4 && make install
5、修改path變量即服務腳本,方便使用
vim /etc/profile.d/httpd24.sh
PATH=/app/httpd24/bin:$PATH
運行腳本生效 . /etc/profile.d/httpd24.sh
6、修改主配置文件,以apache身份運行httpd服務
vim /app/httpd24/conf/httpd.conf
User apache
Group apache
7、配置服務腳本
cp /etc/init.d/httpd /etc/init.d/httpd24
vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
chkconfig --add httpd24
service httpd24 start 啓動服務
8、測試:
感謝瀏覽,如有疑問,歡迎留言