上一個部落格中,記錄了在Linux下安裝、啟動mysql,地址:http://blog.csdn.net/wy3552128/article/details/8143686
平台:VMware上虛擬centos4.7
宿主機:windows
安裝Apache前準備:
1、檢查該環境中是否已經存在httpd服務的設定檔,預設儲存路徑:/etc/httpd/httpd.conf(這是centos預裝的Apache的一個ent版本,一般我們安裝原始碼版的Apache)。如果已經存在/etc/httpd/httpd.conf,請先卸載或者關閉centos系統內建的web服務,執行命令:chkconfig
httpd off,再或者把centos內建的httpd服務的80連接埠改為其他連接埠,只要不與我們安裝的Apache服務的連接埠衝突就可以啦。
停止並卸載Linux系統內建的httpd服務:
1、service httpd stop
2、ps -ef | grep httpd
3、kill -9 pid號(逐個刪除)
4、rpm -qa |grep
httpd
5、rpm
-e httpd軟體包
[root@localhost bin]# find / -name httpd.conf[root@localhost bin]#
2、下載Apache安裝包(httpd-2.4.3.tar.gz或httpd-2.2.23.tar.gz),:http://httpd.apache.org/
在安裝Apache時,我分別針對不同版本進行了安裝,在編譯時間是不同的,configure後跟的參數不同。
httpd-2.2.23版本編譯命令:
./configure --prefix=/usr/local/apache2 (安裝目錄參數後面可以不加任何參數,直接安裝即可)makemake install
httpd-2.4.3版本編譯命令:
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre (除了指定Apache的安裝目錄外,還要安裝apr、apr-util、pcre,並指定參數)makemake install
在編譯Apache(在安裝httpd-2.4.3時遇到的問題)時分別出現了apr not found、APR-util not found、pcre-config for libpcre not found的問題,下面就httpd-2.4.3的這些問題解決來實際操作一把。
http://apr.apache.org/download.cgi 下載apr-1.4.5.tar.gz、apr-util-1.3.12.tar.gz
http://sourceforge.net/projects/pcre/files/latest/download 下載pcre-8.31.zip
1.解決apr not found問題
[root@localhost bin]# tar -zxf apr-1.4.5.tar.gz [root@localhost apr-1.4.5]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.4.5]# make [root@localhost apr-1.4.5]# make install
2.解決APR-util not found問題
[root@localhost bin]# tar -zxf apr-util-1.3.12.tar.gz [root@localhost apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config [root@localhost apr-util-1.3.12]# make [root@localhost apr-util-1.3.12]# make install
3、解決pcre-config for libpcre not found問題
[root@localhost ~]# unzip pcre-8.31.zip [root@localhost ~]# cd pcre-8.31 [root@localhost pcre-8.31]# ./configure --prefix=/usr/local/pcre [root@localhost pcre-8.31]# make[root@localhost pcre-8.31]# make install
如果已經存在/etc/httpd/httpd.conf,請先卸載或者關閉centos系統內建的web服務,執行命令:chkconfig httpd off,再或者把centos內建的httpd服務的80連接埠改為其他連接埠,只要不與我們安裝的Apache服務的連接埠衝突就可以啦。
•啟動Apache:/usr/local/apache2/bin/apachectl start
•停止Apache:/usr/local/apache2/bin/apachectl stop
•重啟Apache:/usr/local/apache2/bin/apachectl restart
網站放在/usr/local/apache2/htdocs目錄下
在IE中通過http://localhost:80,如果看到頁面中顯示“It works!”字樣,則代表Apache驗證通過。如果網站的index尾碼是PHP格式的,則要修改httpd.conf設定檔(/usr/local/apache2/conf),在DirectoryIndex增加 index.php。
## DirectoryIndex: sets the file that Apache will serve if a directory# is requested.#<IfModule dir_module> DirectoryIndex index.html index.php</IfModule>