Setting the DocumentRoot for Rails and CakePHP Applications

Published on and tagged with apache  cakephp  ruby on rails

One of the first steps when I start a new project is to define a virtual host for the project because I prefer urls in the format http://myproject.localhost over http://localhost/myproject on my local development machine.

As I currently use Apache2 for both, Rails (using mod_rails) and CakePHP, a virtual host entry in /etc/apache2/sites-available/default looks like:

<VirtualHost *:80>
    ServerName myproject.localhost
    DocumentRoot /<path_to_document_root_of_myproject>

If you have a CakePHP project, the path to the DocumentRoot is usually something like:

DocumentRoot /<path_to_the_projects>/myproject/app/webroot

With Rails, on the other hand, the path to the DocumentRoot is something like:

DocumentRoot /<path_to_the_projects>/myproject/public

After a restart of Apache you should get the welcome screen of the respective framework if you go to http://myproject.localhost (assuming you already “baked” the project structure and added an entry to the /etc/hosts file).

8 comments baked

Bake a comment

(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License