4

So, I have to deploy a drupal 8 site to a host which doesn't provide functionality to specify an entry point for a Drupal site which is nested below the site root folder. How can I update the folder structure to have everything in the server's site root? What I tried initially was to move the contents of the site_root/web/ folder up to the site root, but this causes 500 errors. I'm not sure since I can't see the errors on the host server, but replicating the scenario on my dev machine points to the autoloader.php file looking in the wrong place PHP Fatal error: require(): Failed opening required '/var/www/html/ab-test/../vendor/autoload.php'.

I have tried to resolve this by first following the suggestion to re-run composer install from the site root but that doesn't seem to help. When I manually update where the autoloader.php should be looking, I then get this errorPHP Warning: require(/var/www/html/ab-test/vendor/composer/../../load.environment.php) which again suggests that the file/folder structure is being set somewhere I'm not thinking of or don't have enough experience to check. So, my convoluted question comes down to how do I switch from a nested to a non-nested folder structure without everything freaking out?

  • Apache or nginx? – Johnathan Elmore Mar 21 at 15:23
  • It's an apache server, shared of course – nizz0k Mar 21 at 15:26
1

As you are using an Apache server, you may try to set the Drupal root folder using an .htaccess file in your site_root:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]

(Replace example.com with your actual domain name.)

This way, you can keep the "nested" folder structure created using Composer and serve all requests for your domain with the web sub folder.

  • I'd read this, but didn't have the admin chops to implement. Does this come with a performance hit? – nizz0k Mar 22 at 13:13
  • The rewrite itself shouldn't matter as much in terms of performance, as using .htaccess does instead of a proper vhost configuration. But obviously it's your only choice on your shared hosting. If you experience performance bottlenecks, it's unlikely to be caused by this little rewrite. – Mario Steinitz Mar 22 at 13:27
  • @nizz0k Careful with this one, you might be open to a kind of directory traversal attack. If you can't change the root path for the vhost, apache will (or at least did last time I checked a few years ago) still serve anything you can physically get to in the parent of ./web. For example: example.com/web/../private_files/my_password.txt. Since "web/" is at the start of the request URI, the rewrite rule won't kick in, and if the file exists apache will probably serve it – Clive Mar 22 at 19:10
  • Thanks Clive, I'm looking into alternatives. It's a European host and I have some language issues trying to get support. I hope to get a more robust solution implemented soon. – nizz0k Mar 25 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.