下面是linux下安裝apache的完整代碼,系統(tǒng)是redhat5.5
下載httpd-2.2.6.tar.bz2 把httpd-2.2.6.tar.bz2放到/soft 下
[root@localhost ~]#cd /soft
[root@localhost soft]#tar jxvf httpd-2.2.6.tar.bz2 //解壓apache的壓縮包
[root@localhost soft]#cd httpd-2.2.6 //定位到httpd-2.2.6 文件夾下
[root@localhost httpd-2.2.6]#ls //查看顯示httpd-2.2.6 文件夾下內(nèi)容
[root@localhost httpd-2.2.6]#./configure --help | more //查看安裝apache配置參數(shù)
[root@localhost httpd-2.2.6]#./configure --prefix=http://www.3lian.com/usr/local/apache --enable-so // 配置apache路徑
[root@localhost httpd-2.2.6]#make //編譯apache
[root@localhost httpd-2.2.6]#make install //安裝apache
[root@localhost httpd-2.2.6]#cd /usr/local/apache //進(jìn)入apache的目錄
[root@localhost apache]# cd conf/
[root@localhost conf]#cp -a httpd.conf httpd.conf- //備份apache配置文件
[root@localhost conf]#chkconfig --list httpd //查看httpd服務(wù)是否已存在
[root@localhost conf]#chkconfig httpd off //關(guān)閉系統(tǒng)自帶了httpd的服務(wù),如果存在httpd服務(wù)
[root@localhost conf]#service httpd status //查看自帶httpd服務(wù)狀態(tài)
[root@localhost conf]#/usr/local/apache/bin/apachectl -k start //linux啟動(dòng)apache命令
[root@localhost conf]#netstat -an | grep :80 //查看linux80端口是否開(kāi)啟
[root@localhost conf]#ps -aux | grep httpd //linux下查看apache進(jìn)程
[root@localhost conf]#cd ../..
[root@localhost local]#cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache //拷貝apache啟動(dòng)腳本
[root@localhost local]#vi /etc/rc.d/init.d/apache // 這里是編輯apache啟動(dòng)腳本
在開(kāi)頭的#!/bin/sh 下面加上
#chkconfig: 2345 85 15
[root@localhost local]#chkconfig --add apache //添加apache服務(wù)
[root@localhost local]#chkconfig --list apache //列出apache服務(wù)
[root@localhost local]#service apache stop //停止apache服務(wù)
[root@localhost local]#netstat -an | grep :80 //查看linux的80端口是否關(guān)閉
[root@localhost local]#ps -aux | grep httpd //查看是否存在httpd服務(wù),若果之前自帶httpd服務(wù)啟動(dòng)的話會(huì)導(dǎo)致新添加的apache服務(wù)啟動(dòng)失敗
[root@localhost local]#service apache start //啟動(dòng)apache服務(wù)