Apache版本以2.4為例
1、修改httpd.conf
把下面第二行的#去掉,啟動虛擬主機設定
# Virtual hosts # Include conf/extra/httpd-vhosts.conf
2、設定httpd-vhost.conf
這裡使用了8081端口,配置了兩個虛擬主機,DocumentRoot不能含有中文目錄
<VirtualHost *:8081> ServerName localhost DirectoryIndex index.php DocumentRoot "D:\Work\php\Apache24\htdocs" <Directory "D:\Work\php\Apache24\htdocs"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:8081> ServerName www.aa.com DirectoryIndex index.php DocumentRoot "E:\php\PhpProjectBase" <Directory "E:\php\PhpProjectBase"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
3、etc/hosts設定
127.0.0.1 localhost127.0.0.1 www.aa.com
4、重啟Apache服務
如果此時虛擬主機仍不能訪問,設定httpd.conf中下列項
<Directory /> AllowOverride none #Require all denied</Directory>
以上是關於phpApache設定虛擬主機的詳細內容。更多資訊請關注PHP中文網其他相關文章!