我是安裝在Centos5.5上面的琳袄。首先去官網(wǎng)http://httpd.apache.org/查看下載最新的仁卷。它還有個依賴apr apr-util,和一個pcre(C語言編寫的正則表達(dá)式數(shù)庫)還有注意地址蚤吹。路徑舆瘪。
wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.23.tar.gz
依賴:APR包 pcre(一個用C語言編寫的正則表達(dá)式函數(shù)庫)
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
tar zxvf apr-1.5.2.tar.gz //解包
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install
tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
yum install pcre pcre-devel -y //這些yum的安裝苇经,就行了
tar zxvf httpd-2.4.23.tar.gz
cd httpd-2.4.23
./configure --prefix=/usr/local/httpd --enable-MODULE=shared --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make && make install
然后就是打IP到自己的瀏覽器去锨推∏撸看見 It works! 表示可以了。
下面的一步就是開機(jī)啟動换可。
本來百度的一些出來椎椰,結(jié)果做一些放上去發(fā)現(xiàn)不行,算了自己寫吧沾鳄。
需要了解一下慨飘,下面的東西
創(chuàng)建一個服務(wù)腳本,
#add for chkconfig
#chkconfig:35 80 10
#processname:myhttpd //服務(wù)名
/80代表啟動優(yōu)先級 10代表關(guān)閉優(yōu)先級
0-關(guān)機(jī)
1-單機(jī)用戶模式
2-多用戶译荞,但是沒有NFS瓤的,不能使用網(wǎng)絡(luò)
3-完全多用戶模式(標(biāo)注模式)
4-保留
5-桌面模式
6-重新啟動
一般我們用3,5即可
//下面直接操作了。
cd /etc/init.d
vim myhttpd
#add for chkconfig
#chkconfig:35 80 10
#processname:myhttpd
/usr/local/httpd/bin/apachectl start
:wq
chmod +x myhttpd
chkconfig --add myhttpd
chkconfig myhttpd on
chkconfig //直接可以看開啟的模式吞歼,看看myhttpd有沒有開啟
我這樣搞圈膏,的確感覺不是最好的方法,不過我已經(jīng)實現(xiàn)開機(jī)啟動篙骡。行了稽坤。
ps -ef | grep httpd //這樣可以查看有沒有httpd的進(jìn)程
/usr/local/httpd/bin/apachectl start
/usr/local/httpd/bin/apachectl stop
/usr/local/httpd/bin/apachectl restart
如果想要 service apache2 start,也可以實現(xiàn)糯俗,就是在寫個shell腳本尿褪,
例如vim apache2
#add for chkconfig
#chkconfig:35 80 10
#description:i am httpd22222
#processname:huang123
start()
{
/usr/local/httpd/bin/apachectl start
}
stop()
{
/usr/local/httpd/bin/apachectl stop
}
restart()
{
/usr/local/httpd/bin/apachectl restart
}
case $1 in
start )
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "no"
;;
esac
:wq //保存退出
之后的步驟和上面的一樣,就可以service apache2 start 得湘, service apache2 stop
不過我喜歡了/usr/local/httpd/bin/apachectl restart杖玲,沒有什么原因
下面的就是多站點(diǎn)配置。
首先說明就是2.4的配置和2.3淘正。2.2有些不同
/usr/local/httpd/conf //我的是編譯安裝摆马,和yum安裝的路徑不同,讀者注意地址
#Include conf/extra/httpd-vhosts.conf //把#號去掉變成 Include conf/extra/httpd-vhosts.conf 鸿吆。就是沒有了#號
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf //在這里多站點(diǎn)配置
Listen 80
<VirtualHost *:80>
ServerAdmin web@xx.com //服務(wù)器郵箱今膊,一般不用,根據(jù)情況
DocumentRoot "/usr/local/httpd/docs/" //網(wǎng)站的目錄
ServerName dummy-host.example.com //網(wǎng)站的域名
ServerAlias www.dummy-host.example.com //綁定多個域名
DirectoryIndex index.php //設(shè)置默認(rèn)的訪問的頁面
ErrorLog "logs/dummy-error_log" //錯誤日志
CustomLog "logs/access_log" common //訪問日志
<Directory "/home/">
Options FollowSymLinks //代表禁止顯示目錄結(jié)構(gòu)
AllowOverride all //允許.htaccess 生效伞剑,none就是不生效
Require all granted? //允許所有人進(jìn)行訪問
</Directory>
</VirtualHost>
//上面的參數(shù)參考一下,記住這個是2.4版本的
我在跟目錄下創(chuàng)建了一個www里面寫了一個index.html市埋。隨便寫點(diǎn)東西黎泣。
Listen 8888
<VirtualHost *:8888>
DocumentRoot "/www/"
ServerName localhost:8888
<Directory "/www/">
Options FollowSymLinks
AllowOverride all
Require all granted?
</Directory>
</VirtualHost>
好了恕刘,我成功了,瀏覽器訪問localhost 和 localhost:8888 是不同的結(jié)果完成任務(wù)抒倚。耐心看吧褐着。