Advertising sustains the DA. Ads are hidden for members. Join today

Security in Drupal

Securing the installer (install.php)

Last updated on
27 November 2026

Drupal's installer is at /core/install.php. You need it once, to install the site. After installation is complete, you should block access to it. This page explains why, and shows three ways to do it.

Why block install.php

Drupal has fixed various security issues in the installer over the years. However if you’ve already installed your site, you don’t need it at all, so can completely remove the risk of any future vulnerabilities.

Before you start

  • Finish the installation first. Never leave a half-finished installation on a server that is reachable from the internet.
  • Know when you still need the installer. You need install.php to install a new site in the browser. This includes adding a new site to a multisite setup. If you do that, allow access again for a short time, or use drush site:install instead. Drush does not use install.php.
  • Blocking install.php does not affect updates. update.php is a separate script. Do not block it by accident with a broad rule.
  • Check with your hosting provider. Some managed hosting platforms already block the installer. Test before you add your own rule (see "Check that it works" below).

This is the best option if you can edit your web server configuration. It keeps working when you update Drupal core.

Apache

Add this to your Apache server configuration, not to .htaccess. Putting it in .htaccess will cause a "500 Internal Server Error".

Run apachectl -S to see which files define your virtual hosts. Add the rule to every virtual host that serves your site, including the HTTPS one (Let's Encrypt often creates a separate file for it). Or, add it once outside any <VirtualHost> to cover them all.

Add this to your virtual host configuration, then reload Apache:

<Location "/core/install.php">
  Require all denied
</Location>

Visitors get a "403 Forbidden" response. If Drupal is installed in a subdirectory, change the path, for example /drupal/core/install.php.

To allow only your own IP address (for example, while you add a site to a multisite setup):

<Location "/core/install.php">
  Require ip 203.0.113.10
</Location>

Run apachectl configtest before you reload Apache.

Nginx

Find the server block that serves your site over HTTPS with:
nginx -T

Add this inside the server block that runs over HTTPS:

location ^~ /core/install.php {
  return 404;
}

The ^~ modifier matches every URL that starts with /core/install.php, including URLs with extra text after the file name, such as /core/install.php/foo. It also tells Nginx to skip pattern matches such as location ~ \.php$, so the order of the blocks does not matter.

Do not use an exact match (location = /core/install.php). Some Nginx configurations send any URL that contains .php/ to PHP, for example with location ~ \.php(/|$). On those servers, an exact match does not block /core/install.php/foo, and the installer still runs.

Run nginx -t before you reload Nginx.

Option 2: Block it in .htaccess (Apache only)

Use this option if you cannot edit your server configuration, for example on shared hosting.

Add this to the .htaccess file in your web root (the folder that contains index.php):

<Files "install.php">
  Require all denied
</Files>

Apache only reads Require rules in .htaccess if AllowOverride includes AuthConfig. Drupal already needs AllowOverride All, so this is normally true.

Important: .htaccess is a scaffold file. Composer replaces it every time the scaffold step runs, including a plain composer install, even when core has not changed. Any lines you add by hand are lost. To keep the change, put the lines above in a separate file (for example assets/htaccess-additions.txt) and tell the scaffold plugin to add it to the end of .htaccess. In composer.json:

"extra": {
  "drupal-scaffold": {
    "file-mapping": {
      "[web-root]/.htaccess": {
        "append": "assets/htaccess-additions.txt"
      }
    }
  }
}

Then run composer update --lock so your lock file matches the changed composer.json, and run composer install. Check that the lines are at the end of .htaccess.

Option 3: Remove the file

You can also delete core/install.php. Composer puts the file back every time it installs or updates core, so you must remove it again after each run. You can do this with Composer scripts in composer.json:

"scripts": {
  "post-install-cmd": ["rm -f web/core/install.php"],
  "post-update-cmd": ["rm -f web/core/install.php"]
}

Change web/ if your web root has a different name.

Trade-offs:

  • If your deployment runs composer install --no-scripts, the file is not removed.
  • You cannot install a new site in the browser until you restore the file.
  • rm -f does not work on Windows without a Unix-style shell.

For most sites, Option 1 or Option 2 is easier to maintain.

These options are not mutually exclusive — Option 3 is strongest combined with Option 1 or 2, not instead of them. Each covers the other's failure mode: a --no-scripts deployment leaves the file in place, while a web server rule can be silently dropped by a config change or a server or platform migration.

Do both: remove the file and block it at the web server, so the installer cannot run even if one layer lapses.

Check that it works

Run these commands, replacing example.com with your site's address:

curl -I https://example.com/core/install.php
curl -IL https://example.com/install.php
curl -I https://example.com/core/install.php/foo

All three should end with a 403 or 404 response. If you see 200, the block is not working.

Then check that your site still works normally, and that you can still run database updates (drush updatedb or /update.php).

Help improve this page

Page status: No known problems

You can: