EverKB

Knowledge Base Ever

在CentOS7上編譯安裝Apache2.4

2019-11-15 12:18:53

標籤: CentOS, Apache, CentOS7, Apache2.4, Compiling Apache, 編譯Apache httpd2.4

CentOS7自帶Apache httpd(後文中簡稱httpd)服務,如果你的機器上不包含該服務時,可以使用yum安裝。

如果需要安裝httpd新版本,如httpd2.4,那就需要自己編譯。編譯的過程並不復雜,只是依賴的軟件包也需要編譯安裝,導致整個過程有些複雜。

卸載舊版本,再安裝編譯工具,並卸載安裝包的舊版本

yum -y remove httpd

yum -y install gcc gcc-c++
yum -y group install "Development Tools"

yum -y remove apr apr-devel apr-util apr-util-devel

安裝apr

cd /usr/local/src/
yum -y install wget
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
tar xf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure --prefix=/usr/local/apr
make && make install

安裝apr-util

yum -y install expat-devel

cd /usr/local/src/
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar xf apr-util-1.6.1.tar.gz 
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config 
make && make install

安裝pcre

cd /usr/local/src/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.43.tar.gz
tar xf pcre-8.43.tar.gz 
cd pcre-8.43
./configure --prefix=/usr/local/pcre  
make && make install

編譯httpd

cd /usr/local/src/
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.39.tar.gz
tar xf httpd-2.4.39.tar.gz
cd httpd-2.4.39
./configure --prefix=/usr/local/apache --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make && make install

編輯/etc/init.d/httpd配置文件,配置systemctl啟動

#!/bin/bash
# chkconfig: 12345 80 90
function start_http()
{
    /usr/local/apache/bin/apachectl start
}
function stop_http()
{
    /usr/local/apache/bin/apachectl stop
}
case "$1" in
start)
    start_http
;;
stop)
    stop_http
;;
restart)
    stop_http
    start_http
;;
*)
    echo "Usage : start | stop | restart"
;;
esac

設置可執行權限,啟動服務,並設置為開機時啟動

chmod a+x /etc/init.d/httpd
systemctl daemon-reload
systemctl start httpd
chkconfig --add httpd

標籤

CentOS7 CentOS PHP Linux Python3 Python MySQL JavaScript MariaDB YUM Redis MySQL8 caching_sha2_password HTML mysql_native_password PHP7 CSS PHPUnit Framework ss5.passwd at-symbol Error Control Operator margin password SOCKET vps daemon process IIS sudoers center Fatal Errors MongoDB4 Phalcon SQL Server 2017 WiFi .htaccess DATE_SUB set_error_handler TestCase Compiling PHP frequency conflict PHPUnit ss5.conf apr Elasticsearch7.3 particles.js Slim Vincent Garreau daemon HTTP Sudo Failed to build these modules: _uuid MongoDB pg_bha.conf SQL Server width DATE_ADD ip command scrollbar Tcp BBR Compiling Apache Frameworks MySQL-python PHPStorm ss5-3.8.9 Apache2.4 Elasticsearch libpython3.7m.so.1.0 NodeJs show VIM CURLOPT_POSTFIELDS substr Bluetooth Failed to build these modules: _ctypes Minimal ISO PECL SQL Date Funcitons Wi-Fi date sub INTERVAL root Tag Cloud CodeIgniter font-size ss5 apache httpd dual network interfaces Laravel ShadowsocksR vertical-align CURLFille horiz-align node.js PyCharm SUBDATE BarManager exec mb_substr PEAR SOCKS5 Proxy Server WebStorm date add IntelliJIDEA remi Tag Chrome find PHP5.5 src Apache du jQuery Shadowsocks-Python V2Ray cURL hide nginx PostgreSQL sub folder availability eth0 MariaDB10.4 pdo_sqlsrv SOCKS5 Web Server date Install MongoDB register_shutdown_function Symfony File Upload mssql-tools php-fpm sqlsrv Zend Framework ADDDATE DevExpress JetBrain Shadowsocks-Libev unixODBC-devel height network interface Port 80 string Aura error_get_last password policy requirements SOCKS Web Development data INDENTIFIED BY Redis5 SVN Fedora Media Writer msodbcsql SQLAlchemy absolute Deepin jemalloc Shadowsocks toggle convert FuelPHP mysqlclient