Introduction: Install NGINX & Drupal 8 with Bitnami Tools
This Tutorial will show how to install NGINX on a VPS hosting plan to run Drupal 8 websites with Linux, MySQL/MariaDB, & PHP 7 settings with a Bitnami LEMP stack.
The Bitnami NGINX stack installs on any Linux, Windows, or Mac server with an integrated development & secure production environment for PHP & MySQL.
The Bitnami NGINX LEMP stack includes a package of phpMyAdmin, SQLite, ImageMagick, FastCGI, Memcached, GD, CURL, PEAR, PECL & other components.
Step One: Install & Configure the NGINX Server Software
HostAdvice has published a number of Tutorials for installing and configuring an NGINX web server on Ubuntu Linux:
- How to setup the Nginx web server with Nginx server blocks on Ubuntu 18.04
- How to Tune and Optimize Performance of Nginx Web Server
Follow these guides to install NGINX & Ubuntu on bare metal web servers or unmanaged VPS plans. Another alternative is to use the Bitnami LEMP stack.
REQUIRED DOWNLOAD:
- Bitnami LEMP Stack: (Download Files)
The Bitnami LEMP stack installs from a single executable file and includes all of the extensions for running MySQL, PHP, PHP-FPM, & other requirements for Drupal 8.
To install, upload the NGINX stack installer package to the web server. Run the following commands to change the permissions & install the NGINX stack:
chmod 755 bitnami-nginxstack-1.14.1-0-linux-x64-installer.run ./bitnami-nginxstack-1.14.1-0-linux-x64-installer.run
Change the package version numbers to match the current download release. The Bitnami LEMP stack will install on Linux, Windows, or Mac OS with requirements.
Next, copy the /demo directory from the /opt/bitnami/docs folder to the /apps directory. Remove the /htdocs directory from the demo app completely by deleting the folder:
cd /opt/bitnami sudo cp -r docs/demo apps/drupal sudo rm -rf /opt/bitnami/apps/drupal/htdocs/
Use the following commands to download the latest version of Drupal 8 and extract the gzip files into the /opt/bitnami/apps/drupal/ directory (while renaming the new directory to /opt/bitnami/apps/drupal/htdocs/):
cd /tmp wget https://ftp.drupal.org/files/projects/drupal-8.6.3.tar.gz sudo tar xfvz drupal-X.Y.Z.tar.gz -C /opt/bitnami/apps/drupal/ sudo mv /opt/bitnami/apps/drupal/drupal-8.6.3//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
Then 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
Finally, change the ownership and permissions of the Drupal 8 application by running the following CLI commands with Sudo:
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 {} ;
After this the Drupal 8 files are available for installation on a NGINX server with all of the required PHP, MySQL, & programming language extension packages needed for maintaining a secure production environment on VPS/Dedicated web hosting plan.
Step Two: Create a New MySQL/MariaDB Database
Drupal 8 developers can now create a new MySQL or MariaDB database for use in installing a new copy of the CMS through the core distribution package.
Run the following commands to create a new MySQL database for Drupal 8:
/opt/bitnami/mysql/bin/mysql -u root -e "create database bitnami_drupal;" -p
Edit the following commands & create a new user for the MySQL database with all of the required privileges:
/opt/bitnami/mysql/bin/mysql -u root -e "grant all privilegeson bitnami_drupal.* to'bn_drupal'@'localhost'identifiedby'DRUPAL-PASSWORD'" -p
Record the password, user, & database name for the Drupal 8 installation. Next navigate to the root domain name at https://example.com & run the installer script.
Note: Developers can also navigate to https://example.com/phpmyadmin & use the phpMyAdmin tool set to create a database, user, & grant permissions for the install.
Step Three: Install the Drupal 8 CMS on NGINX
Open http://example.com/install.php page & run the Drupal 8 installation script, inputting the MySQL database name, user, & password with other site information.
After the installation is finished, Bitnami recommends running the following commands to change permissions on Drupal 8 files for better web security:
sudo /opt/bitnami/apps/drupal/htdocs/ -type d -exec chmod 755 {} ; sudo /opt/bitnami/apps/drupal/htdocs/ -type f -exec chmod 644 {} ;
When installation of Drupal 8 is complete on the Bitnami LEMP stack, it is required to edit the NGINX configuration files on the web server to enable application support.
Step Four: Edit the nginx-app.conf File to Support Drupal 8
Locate the NGINX configuration file on the web server located at: /opt/bitnami/apps/drupal/conf/nginx-app.conf and open it in a text editor.
To run Drupal 8 in the root directory of the web server with the https://example.com URL structure, edit the file with the following information:
if (!-e $request_filename) { rewrite ^/(.+)$ /index.php?q=$1last; } index index.php index.html index.htm; location~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_read_timeout300; fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; }
Save the nginx-app.conf file & upload it again to the web server. Then restart the server to make the changes active to NGINX in operations:
sudo /opt/bitnami/ctlscript.sh restart nginx
To complete the process, navigate to: /opt/bitnami/apps/drupal/conf/nginx-prefix.conf and open the nginx-prefix.conf file in a text editor. Add the text:
root "/opt/bitnami/apps/drupal/htdocs/"; include "/opt/bitnami/apps/drupal/conf/nginx-app.conf";
Save the new version of the file to the web server. This will register the nginx-app.conf file globally so that NGINX supports the Drupal 8 website application in production.
Step Five: Edit the bitnami.conf File for PHP-FastCGI Status
To complete the installation of Drupal 8 on NGINX, it is required to turn off support for running PHP as a Fast CGI process. To do this locate the bitnami.conf file located at:
- /opt/bitnami/nginx/conf/bitnami/bitnami.conf
Comment out (#) support for the phpfastcgi.conf file as shown in the example 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";
Then restart the NGINX server by running the command:
sudo /opt/bitnami/ctlscript.sh restart nginx
This completes the web server configuration requirements for installing Drupal 8 on the Bitnami LEMP/MEMP/WEMP stack running Linux, Mac, or Windows in production.
Conclusion: Bitnami Stack for NGINX, PHP-FPM, & Drupal 8
The Bitnami LEMP stack makes it easier to install an NGINX server on a VPS plan running any version of Linux or Windows with all of the PHP & MySQL packages.
Drupal 8 can be installed manually or via the command line using Drush, Sudo, or Composer for the file transfer and MySQL database creation, or using phpMyAdmin.
The Bitnami LEMP stack only requires minor edits to the nginx-app.conf & bitnami.conf files to install a complete NGINX web server with PHP & MySQL packages in one click.
Check out these top 3 Drupal hosting services:
- Want info about best web hosting? Clicking this link can be of great help.