Statamic CMS is a powerful, flexible, and user-friendly content management system that runs on Laravel. One of its key features is its ability to be customized to fit the needs of any project.
As Statamic runs on Laravel so it has public
as it's default web root directory. So if I have different web root directory like web
or public_html
, Statamic doesn't run properly. By default, Statamic’s public-facing files are served from the public
directory.
Why Change the Web Root Directory?
Before diving into the process, let's quickly cover why you might want to change your web root directory:
- Hosting Requirements: Some hosting providers, like shared hosting environments, require your web root directory to be
public_html
or a similar directory. - Security: Moving the web root directory can enhance security by keeping important files outside of the publicly accessible directory.
- Organization: Customizing your directory structure can help you keep your project organized in a way that makes the most sense for your workflow.
There is very easy and one step way to achive it -
Open the file bootstrap/app.php
and put this line $app->usePublicPath(base_path().'/public_html');
above return $app;
. It depends on the name of web root directory if web root directory name is web
, it will like $app->usePublicPath(base_path().'/web');
That's it 😊.