天天看點

CentOS 7 編譯安裝httpd-2.4.17

環境說明

VMware 12 中 CentOS 7 x64 4cpu 2G記憶體

環境中已經安裝了《

CentOS 7 編譯安裝 MySQL-5.7.9

》《

CentOS 7 編譯安裝PHP7

配置防火牆和開放端口

參考

》中的 “配置防火牆和開放端口”

編譯安裝httpd所需依賴

下載下傳

apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz httpd-2.4.17.tar.gz pcre-8.38.tar.gz

上傳到/root/目錄

######編譯安裝apr-1.5.2.tar.gz     [root@localhost ~]# tar zxf apr-1.5.2.tar.gz && cd apr-1.5.2     [root@localhost apr-1.5.2]# yum install gcc libtools -y     [root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr     [root@localhost apr-1.5.2]# make && make install     [root@localhost apr-1.5.2]# cd .. && rm -rf ../apr-1.5.2*     ######編譯安裝apr-util-1.5.4.tar.gz     [root@localhost ~]# tar zxf apr-util-1.5.4.tar.gz && cd apr-util-1.5.4     [root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/     [root@localhost apr-util-1.5.4]# make && make install     [root@localhost apr-util-1.5.4]# cd .. && rm -rf apr-util-1.5.4*     ######編譯安裝pcre-8.38.tar.gz     [root@localhost ~]# tar zxf pcre-8.38.tar.gz && cd pcre-8.38     [root@localhost pcre-8.38]# ./configure --prefix=/usr/local/pcre     [root@localhost pcre-8.38]# make && make install     [root@localhost pcre-8.38]# cd .. && rm -rf pcre-8.38*           

編譯安裝httpd-2.4.17

[root@localhost ~]# tar zxf httpd-2.4.17.tar.gz && cd httpd-2.4.17     [root@localhost httpd-2.4.17]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre     [root@localhost httpd-2.4.17]# make && make install     [root@localhost httpd-2.4.17]# cd .. && rm -rf httpd-2.4.17*           

配置Apache

設定Apache開機啟動,添加Apache到Linux服務

[root@localhost init.d]# vi /usr/local/apache/conf/httpd.conf     1.搜尋ServerName www.example.com:80 去掉前面的注釋     2.修改DocumentRoot到/home/htdocs,以及這一行下面的一句中的<Directory到/home/htdocs     這個是www的根目錄設定     [root@localhost apache]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd     [root@localhost init.d]# vi httpd      在第一行下添加如下兩行文字     # Comments to support chkconfig on RedHat Linux     # chkconfig: 2345 90 90     # description:http server     注冊該服務      [root@localhost init.d]# chkconfig --add httpd  #所有開機模式下自啟動     [root@localhost init.d]# chkconfig httpd on  #345開機模式下自啟動           

運作Apache

[root@localhost init.d]# service httpd start     ######檢視運作狀态     [root@localhost init.d]# ps -aux | grep httpd     在主機浏覽器輸入linux的ip     出現     It works!           

參考網址

http://linux.it.net.cn/CentOS/server/webserver/2015/0320/14007.html