工作需要缀遍,得配一個(gè) apache+php 的本地環(huán)境,選用的是 apache2.4 和 php5.6
apache 配置
- 打開 conf/httpd.conf 文件个盆,找到如下內(nèi)容并去掉第二行的#號(hào):
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
意思是讓 httpd.conf 文件包含 httpd-vhosts.conf 這個(gè)配置文件 - 將 *ServerName :80 注釋掉 。在 httpd-vhosts.conf 文件中會(huì)配置。
- 將 DocumentRoot "${SRVROOT}/htdocs" 注釋掉拌牲。在 httpd-vhosts.conf 文件中會(huì)配置俱饿。
- 將 <Directory "${SRVROOT}/htdocs">......</Directory> 標(biāo)簽和其內(nèi)部的選項(xiàng)都注釋掉。即:
# <Directory "${SRVROOT}/htdocs">
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
# </Directory> - 打開 conf/extra/httpd-vhosts.conf 文件塌忽,注釋掉以下內(nèi)容:
# <VirtualHost default:80>
# DocumentRoot "${SRVROOT}/htdocs"
# ServerName www.example.com:80
# </VirtualHost>
然后在最下面添加以下配置:
<VirtualHost *:80>
ServerAdmin admin@test.cc
DocumentRoot "d:/www"
ServerName test.cc
DirectoryIndex index.html index.htm index.php
ErrorLog "logs/test.cc-error.log"
CustomLog "logs/test.cc-access.log" common
# apache2.4下必須加目錄權(quán)限的設(shè)置:
<Directory "d:/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted # 需注意拍埠,這段是apache2.4中的關(guān)鍵,與2.2不同
</Directory>
</VirtualHost>
注: VirtualHost 是有順序的土居,排在最前的是我們默認(rèn)的網(wǎng)站域名枣购。如果沒有注釋掉 httpd.conf 中的 DocumentRoot 和 ServerName,那么第一個(gè)虛擬主機(jī)的這兩個(gè)配置都必須與 httpd.conf 中的一樣擦耀,包括端口棉圈。所以建議注釋掉 httpd.conf 中的標(biāo)簽。 - 配置完成保存后重啟 apache 即可
php配置
- 把下載好的文件解壓在 php 目錄眷蜓,
- 在apache配置文件(conf/httpd.conf)中最后加上以下代碼:
# php5 support
LoadModule php5_module "d:/webserver/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "d:/webserver/php/"
注意: LoadModule 的路徑文件必須存在分瘾,如果在 php 目錄沒有這個(gè)文件,說明下載的 php 文件不對吁系,請確保下載的是 VC11 x86 Thread Safe 或 VC11 x64 Thread Safe 版本 - 修改 php 配置文件(php.ini)德召,將根目錄下的 php.ini-development 改為 php.ini 作為配置文件即可
- 開啟相應(yīng)的庫,只需要去除前面的分號(hào)(注釋)即可
extension = php_curl.dll
extension = php_gd2.dll
extension = php_mbstring.dll
extension = php_mysql.dll
extension = php_xmlrpc.dll - 設(shè)置相應(yīng)的時(shí)區(qū)
date.timezone = Asia/Shanghai - 配置完成汽纤,重啟apache使其生效上岗,在根目錄新建一個(gè) index.php 文件,并輸入以下內(nèi)容
<?php
phpinfo();
?> - 在瀏覽器中輸入 http://localhost 查看