Root path

Published

Updated

🏠

Set the entry point directory.

The root path, also called document root or web root, is the folder the web server serves public requests from. It holds the index.php that runs for every page. Files outside of it cannot be reached by URL.

About the root path

A request for https://example.com/about ends up in the root path: the web server looks there for a file named about, or hands the request to the index.php in it. Everything above the root path stays private, such as configuration files, the vendor folder and .env. A wrong root path shows as 404 errors on every page.

Plain PHP projects

In a traditional PHP project, the root path is the top level of the code, holding index.php:

www <-- Root path
├── index.php  <-- file to be called
├── css/
├── js/
├── images/
├── includes/
raw

All files are reachable by URL here, including the scripts in includes/.

Frameworks and CMS

Most frameworks keep the code outside the root path and serve only one folder:

www
├── public/ <-- Root path
│   └── index.php <-- file to be called
├── src/
├── vendor/
└── composer.json
raw

The src/ and vendor/ folders are out of reach of the web. Common root paths:

  • public: Laravel, Statamic, Symfony, TYPO3
  • web: Craft CMS, Drupal
  • the top level: Kirby, Grav, October CMS

Root path setting on fortrabbit

The code of an environment sits in /data/www, see directories. The root path setting names the folder inside it, such as public for /data/www/public, without the index file. The software template fills in the root path the software expects, and it can be changed in the environment settings at any time.

All domains of an environment share the root path. To serve different folders per domain, use rewrite rules in .htaccess.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗