準備工作
爲了不影響實驗效果,提前可以把selinux 和iptables 關閉
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# chkconfig ip6tables off
[root@localhost ~]# /etc/init.d/iptables stop
[root@localhost ~]# /etc/init.d/ip6tables stop
[root@localhost ~]# sed -i "s/LINUX=.*/LINUX=disabled/g" /etc/selinux/config
更改完selinux後要想生效需要重啓一下服務器,reboot或者shutdown -r now
apache對php的支持是通過apache的mod_php5模塊來支持的,這點與nginx不同。nginx是通過第三方的fastcgi處理器纔可以對php進行解析.
因爲我在安裝的時候需要依賴包這裏你可以自行安裝一下:
yum install -y gcc gcc-c++ pcre-devel pcre zlib zlib-devel
第一步安裝mysql 5.5
參考(mysql-5.5)
第二步:安裝apache
首先下載httpd-2.4.7.tar.gz源碼包
進入安裝目錄,依次執行下面命令:
# cd /usr/local/src/
解壓源碼包
# tar zxvf httpd-2.4.7
進入安裝目錄
# cd httpd-2.4.7
配置apache安裝信息, 配置安裝後目錄,模塊動態配置,允許重寫重配置
# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
需要下載apr和apr-utils並解壓到 ./srclib/ 目錄下, 再進行編譯。2.4版本要求apr1.4以上版本
# tar zxvf apr-util-1.4.1.tar.gz
# tar zxvf apr-1.4.6.tar.gz
# cp -r apr-1.4.6 httpd-2.4.7/srclib/apr
# cp -r apr-util-1.4.1 httpd-2.4.7/srclib/apr-util
# cd httpd-2.4.7
# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
報錯:
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.4.7/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
解決方法:需要安裝gcc
# yum install -y gcc
[root@pxe httpd-2.4.20]# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
報錯:
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解決方法:需要安裝pcre
# yum search pcre
# yum install -y pcre-devel pcre
[root@pxe httpd-2.4.20]# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
報錯:
checking for zlib location... not found
checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
解決方法:需要安裝zlib
# yum search zlib
# yum install -y zlib zlib-devel
# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
# make
# make install && echo $?
第二步:配置apache
修改httpd.conf文件
# vim /usr/local/apache2/conf/httpd.conf
//ServerName 修改主機名稱,若無dns,則用IP替代
ServerName 192.168.244.144:80
//DocumentRoot 修改文檔路徑,就是要放置目標網頁的地方
DocumentRoot "/usr/local/apache2//htdocs"
//DirectoryIndex 修改默認的首頁名稱
DirectoryIndex index.html index.php
開啓apache服務
# /usr/local/apache2/bin/apachectl start
# vi /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/apache2/bin/
[root@pxe httpd-2.4.20]# . /etc/profile.d/path.sh
[root@pxe httpd-2.4.20]# apachectl stop
[root@pxe httpd-2.4.20]# apachectl start
[root@pxe src]# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.local
開機啓動
測試一下網頁
更改一下網頁的內容
ok 這裏apache就按照完畢了
第三步 安裝php
參考( php 安裝 )
網頁測試
Apache主配置文件爲:/usr/local/apache2/conf/httpd.conf
更改3個地方
第一 添加 AddType application/x-httpd-php .php
第二 添加 index.php
第三 註銷掉# AllowOverride none,把Require all denied 改成 Require all granted
# vim /usr/local/apache2/conf/httpd.conf
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php (定義apache解析PHP)
#
#
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
#
<Directory />
# AllowOverride none
Require all granted
</Directory>