change Symfony Web directory path

Because we love the Symfony Open-source PHP Web Framework, we have developed multiple applications with it. For those wo are not familiar with Symfony, take a look at their website for more information.
The scripts of the web directory are the entry points to the application. To be able to access them from the Internet or any given webpage, the web server must be correctly 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 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<VirtualHost *:80>
 ServerName www.domain.com
 DocumentRoot "/home/diba/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/diba/myproject/web">
   AllowOverride All
   Allow from All
 Directory>
VirtualHost>
Setting up an web application on a shared host is a little bit trickier, since
the host usually has a specific directory layout that you can't change, except when you have a webserver at your disposal of course. Let's imagine that your shared host requires that the web folder is named public_html instead of web, and that it doesn't give you access to the httpd.conf file, but only to an .htaccess file in the web folder.
In directadmin you have the option to change/update the virtualhost of a certain domain. The downside of this solution is that whenever you change data related to this domain (safe mode, open basedir, add new domain), the virtualhost will get rewritten, causing your changed to be lost. There is a solution for this, although it requires a small symfony hack.
In a symfony project, every path to a directory is configurable. You can
still rename the web directory to public_html and
have the application take it into account by changing the
configuration. These lines are to be added to
the end of the application config.php file:

1
2
3
4
5
6
$sf_root_dir = sfConfig::get('sf_root_dir');
sfConfig::add(array(
 'sf_web_dir_name' => $sf_web_dir_name = 'public_html',
 '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'),
));
And that's it! Your webapplication will now get it's public content from public_html, and the Symfony framework is smart enough to know that all the other files are one dir above this one. All hail to Sensiolabs!
P.S. If you are doing this because of the directadmin limitations, there is a post you should read.

No comments:

Post a Comment