Changing the Symfony2 web directory

By Web Design

WASHINGTON, DC WordPress development company – Herndon, Virginia

For a recent project, a client needed a custom application built, and we determined that it went beyond the scope covered by a CMS like WordPress or Drupal; instead we chose to use the Symfony2 PHP Web Framework, which is well known for its stability, security, and OOP design, and for adhering to good coding practices.

When it came time to deploy the application, we had to determine where it would need to reside on the server, and to do that we needed to know how the client wanted to be able to access it, either in the root of a domain or subdomain, or in a subdirectory within a domain. Of course, the first option would have been as simple as copying in the files and either changing the Document Root to the ‘web’ directory or else renaming the web directory to the folder already defined as the Document Root.

However, the client chose the latter; they wanted to have the application reside in a subdirectory beneath the main website. I did a little bit of research and determined that it is actually easier than it sounds. Symfony itself doesn’t actually know what the ‘web’ directory is called. Because the file that is accessed by the user is the ‘app.php’ file within the ‘web’ directory, Symfony just relies on a relative path from there to the other directories.

So I was able to easily split up the directories so that all but the ‘web’ directory were outside of the user-accessible Document Root, and then I renamed the ‘web’ directory to the name chosen by the client, and finally I changed the paths in ‘app.php’ (in two places) so that they would correctly point to the other directories.

Note that any paths in your controllers or other objects may need to be adjusted accordingly as well. However, the simple act of separating the frontend files and the backend files is as simple as I described above.

Tagged under: