In this article, our Drupal web agency will speak about Drupal core installation as a submodule. We will not dwell upon the very concept of a submodule here for long, nor try to consider its dis/advantages. What we want to figure out is just some detailed regulations of how it can be done.
Well, where should we start? First off, get connected to the remote server to have remote access to it (you can make use of ssh, for instance). You need to have two repositories initiated on the server - one for the core and the other for the site itself. It's on this site that the Drupal core will be installed on. We will create a user named "git" just for the purposes of illustrating. The repositories' initialization will then look like this:
cd /home/git/ mkdir bare cd bare mkdir core mkdir project cd core git init --bare cd /home/git/bare/project git init --bare
Secondly, we will build a master branch in the core repository. It can be done at any testing ground once you have created a directory where core files will reside (in our instance it's /var/www/site_core), as well as have unsourced the core git repository that had been created before (the remote server can be accessed through the following path ssh://[email protected]). Next, we perform the first commit to create the master branch in the repository. The relevant picture will read as follows:
cd /var/www/ mkdir site_core cd site_core git clone ssh://[email protected]/home/git/bare/core ./ touch Readme.txt echo 'Core repo' > Readme.txt git add . git commit -m "Initial commit" git push origin master
Thus, we have Drupal core git repository fully initialized and on-the-go, though it still lacks the core files themselves. They should accordingly be added (mind that we are still in /var/www/site_core). The folders which can be affected in the course of elaborating the site should also be removed and placed over into .gitignore. Failing to do this will lead to putting the content of the above folders to the initial state as soon as you have started the git submodule update command running. And that will affect removing the added modules. The folders in question are "modules" and "sites":
git checkout -b 8.x wget http://ftp.drupal.org/files/projects/drupal-8.x-dev.tar.gz tar -xzvf drupal-8.x-dev.tar.gz -C /tmp && mv /tmp/drupal-8.x-dev/* /var/www/site_core rm -rf sites/ modules/ git add . git commit -m "Add core files" git push origin 8.x touch .gitignore echo modules > .gitignore echo sites >> .gitignore git add .gitignore git commit -m "Disalow modules and sites folders" git push
If the chances are the rest of the files can be affected, too, or some of the files can be added to the root while the site is being developed (say, .htaccess file or various HTML metrics files), such files should also be placed into .gitignore.
At this point we have the core repository up and running and available for use as a submodule. So now we are settling down to the site installation proper. For this, we will create (for testing purposes only) a catalog on the server or locally (e.g. new_site), where all site files will reside. The catalog's content should be retrieved from the git repository of the site which had been created in the first stage, as well as the first commit should be performed to initialize the repository master branch:
cd /var/www/ mkdir new_site cd new_site git clone ssh://[email protected]/home/git/bare/project ./ touch Readme.txt echo 'Core project' > Readme.txt git add . git commit -m "Initial commit" git push origin master
Now we are going to tackle the key point within the task, i.e. installing Drupal as a submodule. The following actions should be performed within the site's home directory.
Important: as long as the core will be displayed a submodule now, it can't stay right in the home directory of the site anymore, thus it should be properly placed into a certain directory (e.g. htdocs). The above effort is being taken to free the submodule directory from any files that are foreign to the matter. The installation process is as follows:
git checkout -b dev git submodule add ssh://[email protected]/home/git/bare/core htdocs cd htdocs git checkout 8.x
At the end of the day we have the site home directory /var/www/new_site with the Drupal core placed into /var/www/new_site/htdocs, which has been switched over to the required branch (8.x).
Now it's time to come back to the removed "modules" and "sites" folders. We need them, though they can't be stored at the core submodule. Hence, they need to be created at the site root with the relevant links customized in a way that fakes the folders' presence in the same directory with the core:
cd /var/www/new_site mkdir sites mkdir modules ln -s /var/www/new_site/sites/ /var/www/new_site/htdocs/ ln -s /var/www/new_site/modules/ /var/www/new_site/htdocs/ git add . git commit -m "Install Drupal core" git push origin dev
Well, that's about it - the Drupal core as a submodule installation process is complete! Additional modules should be installed into the "modules" folder, which is in the site root. With a view to illustrate the case, let's install the Administration menu module:
cd /var/www/new_site/ git submodule add --branch 8.x-3.x http://git.drupal.org/project/admin_menu.git modules/admin_menu git add . git commit -m "Install admin menu module" git push
So this is a concise review of how Drupal installation as a git submodule can be performed. Our web development services company hopes the above method will stand you in good stead.