apache2.4以上版本配置虚拟主机
1、在linux下使用任意编辑器比如vim或者nano等命令行编辑即可,输入以下命令:sudo nano /etc/hosts修改hosts,将需要添加的域名和127.0.0.1绑定配置如下:127.0.0.1 yii2 我使用的是yii2这个域名,可以是yii.web 或者其它保存即可
2、配置/etc/httpd/conf/httpd.conf (由于操作系统不同可能会有不同的路悄钸碌灵径,此处使用的是archlinux桌面环境)去鼓饫废希掉vittual hosts 下面的 Include conf/extra/httpd-vhosts.conf 前面的注释在httpd.conf里搜索AllowOverride 将后面的参数更改为All即可然后保存
3、修改 /etc/httpd/conf/extra/httpd-vhosts.conf增加下面内容 ,2.4以后这部分内容很重要&造婷用痃lt;Directory "/srv/http/"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted</Directory>/srv/http/是根目录,视情况而定,在ubuntu或者fedora以及cent os 里可能是/var/www/然后在下面增加:<VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/srv/http/yii2/web" ServerName yii2 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log" CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common</VirtualHost>ServerName 以及DocumentRoot这一部分一定要写对!其它可以默认即可!
4、重启apache,在archlinux里的命令是systemctl restart httpd.service ubuntu及其它发行版百度搜索一下!
5、在浏览器地址栏输入http://yii2 打开,如跳转到你的网站主页面,说明配置成功