Thursday, June 28, 2012

Symfony2: The above URL assumes that localhost points to the web directory of your new Symfony2 project

Reading the Symfony2 book, in the "Creating Pages in Symfony2" section in the "The "Hello Symfony!" Page" subtitle. I found an advise:

"The tutorial assumes that you've already downloaded Symfony2 and configured your webserver. The above URL assumes that localhost points to the web directory of your new Symfony2 project. For detailed information on this process, see the documentation on the web server you are using. Here's the relevant documentation page for some web server you might be using:


 - For Apache HTTP Server, refer to Apache's DirectoryIndex documentation.
 - For Nginx, refer to Nginx HttpCoreModule location documentation."

The apache issue consist in being able to access to the same page ussing two different urls, one is the default:

http://localhost/Symfony/web/app_dev.php/hello/Symfony

and the other is the page that the tutorial assumes you have already configured. Note that "Symfony/web"  is missing:


http://localhost/app_dev.php/hello/Symfony

Your can get that configuration going to the file : "apache_installation_dir\conf\extra\httpd-vhosts.conf" and setting the following configuration:



NameVirtualHost *:8082
Listen 127.0.0.1:8082


<VirtualHost *:8082>
  ServerName local.myproject
  DocumentRoot "E:/Programs/windows7/xampp-win32-1.7.4-VC6/xampp/htdocs/Symfony/web"
  DirectoryIndex index.php
  <Directory "E:/Programs/windows7/xampp-win32-1.7.4-VC6/xampp/htdocs/Symfony/web">
    AllowOverride All
    Allow from All
  </Directory>


  Alias /sf "E:/Programs/windows7/xampp-win32-1.7.4-VC6/xampp/htdocs/Symfony/lib/vendor/symfony/data/web/sf"
  <Directory "E:/Programs/windows7/xampp-win32-1.7.4-VC6/xampp/htdocs/Symfony/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Note: be aware of changing the routes and changing the port. In my case I preferred to use 8082 port so I could access to the url http://localhost:8082/app_dev.php/hello/Symfony

No comments: