0

I'm learning Symfony right now. I created 2 Symfony projects with 2 different domains. Nevertheless, my second domain points to the first, and don't know why.

I'm following this tutorial, the famous jobeet: http://www.symfony-project.org/jobeet/1 ... rine/en/01

Notice my configurations:

My /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>

Notice that I'm listening to 8081 port in the tutorial domain. I tried the permutation of VirtualHost 127.0.0.1:80 and VirtualHost 127.0.0.1:81. Neither worked. (really don't know which use)

My /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

After that I restarted Apache.

Now, when I do: http://www.jobeet.com.localhost/frontend_dev.php/ I go to my Jobeet tutorial things, BUT when I do http://www.tutorial.com.localhost/frontend_dev.php/ I ALSO go to the Jobeet page. I should go to the one containing the tutorial part.

Why is not working??!

Vlad Jula-Nedelcu
  • 1,681
  • 11
  • 17
  • it sounds more like a webserver (apache) problem.... – Vlad Jula-Nedelcu Feb 01 '12 at 19:14
  • It was my mistake. I will post after 8 hours -because my reputation in less than 100- So, for tomorrow, I will put the answer. Short one: NameVirtualHost must be called ONE time, like NameVirtualHost:80 –  Feb 01 '12 at 20:52
  • May I suggest, if you're learning Symfony for the first time, that you learn Symfony2 instead. Symfony 1 will no longer be supported as of a year from now. – lonesomeday Feb 02 '12 at 13:30
  • Thank you! In fact I'm learning both! Never the less, the projects of the company I'm working for are in 1.4. They do not want to migrate to 2 because the fears of breaking the system (is HUGE, and gives services to half a continent). So, I have no option right now :/ –  Feb 02 '12 at 14:05

2 Answers2

1

Well:

In /etc/apache2/httpd.conf is enough with:

 NameVirtualHost 127.0.0.1:80

I repeated this command when creating the other ServeName (tutorial). Maybe that was the conflict. I left all in port 80. Now it resolve right.

So, this is the final /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>

The /etc/hosts (or in /etc/apache2/sites-avaiable for debian) is the same.

I can access to www.jobeet.com.localhost and www.tutorial.com.localhost

Sorry, it was my misconfiguration.

0
  1. A common mistake is to have disabled the virtual host module for apache, for enable it try: sudo a2enmod virtualhost

  2. put your vhost conf in /etc/apache2/sites-available/name-file-with-vhost-conf

  3. all virtual host must be enabled, with sudo a2ensite name-file-with-vhost-conf

  4. apache2 must be reloaded sudo service apache2 reload

you can try this github/rokemaster/virtual_hosts is all steps in one script

rkmax
  • 17,633
  • 23
  • 91
  • 176
  • there would be a difference doing it in the `/sites-aviables rather` than in the `/etc/hosts`? –  Feb 02 '12 at 14:07
  • `/sites-available/`is a place where apache read configuration about vhost and `/etc/hosts` file is a static DNS for the OS and is necesary for the properly function of virtual host – rkmax Feb 03 '12 at 04:59