Bitnami How-To Guides for AWS Cloud

Install Drupal On Top Of The Bitnami NGINX Stack


If you’re interested in creating a personal or a business website, you can use Drupal. Drupal is an open source content management framework used by thousand of enterprises, governments, higher-education institutions and NGOs for creating their websites with reliably and flexibly.

NGINX is an open source web server that helps developers to improve the security, performance and reliability of their applications. And not only that, it can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

This guide walks you through the process of installing Drupal on top of a running NGINX server. That way, you will simplify, for example, the configuration of Let’s Encrypt certificates to secure your Drupal website.

Assumptions and prerequisites

This guide makes the following assumptions:

  • You have a basic understanding of NGINX.
  • You have a Bitnami stack installed with an Nginx server - for example, the Bitnami Nginx Stack.

Step 1: Prepare your NGINX server

This step consists of preparing your NGINX server for installing Drupal on top of it. You need to leave some NGINX directories ready for the new Drupal installation. To do so, follow the instructions below:

  • Copy the demo/ directory from the /opt/bitnami/docs directory to the apps directory, and remove the htdocs/ directory from the demo application.

    $ cd /opt/bitnami
    $ sudo cp -r docs/demo apps/drupal
    $ sudo rm -rf /opt/bitnami/apps/drupal/htdocs/
  • Download the latest version of Drupal (replace the X.Y.Z placeholder with the latest version available) and extract the files into the /opt/bitnami/apps/drupal/ directory, then rename that directory to /opt/bitnami/apps/drupal/htdocs/.

    $ cd /tmp
    $ wget
    $ sudo tar xfvz drupal-X.Y.Z.tar.gz -C /opt/bitnami/apps/drupal/
    $ sudo mv /opt/bitnami/apps/drupal/drupal-X.Y.Z/ /opt/bitnami/apps/drupal/htdocs/
    $ sudo cp /opt/bitnami/apps/drupal/htdocs/sites/default/default.settings.php /opt/bitnami/apps/drupal/htdocs/sites/default/settings.php
  • Update the NGINX configuration files using the commands below:

    $ sudo sed -i 's/demo/drupal/g' /opt/bitnami/apps/drupal/conf/nginx-prefix.conf
    $ sudo sed -i 's/demo/drupal/g' /opt/bitnami/apps/drupal/conf/nginx-vhosts.conf
  • Add a new entry in the /opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf file:

    $ echo 'include "/opt/bitnami/apps/drupal/conf/nginx-prefix.conf";' | sudo tee -a /opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf
  • Change the ownership and permissions of the Drupal application by running the following commands:

    $ sudo chown -R bitnami:daemon /opt/bitnami/apps/drupal/htdocs/
    $ sudo find /opt/bitnami/apps/drupal/htdocs/ -type d -exec chmod 775 {} \;
    $ sudo find /opt/bitnami/apps/drupal/htdocs/ -type f -exec chmod 664 {} \;

Step 2: Create and configure the Drupal database

  • Create a database for Drupal (you need to indicate the MySQL credentials).

    $ /opt/bitnami/mysql/bin/mysql -u root -e "create database bitnami_drupal;" -p
  • Create a database user for Drupal (you need to indicate the MySQL credentials).

    $ /opt/bitnami/mysql/bin/mysql -u root -e "grant all privileges on bitnami_drupal.* to 'bn_drupal'@'localhost' identified by 'DRUPAL-PASSWORD'" -p

    NOTE: Replace the DRUPAL-PASSWORD placeholder with a user-defined password that you will use when installing Drupal.

  • Restart NGINX:

    $ sudo /opt/bitnami/ restart nginx
  • Open a browser and go to http://YOUR-SERVER-IP/drupal/core/install.php as it is shown below:

    Select Drupal language

Follow the installation steps:

  • Choose the language.
  • Choose “standard” as profile.
  • When setting the database, use the DRUPAL-PASSWORD you previously chose. Once you have finished, click “Save and continue”:

    Drupal database configuration

  • Enter the required information in the “Configure site” screen and click “Save and continue”:

    Drupal site configuration

  • Finally, strength the Drupal permissions to improve the security of your site:

    $ sudo /opt/bitnami/apps/drupal/htdocs/ -type d -exec chmod 755 {} \;
    $ sudo /opt/bitnami/apps/drupal/htdocs/ -type f -exec chmod 644 {} \;

Step 3: Update the NGINX configuration

In this step, you will perform some changes in the NGINX configuration files in order to make the application work at the root URL of the NGINX server. Follow the instructions below to finish the Drupal installation.

  • Edit the /opt/bitnami/apps/drupal/conf/nginx-app.conf file again and update it so that it looks as follows:

    if (!-e $request_filename)
    rewrite ^/(.+)$ /index.php?q=$1 last;
    index index.php index.html index.htm;
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_read_timeout 300;
        fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
  • Edit the /opt/bitnami/apps/drupal/conf/nginx-prefix.conf file. It should looks like this:

    root   "/opt/bitnami/apps/drupal/htdocs/";
    include "/opt/bitnami/apps/drupal/conf/nginx-app.conf";
  • Comment the phpfastcgi.conf lines of the /opt/bitnami/nginx/conf/bitnami/bitnami.conf file as shown below:

    # HTTP server
    server {
        listen       80;
        server_name  localhost;
        #include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
        include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
    # HTTPS server
    server {
        listen       443 ssl;
        server_name  localhost;
        ssl_certificate      server.crt;
        ssl_certificate_key  server.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        # include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
        include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
    include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-vhosts.conf";
  • Restart NGINX:

    $ sudo /opt/bitnami/ restart nginx

Now, your Drupal installation should be running at the root URL of your NGINX Web server!

Last modification February 7, 2019