PHP front-controller to destroy and re-install a Drupal (8) site.
Place this script into the document root of your Drupal site; i.e.,
/reinstall.php
Request it in your browser to drop all Drupal database tables and delete all configuration, so you can re-install from scratch.
Without additional parameters, settings.php
is retained as-is, so you can
re-install with your previously existing database connection info, etc.
Optional GET query parameters:
delete=1
Additionally deletessettings.php
and the files directory.main=1
Unlocks reinstallation of of the main/default site. By default, only a [multi-]site may be reinstalled/deleted.
Regardless of parameters, the site directory itself (and /sites/sites.php
) is
never deleted. This enables the Drupal installer to discover the same site
directory again.
You may pass additional query parameters like langcode
and profile
, which
will be forwarded to /install.php
; e.g.:
http://drupal8.test/reinstall.php?delete=1&langcode=en&profile=testing
Simply download reinstall.php into the Document Root directory of your Drupal site.
# Wherever you normally clone git repos...
cd ~/gitrepos
git clone https://github.com/sun/drupal-reinstall.git
# In the Document Root directory of your Drupal checkout...
cd /var/www/drupal8
ln -s ~/gitrepos/drupal-reinstall/reinstall.php
:: Wherever you normally clone git repos...
cd C:\gitrepos
git clone https://github.com/sun/drupal-reinstall.git
:: In the Document Root directory of your Drupal checkout...
cd H:\htdocs\drupal8
mklink /H reinstall.php C:\gitrepos\drupal-reinstall\reinstall.php
:: yields:
Created hard link for reinstall.php <<===>> C:\gitrepos\drupal-reinstall\reinstall.php
This script and manual refers to "multiple sites" in a couple of places. This chapter explains what is meant by that and why it matters.
Drupal core natively supports a multi-site concept; see
/sites/default/default.settings.php
Drupal's multi-site functionality is normally used when you have multiple domains pointing to the same host and identical code base. — But what if you don't have or want that? Can you leverage it for quick throw-away "scratch" re-installations?
Yes, you can. Assuming the following:
- You have Drupal in
/var/www/drupal8/
- You normally access it via http://drupal8.local/
- You want to access a separate scratch site via http://drupal8.local/scratch/
Here is how:
-
Edit your Apache
httpd.conf
(or corresponding virtual host*.conf
file) to add anAlias
:<VirtualHost *:80> ServerName drupal8.local ... Alias /scratch /var/www/drupal8 </VirtualHost>
-
Restart Apache.
-
Create an empty
/sites/scratch
directory. -
Copy
/sites/example.sites.php
into/sites/sites.php
-
Add the following line to
/sites/sites.php
:$sites['drupal8.local.scratch'] = 'scratch';
Known limitation:
-
The Apache 2.4+
mod_alias
module supplies a$_SERVER['CONTEXT_PREFIX']
variable to PHP, which is not consumed in any way by Drupal. -
mod_alias
is only triggered when requesting a file within the aliased location. When only requesting a directory (e.g.,/scratch
), then the request does not run against the alias. -
Due to the above, the final redirect to
/scratch
after completing the Drupal installation will end up in the default site. To access the newly installed scratch site, you have to manually inject a "dirty" URL:-http://drupal8.local/scratch/user/1 +http://drupal8.local/scratch/index.php/user/1
The limitation does not apply to the reinstall.php
script itself, nor to
install.php
, since both are interpreted as files by Apache.
Tip: Use the SQLite database driver when installing your scratch site, so the
entire site is contained in files in the /sites/scratch
directory.