一、下載所需軟件包php
根據官網所示,安裝apache2.4.9必須先安裝apr、apr-util、pcre包html
The following requirements exist for building Apache httpd: APR and APR-Util Make sure you have APR and APR-Util already installed on your system. If you don't, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/) and use ./configure's --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util. Perl-Compatible Regular Expressions Library (PCRE) This library is required but not longer bundled with httpd. Download the source code from http://www.pcre.org, or install a Port or Package. If your build system can't find the pcre-config script installed by the PCRE build, point to it using the --with-pcre parameter. On some platforms, you may have to install the corresponding -dev package to allow httpd to build against your installed copy of PCRE.
apr-1.5.1.tar.gz apr-util-1.5.3.tar.gz cd.sh httpd-2.4.9.tar.gz pcre-8.33.zip正則表達式
二、安裝apache
# 解壓縮 tar fvxz apr-1.5.1.tar.gz tar fvxz apr-util-1.5.3.tar.gz tar httpd-2.4.9.tar.gz tar fvxz httpd-2.4.9.tar.gz tar fvxz pcre-8.33.zip unzip pcre-8.33.zip # 編譯安裝apr cd /data/apr-1.5.1 ./configure --prefix=/usr/local/apr make && make install # 編譯安裝apr-util cd ../apr-util-1.5.3 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install # 編譯安裝pcre cd ../pcre-8.33 ./configure --prefix=/usr/local/pcre make && make install # 編譯安裝apache # 安裝以前請確保系統以前預裝的httpd已被卸載 cd ../httpd-2.4.9 # 參數依次是: httpd安裝路徑 httpd配置文件存放路徑 啓用模塊化方式 啓用ssl安全鏈接# 啓用cgi腳本功能 啓用url重寫 啓用服務器壓縮 啓用正則表達式支持 apr安裝路徑 # apr util安裝路徑 啓用經常使用模塊以確保apache正常工做 將多進程模型非靜態化 # 啓用事件異步模型 ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event make && make install
三、錯誤提示安全
安裝openssl依賴關係 便可解決下面問題bash
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
四、啓動&測試服務器
# /usr/local/apache/bin/apachectl startapp
若是成功,能夠中止 Apache 服務器並繼續安裝 PHP:異步
/usr/local/apache2/bin/apachectl stop OR /usr/local/apache/bin/apachectl -k stop(推薦)
五、安裝php5.5.12ide
tar fvxz php-5.5.12.tar.gz ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs make && make install
六、配置php.ini
cp php.ini-development /usr/local/lib/php.ini
七、編輯 httpd.conf 文件以調用 PHP 模塊。LoadModule 達式右邊的路徑必須指向系統中的 PHP 模塊。以上的 make install 命令可能已經完成了這些,但務必要檢查
LoadModule php5_module modules/libphp5.so
八、apache解析php,添加以下內容:
# 讓Apache將擴展名.php 解析成 PHP。爲了不潛在的危險,例如上傳或者建立相似 exploit.php.jpg 的文件並被當作 PHP 執行,咱們再也不使用 Apache 的 AddType 指令來設置。 <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> # 將.php,.php2,.php3,.php4,.php5,.php6,以及.phtml文件都當作PHP來運行 <FilesMatch "\.ph(p[2-6]?|tml)$"> SetHandler application/x-httpd-php </FilesMatch> # .phps 文件由 PHP 源碼過濾器處理,使得其在顯示時能夠高亮源碼 <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> # mod_rewrite也有助於將那些不須要運行的.php文件的源碼高亮顯示,而並不須要將他們改名.phps文件 RewriteEngine On RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]