diff --git a/phpBB/common.php b/phpBB/common.php
index fc309892d6..b9ba37935d 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -51,7 +51,8 @@ if (!defined('PHPBB_INSTALLED'))
 		new phpbb_symfony_request(
 			new phpbb_request()
 		),
-		$phpbb_root_path
+		$phpbb_root_path,
+		$phpEx
 	);
 	$script_path = $phpbb_filesystem->clean_path($script_path);
 
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index a9c819fe9a..9231138e1c 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -172,6 +172,8 @@ services:
         arguments:
             - @symfony_request
             - %core.root_path%
+            - %core.php_ext%
+            - %core.adm_relative_path%
 
     groupposition.legend:
         class: phpbb_groupposition_legend
@@ -263,13 +265,11 @@ services:
     template:
         class: phpbb_template_twig
         arguments:
-            - %core.root_path%
-            - %core.php_ext%
+            - @filesystem
             - @config
             - @user
             - @template_context
             - @ext.manager
-            - %core.adm_relative_path%
 
     template_context:
         class: phpbb_template_context
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php
index 2fa6a8b099..0c567dd012 100644
--- a/phpBB/includes/bbcode.php
+++ b/phpBB/includes/bbcode.php
@@ -126,13 +126,13 @@ class bbcode
 	*/
 	function bbcode_cache_init()
 	{
-		global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager;
+		global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager, $phpbb_filesystem;
 
 		if (empty($this->template_filename))
 		{
 			$this->template_bitfield = new bitfield($user->style['bbcode_bitfield']);
 
-			$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
+			$template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
 			$template->set_style();
 			$template->set_filenames(array('bbcode.html' => 'bbcode.html'));
 			$this->template_filename = $template->get_source_file_for_handle('bbcode.html');
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index cf9f71244b..b28e808606 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1070,7 +1070,14 @@ function phpbb_clean_path($path)
 			global $phpbb_root_path, $phpEx;
 			require($phpbb_root_path . 'includes/filesystem.' . $phpEx);
 		}
-		$phpbb_filesystem = new phpbb_filesystem();
+
+		$phpbb_filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_request()
+			),
+			$phpbb_root_path,
+			$phpEx
+		);
 	}
 
 	return $phpbb_filesystem->clean_path($path);
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 3bfc1a44f0..13e25b4f5e 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -626,14 +626,14 @@ class messenger
 	*/
 	protected function setup_template()
 	{
-		global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager;
+		global $config, $phpbb_filesystem, $user, $phpbb_extension_manager;
 
 		if ($this->template instanceof phpbb_template)
 		{
 			return;
 		}
 
-		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
+		$this->template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
 	}
 
 	/**
diff --git a/phpBB/install/index.php b/phpBB/install/index.php
index ec9aa5f32a..fbc47872c8 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -244,7 +244,8 @@ $config = new phpbb_config(array(
 	'load_tplcompile'	=> '1'
 ));
 
-$template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());
+$phpbb_filesystem = $phpbb_container->get('filesystem');
+$template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context());
 $paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style');
 $paths = array_filter($paths, 'is_dir');
 $template->set_custom_style('adm', $paths);
diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php
index e6c36375af..433fa9a62b 100644
--- a/phpBB/phpbb/filesystem.php
+++ b/phpBB/phpbb/filesystem.php
@@ -27,6 +27,12 @@ class phpbb_filesystem
 	/** @var string */
 	protected $phpbb_root_path;
 
+	/** @var string */
+	protected $adm_relative_path;
+
+	/** @var string */
+	protected $php_ext;
+
 	/** @var string */
 	protected $web_root_path;
 
@@ -34,12 +40,15 @@ class phpbb_filesystem
 	* Constructor
 	*
 	* @param phpbb_symfony_request $symfony_request
-	* @param string $phpbb_root_path
+	* @param string $phpbb_root_path Relative path to phpBB root
+	* @param string $php_ext PHP extension (php)
 	*/
-	public function __construct(phpbb_symfony_request $symfony_request, $phpbb_root_path)
+	public function __construct(phpbb_symfony_request $symfony_request, $phpbb_root_path, $php_ext, $adm_relative_path = null)
 	{
 		$this->symfony_request = $symfony_request;
 		$this->phpbb_root_path = $phpbb_root_path;
+		$this->php_ext = $php_ext;
+		$this->adm_relative_path = $adm_relative_path;
 	}
 
 	/**
@@ -52,6 +61,26 @@ class phpbb_filesystem
 		return $this->phpbb_root_path;
 	}
 
+	/**
+	* Get the adm root path
+	*
+	* @return string
+	*/
+	public function get_adm_relative_path()
+	{
+		return $this->adm_relative_path;
+	}
+
+	/**
+	* Get the php extension
+	*
+	* @return string
+	*/
+	public function get_php_ext()
+	{
+		return $this->php_ext;
+	}
+
 	/**
 	* Update a path to the correct relative root path
 	*
diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php
index 9a40dc2b15..612519db69 100644
--- a/phpBB/phpbb/template/twig/environment.php
+++ b/phpBB/phpbb/template/twig/environment.php
@@ -23,9 +23,15 @@ class phpbb_template_twig_environment extends Twig_Environment
 	/** @var phpbb_config */
 	protected $phpbb_config;
 
+	/** @var phpbb_filesystem */
+	protected $phpbb_filesystem;
+
 	/** @var string */
 	protected $phpbb_root_path;
 
+	/** @var string */
+	protected $web_root_path;
+
 	/** @var array **/
 	protected $namespace_look_up_order = array('__main__');
 
@@ -38,11 +44,14 @@ class phpbb_template_twig_environment extends Twig_Environment
 	* @param Twig_LoaderInterface $loader
 	* @param array $options Array of options to pass to Twig
 	*/
-	public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array())
+	public function __construct($phpbb_config, $phpbb_extensions, phpbb_filesystem $phpbb_filesystem, Twig_LoaderInterface $loader = null, $options = array())
 	{
 		$this->phpbb_config = $phpbb_config;
 		$this->phpbb_extensions = $phpbb_extensions;
-		$this->phpbb_root_path = $phpbb_root_path;
+
+		$this->phpbb_filesystem = $phpbb_filesystem;
+		$this->phpbb_root_path = $this->phpbb_filesystem->get_phpbb_root_path();
+		$this->web_root_path = $this->phpbb_filesystem->get_web_root_path();
 
 		return parent::__construct($loader, $options);
 	}
@@ -79,6 +88,26 @@ class phpbb_template_twig_environment extends Twig_Environment
 		return $this->phpbb_root_path;
 	}
 
+	/**
+	* Get the web root path
+	*
+	* @return string
+	*/
+	public function get_web_root_path()
+	{
+		return $this->web_root_path;
+	}
+
+	/**
+	* Get the phpbb_filesystem object
+	*
+	* @return phpbb_filesystem
+	*/
+	public function get_filesystem()
+	{
+		return $this->phpbb_filesystem;
+	}
+
 	/**
 	* Get the namespace look up order
 	*
diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php
index 0808e2b10e..2dcd2003a3 100644
--- a/phpBB/phpbb/template/twig/node/includeasset.php
+++ b/phpBB/phpbb/template/twig/node/includeasset.php
@@ -37,7 +37,7 @@ abstract class phpbb_template_twig_node_includeasset extends Twig_Node
 			->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
 			->indent()
 				->write("\$asset_path = \$asset->get_path();")
-				->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n")
+				->write("\$local_file = \$this->getEnvironment()->get_web_root_path() . \$asset_path;\n")
 				->write("if (!file_exists(\$local_file)) {\n")
 				->indent()
 					->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n")
diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php
index 5746cc64a3..3aa063ffc6 100644
--- a/phpBB/phpbb/template/twig/twig.php
+++ b/phpBB/phpbb/template/twig/twig.php
@@ -30,6 +30,12 @@ class phpbb_template_twig extends phpbb_template_base
 	*/
 	private $cachepath = '';
 
+	/**
+	* phpBB filesystem
+	* @var phpbb_filesystem
+	*/
+	protected $phpbb_filesystem;
+
 	/**
 	* phpBB root path
 	* @var string
@@ -71,24 +77,23 @@ class phpbb_template_twig extends phpbb_template_base
 	/**
 	* Constructor.
 	*
-	* @param string $phpbb_root_path phpBB root path
-	* @param string $php_ext php extension (typically 'php')
+	* @param phpbb_filesystem $phpbb_filesystem
 	* @param phpbb_config $config
 	* @param phpbb_user $user
 	* @param phpbb_template_context $context template context
 	* @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked
-	* @param string $adm_relative_path relative path to adm directory
 	*/
-	public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null, $adm_relative_path = null)
+	public function __construct(phpbb_filesystem $phpbb_filesystem, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null)
 	{
-		$this->phpbb_root_path = $phpbb_root_path;
-		$this->php_ext = $php_ext;
+		$this->phpbb_filesystem = $phpbb_filesystem;
+		$this->phpbb_root_path = $phpbb_filesystem->get_phpbb_root_path();
+		$this->php_ext = $phpbb_filesystem->get_php_ext();
 		$this->config = $config;
 		$this->user = $user;
 		$this->context = $context;
 		$this->extension_manager = $extension_manager;
 
-		$this->cachepath = $phpbb_root_path . 'cache/twig/';
+		$this->cachepath = $this->phpbb_root_path . 'cache/twig/';
 
 		// Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
 		$loader = new phpbb_template_twig_loader('');
@@ -96,7 +101,7 @@ class phpbb_template_twig extends phpbb_template_base
 		$this->twig = new phpbb_template_twig_environment(
 			$this->config,
 			($this->extension_manager) ? $this->extension_manager->all_enabled() : array(),
-			$this->phpbb_root_path,
+			$this->phpbb_filesystem,
 			$loader,
 			array(
 				'cache'			=> (defined('IN_INSTALL')) ? false : $this->cachepath,
@@ -118,9 +123,9 @@ class phpbb_template_twig extends phpbb_template_base
 		$this->twig->setLexer($lexer);
 
 		// Add admin namespace
-		if ($adm_relative_path !== null && is_dir($this->phpbb_root_path . $adm_relative_path . 'style/'))
+		if ($this->phpbb_filesystem->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/'))
 		{
-			$this->twig->getLoader()->setPaths($this->phpbb_root_path . $adm_relative_path . 'style/', 'admin');
+			$this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/', 'admin');
 		}
 	}
 
diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php
index da90947bb5..2dd7269caa 100644
--- a/tests/controller/helper_url_test.php
+++ b/tests/controller/helper_url_test.php
@@ -49,7 +49,14 @@ class phpbb_controller_helper_url_test extends phpbb_test_case
 
 		$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
 		$this->user = $this->getMock('phpbb_user');
-		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
+		$phpbb_filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_mock_request()
+			),
+			$phpbb_root_path,
+			$phpEx
+		);
+		$this->template = new phpbb_template_twig($phpbb_filesystem, $config, $this->user, new phpbb_template_context());
 
 		// We don't use mod_rewrite in these tests
 		$config = new phpbb_config(array('enable_mod_rewrite' => '0'));
@@ -94,7 +101,14 @@ class phpbb_controller_helper_url_test extends phpbb_test_case
 
 		$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
 		$this->user = $this->getMock('phpbb_user');
-		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
+				$phpbb_filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_mock_request()
+			),
+			$phpbb_root_path,
+			$phpEx
+		);
+		$this->template = new phpbb_template_twig($phpbb_filesystem, $config, $this->user, new phpbb_template_context());
 
 		$config = new phpbb_config(array('enable_mod_rewrite' => '1'));
 		$helper = new phpbb_controller_helper($this->template, $this->user, $config, '', 'php');
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 5f0818d568..d722439b3f 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -63,7 +63,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
 				new phpbb_symfony_request(
 					new phpbb_mock_request()
 				),
-				dirname(__FILE__) . '/../../phpBB/'
+				dirname(__FILE__) . '/../../phpBB/',
+				'php'
 			),
 			'phpbb_ext',
 			dirname(__FILE__) . '/../../phpBB/',
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index b9a920d092..07ca9fb417 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -118,7 +118,8 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
 				new phpbb_symfony_request(
 					new phpbb_mock_request()
 				),
-				$phpbb_root_path
+				$phpbb_root_path,
+				$php_ext
 			),
 			'phpbb_ext',
 			dirname(__FILE__) . '/',
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
index 6b27929ebf..3ee10c3a74 100644
--- a/tests/extension/metadata_manager_test.php
+++ b/tests/extension/metadata_manager_test.php
@@ -41,8 +41,13 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
 		$this->table_prefix = 'phpbb_';
 
 		$this->template = new phpbb_template_twig(
-			$this->phpbb_root_path,
-			$this->phpEx,
+			new phpbb_filesystem(
+				new phpbb_symfony_request(
+					new phpbb_mock_request()
+				),
+				$this->phpbb_root_path,
+				$this->phpEx
+			),
 			$this->config,
 			$this->user,
 			new phpbb_template_context()
@@ -69,7 +74,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
 				new phpbb_symfony_request(
 					new phpbb_mock_request()
 				),
-				$this->phpbb_root_path
+				$this->phpbb_root_path,
+				$this->phpEx
 			),
 			'phpbb_ext',
 			$this->phpbb_root_path,
diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php
index b79668fc33..38ccf1b603 100644
--- a/tests/filesystem/clean_path_test.php
+++ b/tests/filesystem/clean_path_test.php
@@ -18,7 +18,8 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case
 			new phpbb_symfony_request(
 				new phpbb_mock_request()
 			),
-			dirname(__FILE__) . './../../phpBB/'
+			dirname(__FILE__) . './../../phpBB/',
+			'php'
 		);
 	}
 
diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php
index b681c26de9..ae59d4f709 100644
--- a/tests/filesystem/web_root_path_test.php
+++ b/tests/filesystem/web_root_path_test.php
@@ -18,8 +18,13 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case
 
 		$this->set_phpbb_root_path();
 
-		$symfony_request = new phpbb_symfony_request(new phpbb_mock_request());
-		$this->filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path);
+		$this->filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_mock_request()
+			),
+			$this->phpbb_root_path,
+			'php'
+		);
 	}
 
 	/**
@@ -126,7 +131,11 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case
 			->method('getScriptName')
 			->will($this->returnValue($getScriptName));
 
-		$filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path);
+		$filesystem = new phpbb_filesystem(
+			$symfony_request,
+			$this->phpbb_root_path,
+			'php'
+		);
 
 		$this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request));
 	}
diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php
index 0c73adcf47..0d1b6940ca 100644
--- a/tests/mock/extension_manager.php
+++ b/tests/mock/extension_manager.php
@@ -18,7 +18,8 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager
 			new phpbb_symfony_request(
 				new phpbb_mock_request()
 			),
-			$phpbb_root_path
+			$this->phpbb_root_path,
+			$this->php_ext
 		);
 	}
 }
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index 4280a7e7ff..58691a36da 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -116,7 +116,14 @@ Zeta test event in all',
 		$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
 			dirname(__FILE__) . "/datasets/$dataset/"
 		);
-		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager);
+		$phpbb_filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_mock_request()
+			),
+			$phpbb_root_path,
+			$phpEx
+		);
+		$this->template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context, $this->extension_manager);
 		$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
 	}
 }
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 91895502ad..8151e15b24 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -63,8 +63,16 @@ class phpbb_template_template_test_case extends phpbb_test_case
 		$config = new phpbb_config(array_merge($defaults, $new_config));
 		$this->user = new phpbb_user;
 
+		$phpbb_filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_mock_request()
+			),
+			$phpbb_root_path,
+			$phpEx
+		);
+
 		$this->template_path = $this->test_path . '/templates';
-		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
+		$this->template = new phpbb_template_twig($phpbb_filesystem, $config, $this->user, new phpbb_template_context());
 		$this->template->set_custom_style('tests', $this->template_path);
 	}
 
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index 477192c28a..c4f3b4a257 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -18,9 +18,17 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
 		$defaults = $this->config_defaults();
 		$config = new phpbb_config(array_merge($defaults, $new_config));
 
+		$phpbb_filesystem = new phpbb_filesystem(
+			new phpbb_symfony_request(
+				new phpbb_mock_request()
+			),
+			$phpbb_root_path,
+			$phpEx
+		);
+
 		$this->template_path = $this->test_path . '/templates';
 		$this->parent_template_path = $this->test_path . '/parent_templates';
-		$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context());
+		$this->template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context());
 		$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
 	}
 }
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 48c5649281..00f166d4fe 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -207,7 +207,8 @@ class phpbb_functional_test_case extends phpbb_test_case
 				new phpbb_symfony_request(
 					new phpbb_mock_request()
 				),
-				$phpbb_root_path
+				$phpbb_root_path,
+				$php_ext
 			),
 			self::$config['table_prefix'] . 'ext',
 			dirname(__FILE__) . '/',