虚拟主机上的 Symfony 2 [英] Symfony 2 on virtual hosts
问题描述
我在使用 Symfony 2 时遇到问题.我想在 Windows Vista PC 上拥有虚拟主机,这样我就可以像这样myapp.local.com
访问我的 Symfony 应用程序.我尝试过的:
I have a problem here with Symfony 2. I want to have virtual host on Windows Vista PC, so I can access my Symfony application like this myapp.local.com
.
What I have tried:
我将这些行添加到主机文件
I added these lines to hosts file
127.0.0.1 local.com
127.0.0.1 myapp.local.com
这些我添加到 apache httpd-vhosts.conf
These I added to apache httpd-vhosts.conf
< VirtualHost myapp.local.com:80 >
DocumentRoot "d:/data/www/myapp/web"
ServerName myapp.local.com
Alias /sf /$sf_symfony_data_dir/web/sf
< Directory "/$sf_symfony_data_dir/web/sf" >
AllowOverride All
Allow from All
< /Directory >
< Directory "d:/data/www/myapp/web" >
AllowOverride All
Allow from All
< /Directory >
< /VirtualHost >
但是当我在浏览器中编写 myapp.local.com
时,它带来了我的 www
目录的索引.我做错了什么?
but when I write myapp.local.com
in my browser, it brings the index of my www
directory. What am I doing wrong?
推荐答案
您正在使用为 Symfony 1 提议的虚拟主机配置.
You are using the virtualhost configuration proposed for Symfony 1.
我的 Symfony2 在 linux 下的虚拟主机如下所示:
My virtualhost for Symfony2 under linux looks like this:
<VirtualHost *:80>
ServerName www.domain.com.localhost
ServerAlias domain.com.localhost
ServerAdmin webmaster@localhost
DocumentRoot /home/user/www/project/web
<Directory /home/user/www/project/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
试试这个(适应你在 windows 中的配置),重启 Apache,然后再次尝试访问 URL.
Try this (adapted to your config in windows), restart Apache, and try accessing the URL again.
您可以在此食谱条目上找到有关 Symfony2 虚拟主机的更多信息.
You will find more informations on Symfony2 virtual hosts on this cookbook entry.
这篇关于虚拟主机上的 Symfony 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!