{"id":817,"date":"2024-06-30T09:00:17","date_gmt":"2024-06-30T09:00:17","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=817"},"modified":"2024-06-30T16:57:18","modified_gmt":"2024-06-30T16:57:18","slug":"drupal-tutorials-sites-directory-and-its-use-cases","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/drupal-tutorials-sites-directory-and-its-use-cases\/","title":{"rendered":"Drupal Tutorials: directory structure and Its Use Cases"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>sites<\/code> directory in a Drupal installation plays a crucial role in managing site-specific configurations, files, modules, themes, and other resources. It is designed to support multisite setups, allowing multiple Drupal sites to share a single codebase while maintaining separate configurations and content.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Structure of the <code>sites<\/code> Directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an overview of the typical structure within the <code>sites<\/code> directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drupal\/\n\u251c\u2500\u2500 includes\/\n\u251c\u2500\u2500 misc\/\n\u251c\u2500\u2500 modules\/\n\u251c\u2500\u2500 profiles\/\n\u251c\u2500\u2500 scripts\/\n\u251c\u2500\u2500 sites\/\n\u2502   \u251c\u2500\u2500 all\/\n\u2502   \u2502   \u251c\u2500\u2500 libraries\/\n\u2502   \u2502   \u251c\u2500\u2500 modules\/\n\u2502   \u2502   \u2514\u2500\u2500 themes\/\n\u2502   \u251c\u2500\u2500 default\/\n\u2502   \u2502   \u251c\u2500\u2500 files\/\n\u2502   \u2502   \u251c\u2500\u2500 settings.php\n\u2502   \u2502   \u2514\u2500\u2500 default.settings.php\n\u2502   \u251c\u2500\u2500 example.com\/\n\u2502   \u2502   \u251c\u2500\u2500 files\/\n\u2502   \u2502   \u251c\u2500\u2500 settings.php\n\u2502   \u2502   \u2514\u2500\u2500 default.settings.php\n\u2502   \u2514\u2500\u2500 example.sites.php\n\u251c\u2500\u2500 themes\/\n\u251c\u2500\u2500 updates\/\n\u251c\u2500\u2500 web.config\n\u251c\u2500\u2500 .htaccess\n\u251c\u2500\u2500 cron.php\n\u251c\u2500\u2500 index.php\n\u251c\u2500\u2500 install.php\n\u251c\u2500\u2500 LICENSE.txt\n\u251c\u2500\u2500 MAINTAINERS.txt\n\u251c\u2500\u2500 README.txt\n\u2514\u2500\u2500 xmlrpc.php\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Directories and Their Uses<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>sites\/all\/<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This directory contains resources that are shared across all Drupal sites in a multisite setup. It&#8217;s useful for storing libraries, modules, and themes that should be available to every site using the same Drupal codebase.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>libraries\/<\/strong>: Place shared third-party libraries here.<\/li>\n\n\n\n<li><strong>modules\/<\/strong>: Place shared modules here.<\/li>\n\n\n\n<li><strong>themes\/<\/strong>: Place shared themes here.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>sites\/default\/<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This directory is used for the default Drupal site configuration. If you&#8217;re running a single-site setup, this is where all your site-specific files and configurations will be located.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>files\/<\/strong>: Stores uploaded files such as images and documents. It must be writable by the web server.<\/li>\n\n\n\n<li><strong>settings.php<\/strong>: The main configuration file for the site, including database connection details and other site-specific settings.<\/li>\n\n\n\n<li><strong>default.settings.php<\/strong>: A template for the <code>settings.php<\/code> file. This file is copied and renamed to <code>settings.php<\/code> during installation.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong>sites\/[sitename]\/ (e.g., sites\/example.com\/)<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In a multisite setup, each site has its own directory within the <code>sites<\/code> directory. The directory name typically matches the site&#8217;s domain or subdomain.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>files\/<\/strong>: Stores uploaded files for this specific site.<\/li>\n\n\n\n<li><strong>settings.php<\/strong>: Configuration file for this specific site.<\/li>\n\n\n\n<li><strong>default.settings.php<\/strong>: Template for creating the <code>settings.php<\/code> file.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4. <strong>example.sites.php<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This file is an example configuration file for setting up multisite. It shows how to map hostnames to specific site directories within the <code>sites<\/code> directory. To enable multisite, you would copy this file to <code>sites\/sites.php<\/code> and customize it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Use Cases<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Single-Site Setup<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In a single-site setup, you primarily use the <code>sites\/default<\/code> directory for all site-specific configurations and files. This simplifies management as everything related to your site is contained within this directory.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Multisite Setup<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Drupal&#8217;s multisite feature allows you to run multiple websites from a single codebase. Each site can have its own configuration, modules, themes, and content. This setup is ideal for scenarios where you need to manage multiple websites that share common features but require separate content and configurations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Multisite Use Case:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Corporate Website Network:<\/strong> A company with multiple regional or product-specific websites can manage all these sites from a single Drupal installation. Each site can have its own directory under <code>sites<\/code>, such as <code>sites\/region1.example.com<\/code>, <code>sites\/region2.example.com<\/code>, and <code>sites\/products.example.com<\/code>.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Shared Resources<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>sites\/all<\/code> directory is used to store shared resources like modules and themes that should be available to all sites in a multisite setup. This allows you to maintain and update common functionalities in one place without duplicating files across multiple directories.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration Details<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Multisite Configuration Example:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create Site Directories:<\/strong>Create a directory for each site in the <code>sites<\/code> directory:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p sites\/region1.example.com\nmkdir -p sites\/region2.example.com\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Copy Default Settings:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the <code>default.settings.php<\/code> file to each site directory and rename it to <code>settings.php<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp sites\/default\/default.settings.php sites\/region1.example.com\/settings.php\ncp sites\/default\/default.settings.php sites\/region2.example.com\/settings.php\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Configure Database Settings:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the <code>settings.php<\/code> file for each site to configure the database connection and other site-specific settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set Up <code>sites.php<\/code>:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy <code>example.sites.php<\/code> to <code>sites\/sites.php<\/code> and configure it to map hostnames to site directories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$sites = array(\n  'region1.example.com' =&gt; 'region1.example.com',\n  'region2.example.com' =&gt; 'region2.example.com',\n);\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Configure Web Server:<\/strong>Ensure your web server is configured to serve the correct site based on the hostname. For Apache, this involves setting up virtual hosts.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Apache Virtual Host Configuration:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerName region1.example.com\n    DocumentRoot \/path\/to\/drupal\n    &lt;Directory \/path\/to\/drupal&gt;\n        AllowOverride All\n        Order allow,deny\n        allow from all\n    &lt;\/Directory&gt;\n&lt;\/VirtualHost&gt;\n\n&lt;VirtualHost *:80&gt;\n    ServerName region2.example.com\n    DocumentRoot \/path\/to\/drupal\n    &lt;Directory \/path\/to\/drupal&gt;\n        AllowOverride All\n        Order allow,deny\n        allow from all\n    &lt;\/Directory&gt;\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By understanding and leveraging the <code>sites<\/code> directory, you can effectively manage single-site and multisite Drupal installations, allowing for greater flexibility and organization in your Drupal projects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80>\r\n    ServerName region1.example.com\r\n    DocumentRoot \/var\/www\/html\/drupal\r\n    &lt;Directory \/var\/www\/html\/drupal>\r\n        AllowOverride All\r\n        Order allow,deny\r\n        allow from all\r\n        Require all granted\r\n    &lt;\/Directory>\r\n&lt;\/VirtualHost>\r\n\r\n&lt;VirtualHost *:80>\r\n    ServerName region2.example.com\r\n    DocumentRoot \/var\/www\/html\/drupal\r\n    &lt;Directory \/var\/www\/html\/drupal>\r\n        AllowOverride All\r\n        Order allow,deny\r\n        allow from all\r\n        Require all granted\r\n    &lt;\/Directory>\r\n&lt;\/VirtualHost>\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The sites directory in a Drupal installation plays a crucial role in managing site-specific configurations, files, modules, themes, and other<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[790],"tags":[],"class_list":["post-817","post","type-post","status-publish","format-standard","hentry","category-drupal"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=817"}],"version-history":[{"count":4,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/817\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/817\/revisions\/841"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}