Symfony:许多不同领域的许多项目

时间:2012-02-01 14:26:17

标签: php apache symfony1 virtual-hosts

我正在学习Symfony。我用2个不同的域创建了2个Symfony项目。然而,我的第二个域指向第一个域,并且不知道为什么。

我正在按照本教程,着名的工作机会:http://www.symfony-project.org/jobeet/1 ... rine / en / 01

请注意我的配置:

我的/etc/apache2/httpd.conf

ServerName localhost

#From the symfony tutorial "jobeet"
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080

# This is the configuration for your project
<VirtualHost 127.0.0.1:80>
 ServerName www.jobeet.com.localhost
 DocumentRoot "/home/lola/sfprojects/jobeet/web"
 DirectoryIndex index.php
 <Directory "/home/lola/sfprojects/jobeet/web">
    AllowOverride All
    Allow from All
 </Directory>
 Alias /sf /home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf
<Directory "/home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf">
    AllowOverride All
   Allow from All
 </Directory>
</VirtualHost>


#Another symfony tutorial
NameVirtualHost 127.0.0.1:8081

<VirtualHost 127.0.0.1:80>
ServerName www.tutorial.com.localhost
DocumentRoot "/home/sfprojects/tutorial/web"
  DirectoryIndex index.php
  <Directory "/home/sfprojects/tutorial/web">
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf /home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf
  <Directory "/home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

注意我正在教程域中收听 8081 端口。我尝试了VirtualHost 127.0.0.1的排列: 80 和VirtualHost 127.0.0.1: 81 。都没有奏效。 (真的不知道用哪个)

我的/ etc / hosts:

#From the symfony tutorial
127.0.0.1 www.jobeet.com.localhost

#From ANOTHER symfony tutorial
127.0.0.1 www.tutorial.com.localhost

之后我重启了Apache。

现在,当我这样做时: http://www.jobeet.com.localhost/frontend_dev.php/我进入Jobeet教程,当我http://www.tutorial.com.localhost/frontend_dev.php/ 进入Jobeet页面。我应该去包含教程部分的那个。

为什么正在工作?!

2 个答案:

答案 0 :(得分:1)

好:

在/etc/apache2/httpd.conf中就足够了:

 NameVirtualHost 127.0.0.1:80

我在创建其他 ServeName 教程)时重复了此命令。也许这就是冲突。我把所有人留在了 80 的端口。现在它解决了。

所以,这是最后的/etc/apache2/httpd.conf:

ServerName localhost

NameVirtualHost 127.0.0.1:80

# This is the configuration for your project
<VirtualHost 127.0.0.1:80>
 ServerName www.jobeet.com.localhost
 DocumentRoot "/home/lola/sfprojects/jobeet/web"
 DirectoryIndex index.php
 <Directory "/home/lola/sfprojects/jobeet/web">
    AllowOverride All
    Allow from All
 </Directory>
 Alias /sf /home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf
<Directory "/home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf">
   AllowOverride All
   Allow from All
</Directory>
</VirtualHost>


#Another symfony tutorial
# DO NOT REPEAT NameVirtualHost 127.0.0.1:80 --------> ****HERE: do not repeat this****

<VirtualHost 127.0.0.1:80>
ServerName www.tutorial.com.localhost
DocumentRoot "/home/sfprojects/tutorial/web"
  DirectoryIndex index.php
  <Directory "/home/sfprojects/tutorial/web">
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf /home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf
  <Directory "/home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
 </VirtualHost>

/ etc / hosts(或/ etc / apache2 / sites-avaiable for debian)是一样的。

我可以访问www.jobeet.com.localhost和www.tutorial.com.localhost

抱歉,这是我的错误配置。

答案 1 :(得分:0)

  1. 一个常见的错误是为apache禁用了虚拟主机模块,因此请尝试:sudo a2enmod virtualhost

  2. 将您的vhost conf置于/etc/apache2/sites-available/name-file-with-vhost-conf

  3. 必须使用sudo a2ensite name-file-with-vhost-conf

  4. 启用所有虚拟主机
  5. 必须重新加载apache2 sudo service apache2 reload

  6. 你可以尝试这个github/rokemaster/virtual_hosts是一个脚本中的所有步骤