The definitive guide of Symfony 1.0

3.4. Configuring the Web Server

The scripts of the web/ directory are the entry points to the application. To be able to access them from the Internet, the web server must be configured. In your development server, as well as in a professional hosting solution, you probably have access to the Apache configuration and you can set up a virtual host. On a shared-host server, you probably have access only to an .htaccess file.

3.4.1. Setting Up a Virtual Host

Listing 3-1 is an example of Apache configuration, where a new virtual host is added in the httpd.conf file.

Listing 3-1 - Sample Apache Configuration, in apache/conf/httpd.conf

<VirtualHost *:80>
  ServerName myapp.example.com
  DocumentRoot "/home/steve/myproject/web"
  DirectoryIndex index.php
  Alias /sf /$sf_symfony_data_dir/web/sf
  <Directory "/$sf_symfony_data_dir/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
  <Directory "/home/steve/myproject/web">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

In the configuration in Listing 3-1, the $sf_symfony_data_dir placeholder must be replaced by the actual path. For example, for a PEAR installation in *nix, you should type something like this:

Alias /sf /usr/local/lib/php/data/symfony/web/sf

Note The alias to the web/sf/ directory is not mandatory. It allows Apache to find images, style sheets, and JavaScript files for the web debug toolbar, the admin generator, the default symfony pages, and the Ajax support. An alternative to this alias would be to create a symbolic link (symlink) or copy the /path/to/symfony/data/web/sf/ directory to myproject/web/sf/.

Restart Apache, and that's it. Your newly created application can now be called and viewed through a standard web browser at the following URL:

http://localhost/myapp_dev.php/

You should see a congratulations page similar to the one shown earlier in Figure 3-1.

[side URL Rewriting] Symfony uses URL rewriting to display "smart URLs"--meaningful locations that display well on search engines and hide all the technical data from the user. You will learn more about this feature, called routing, in Chapter 9.

If your version of Apache is not compiled with the mod_rewrite module, check that you have the mod_rewrite Dynamic Shared Object (DSO) installed and the following lines in your httpd.conf:

AddModule mod_rewrite.c
LoadModule rewrite_module modules/mod_rewrite.so

For Internet Information Services (IIS), you will need isapi/rewrite installed and running. Check the symfony online documentation for a detailed IIS installation guide. code.bb77443db1c125912a476e32420a30f108711b79php $sf_root_dir = sfConfig::get('sf_root_dir'); sfConfig::add(array( 'sf_web_dir_name' => $sf_web_dir_name = 'www', 'sf_web_dir' => $sf_root_dir.DIRECTORY_SEPARATOR.$sf_web_dir_name, 'sf_upload_dir' => $sf_root_dir.DIRECTORY_SEPARATOR.$sf_web_dir_name.DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir_name'), )); code.f28724b373f6a914807fa158be98a60c218005c2 Options +FollowSymLinks +ExecCGI

RewriteEngine On

# we skip all files with .something RewriteCond %{REQUEST_URI} ..+$ RewriteCond %{REQUEST_URI} !.html$ RewriteRule .* - [L]

# we check if the .html version is here (caching) RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller RewriteRule ^(.*)$ index.php [QSA,L]