Hosting Drupal Website on Shared Server in a Sub-Directory

Submitted by Tom Thorp on Tuesday, October 17, 2017 - 16:14
Modified on Wednesday, August 1, 2018 - 02:30
Drupal 8
I recently came across a curly issue hosting my Drupal website on my shared hosting provider. I wanted to now set up a Drupal website using the primary domain name I registered my account with. However, as with shared hosting accounts, the primary domain has a fixed directory where websites can be served from and cannot be virtually hosted/moved to some other part of the home directory structure.
 
The two issues I faced were:
 
  1. I wanted to install my primary domain in the same sub-directory structure as with my other add-on domains (instead of installing it in the root directory), and
  2. the URI address had to be shown as if it was virtually hosted (ie. not showing the path where the website is installed.)
The answer turned out to be a simple change to the .htaccess file in the directory serving my primary domain.  
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_URI} !websites/primarydrupal/
  RewriteRule (.*) /websites/primarydrupal/$1 [L]
</IfModule>
 
Two problems that require further investigation 
 
  1. If you had installed Drupal prior to implementing the .htaccess redirection, you will find that your admin and menu paths include the full install path in the URI. By reinstalling Drupal with the redirection in place, solves this issue. If there is an easier way (apart from reinstalling Drupal) that will rebuild the paths, I'd like to hear it.
  2. When I performed a Drupal upgrade via Composer (8.3.7 => 8.4.0), logged in and run Update.php, Drupal defaulted the URI path to the full installation path and failed. The workaround I found was to change "settings.php" and temporarily change the following line :
    $settings['update_free_access'] = FALSE;
    to
    $settings['update_free_access'] = TRUE;
    Is this a short-coming, or is something else at play?
 
Leave your comments below. 
 

About the author

Tom Thorp
Tom Thorp is an IT Consultant living in Miami on Queensland's Gold Coast. With over 30+ years working in the IT industry, Tom's experience is a broad canvas. The IT services Tom provides to his clients, includes :
 
Website development and hosting
Database Administration
Server Administration (Windows, Linux, Apple)
PABX Hosting and Administration
Helpdesk Support (end-user & technical).
 
 
Categories