Deploying a Drupal 8 Website built with Composer to a Live Server

Drupal is a powerful CMS, and pairing it with Composer makes downloading and updating modules so much easier. Deploying a Drupal website to a live server and specifying the correct directories to get the website working properly can be a bit tricky for newbies. I'm going to show you the few simple steps to accomplish this!

Step 1: Upload all of your files to your web server.

The first thing I did wrong when I was deploying my first Drupal 8 website was only upload the /web directory. Big mistake! You need to make sure you upload ALL of the project folders, including /vendor, /web, etc.

Step 2: Update your .htaccess file

We need to update the main .htaccess file to tell the web server that our main website files are in the /web directory:

RewriteEngine on
# Redirect to the subdirectory because that's where Drupal is installed
RewriteRule (.*) web/$1 [L]

Step 3: Add the following PHP snippet to your settings.php file

The .htaccess adjustment above does most of the work, but as per this article I found, we also need to add the following snippet to the settings.php file:

if ( isset($GLOBALS['request']) && '/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME') ) {
	$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');

You're all set!

You should now have a fully functioning Drupal 8 website on your web server.

Written by Brianna Deleasa on

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.