lamp的安装参考: 安装lamp
apache有三种配置虚拟主机的方法,分别是基于不同的端口,不同的IP,和基于不同的域名,这三种方法分别适合不同的场景,
apache2.2以上建义虚拟主机的配置或是修改都在conf/extra/httpd-vhost.conf 文件里进行。然后去掉httpd.conf 里面的 #Include conf/extra/httpd-vhosts.conf 这一行的注释("#" )
针对apache配置文件的修改,都需要重启apache服务
1.基于相同IP不同Port的虚拟主机
更改虚拟主机配置,例如下:
Listen 80
Listen 8888
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/wordpress/"
ServerName develop.realqi.cn
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:8888>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/cms/wordpress"
ServerName cms.realqi.cn
</VirtualHost>
注意:相关的目录如"wordpress","../cms/wordpress" 必需存在.重启apache,就可生效.
2.基于相同Port不同IP的虚拟主机这种情况适合服务器有多个IP
详细参考:
3.基于域名的虚拟主机的访问,例子如下
NameVirtualHost 10.29.20.22
<VirtualHost www.realqi.cn>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/"
ServerName www.realqi.cn
DirectoryIndex rd.html
</VirtualHost>
<VirtualHost develop.realqi.cn>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/htdocs/wordpress/"
ServerName develop.realqi.cn
DirectoryIndex index.php
</VirtualHost>