PhpStorm 2024.1 Help

Content root

In PhpStorm, content is a collection of files with which you are currently working, possibly organized in a hierarchy of subfolders. The folder that is the highest in this hierarchy is called the content root folder or content root for short. A project has at least one content root folder, which by default is the project folder itself.

Add a content root

Having several content roots enables you to work with files from several directories that do not have a common immediate parent. This is helpful when you use static contents, for example, icons. You can just save them all in a folder and then specify this folder as an extra content root in several projects.

  1. In the Settings dialog (Ctrl+Alt+S) , click Directories.

  2. On the Directories page, click Add Content RootAdd Content Root and set the path to the desired directory.

    Add, manage, and delete content roots

Content root types

Within the content root, PhpStorm can distinguish between the folders that contain source code, folders that contain tests and resources, folders with third-party libraries, and the folders that should be excluded from indexing. The available root categories are:

  • Source

    This is the root for PHP namespaces used in your project.

    Based on this setting, PhpStorm suggests the proper folder name when you want to create a new namespace under another parent namespace during creation or moving of a PHP class, that is, when you are actually creating or moving a PHP class to a non-existing namespace under another parent namespace. If no Sources folder is specified, you will have to type the proper folder manually.

  • Tests

    PhpStorm considers the contents of the Tests folder to be unit tests.

  •   Resource Root

    Files and subfolders in a Resource Root folder can be referenced relative to this folder instead of specifying full paths to them.

  • the Excluded root icon Excluded

    Excluded folders are not involved in indexing, and therefore they are ignored during search, parsing, watching, and other operations.

    Usually, one would like to exclude temporary build folders, generated output, logs, and other project output. Excluding the unnecessary paths is a good way to significantly improve performance.

  • Library root icon Library

    Library folders are a specific case of excluded roots that contain libraries as PHP include paths and are therefore indexed. For more information, refer to PHP library roots.

Mark directories with a root type

When you open a project, PhpStorm sets the Source root the Source root icon, Tests root the Tests root icon, and Library root folders automatically based on the contents of your composer.json file. You can also mark and unmark folders with a root type manually in the project settings:

  1. In the Settings dialog (Ctrl+Alt+S) , select Directories.

  2. On the Directories page, click the desired content root in the right-hand pane. Directories under this content root are displayed as a tree view in the left-hand pane.

  3. Select the directory and use its context menu or the Mark as toolbar to mark it as one of the available root types.

    Mark directory with root category

Mark directories in the Project tool window

  1. Right-click the desired directory in the Project tool window.

  2. From the context menu, point to Mark Directory As node.

  3. Choose Mark as <directory status>.

Last modified: 17 April 2024