Relocated web root on shared hosting with symlink
Warning: Only use this method if you are an experienced Unix user.
The recommended method of running a Drupal site is with a "relocated document root":
[...] the files "index.php" and the "core" directory and so on are placed inside a subfolder named "web" rather than being placed next to "composer.json" and the "vendor" directory at the project root.
From Securing file permissions and ownership.
This can be a challenge on shared hosting, if you are not allowed to set the DocumentRoot, either via configuration or the GUI.
A workaround is placing the Drupal files in a folder outside the public_html folder, and instead serve the /web-folder via public_html using a symlink. This method requires command line access, via SSH or the browser.
Assuming that when you log in on your shared hosting, this is your home folder:
/var/www/example.org
Assuming this is the path to the public_html folder:
/var/www/example.org/public_html
- Place your Drupal folder here:
/var/www/example.org/drupal10 - Rename the
public_htmlfolder:
mv public_html public_html_OLD - Create a symlink from
public_htmltoweb:
ln -s /var/www/example.org/drupal10/web /var/www/example.org/public_html
Now, the files in /web will be served via the symlinked public_html-folder. Run Composer and Drush commands from the drupal10 folder, not public_html.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.