bchinstall-wordpress-nginx

Install WordPress On Top Of The Bitnami Nginx Stack

Introduction

If you’re interested in creating a personal or small business blog, chances are that you’re going to use WordPress. WordPress is one of the most popular blogging platforms in the world, used on over 60 million websites (according to Wikipedia). And it is not hard to see why: WordPress is very easy to use, comes with thousands of extensions and themes, is completely free, and is open source.

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 WordPress on top of a running NGINX server. That way, you will simplify, for example, the configuration of Let’s Encrypt certificates to secure your WordPress site.

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 on it. You need to leave some NGINX directories ready for the new WordPress installation. To do so, follow the instructions below:

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

    $ cd /opt/bitnami
    $ sudo cp -r docs/demo apps/wordpress
    $ sudo rm -rf /opt/bitnami/apps/wordpress/htdocs/
    
  • Download the latest version of WordPress and extract the files to the /opt/bitnami/apps/wordpress/ directory, then rename the directory containing the extracted files to /opt/bitnami/apps/wordpress/htdocs/.

    $ cd /tmp
    $ wget https://wordpress.org/latest.tar.gz
    $ sudo tar xfvz latest.tar.gz -C /opt/bitnami/apps/wordpress/
    $ sudo mv /opt/bitnami/apps/wordpress/wordpress/ /opt/bitnami/apps/wordpress/htdocs/
    
  • Update the configuration files using the commands below:

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

    include "/opt/bitnami/apps/wordpress/conf/nginx-prefix.conf";
    
  • If you plan to use WordPress permalinks, add this configuration snippet to your /opt/bitnami/apps/wordpress/conf/nginx-app.conf file before the location directive.

    if (!-e $request_filename)
    {
     rewrite ^/wordpress/(.+)$ /wordpress/index.php?q=$1 last;
    }
    
  • Change ownership for the WordPress application by running the following command:

    $ sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/
    
  • Change the permissions of the WordPress files by running the following commands:

    $ sudo find /opt/bitnami/apps/wordpress/htdocs/ -type d -exec chmod 775 {} \;
    $ sudo find /opt/bitnami/apps/wordpress/htdocs/ -type f -exec chmod 664 {} \;
    

Step 2: Create and configure the WordPress database

  • Create a database for WordPress.

    $ /opt/bitnami/mysql/bin/mysql -u root -p
    mysql> create database bitnami_wordpress;
    

    NOTE: When you connect to the MySQL database server, you will be prompted to enter the root user password. This is the same as the application password.

  • Create a database user for WordPress.

    mysql> grant all privileges on bitnami_wordpress.* to 'bn_wordpress'@'localhost'
    identified by 'WORDPRESS-PASSWORD';
    mysql> exit
    

    Keep in mind that you must replace the WORDPRESS-PASSWORD placeholder with an user-defined password that you will use when installing WordPress.

  • Restart NGINX.

    $ sudo /opt/bitnami/ctlscript.sh restart nginx
    
  • Browse to http://SERVER-IP/wordpress to launch the WordPress Web configuration wizard. Simply follow the steps as prompted by the wizard. Click the “Let’s go” button to start the wizard.

    Start WordPress Database Configuration

  • Use the credentials specified earlier when asked for the database configuration and application credentials, as below:

    Database Name: bitnami_wordpress
    User Name: bn_wordpress
    Password:  WORDPRESS-PASSWORD
    Database Host: localhost
    Table Prefix: wp_
    

    WordPress Database Configuration

Step 3: Finish the WordPress installation

  • Create the wp-config.php file manually in the htdocs/ directory by pasting the text indicated in the WordPress configuration file.

  • Return to the browser and click the “Run Install” button.

    Create wp-config.php file

  • End the WordPress installation process filling the information needed. Click the “Install WordPress” button.

IMPORTANT: Use the credentials specified earlier when creating the database user for WordPress. Remember that you must replace the WORDPRESS-PASSWORD placeholder with the same password you defined when creating the database user for WordPress.

[![WordPress site information](/images/img/infrastructure/nginx/wp-install-nginx.png)](/images/img/infrastructure/nginx/wp-install-nginx.png)
  • Run the following command to disable FTP authentication for plugins installation:

    $ sudo echo "define ( 'FS_METHOD', 'direct' );" >> /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    
  • Change the permissions of the wp-config.file file. Run the following commands:

    $ sudo chmod 640 wp-config.php /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    $ sudo chown bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    
  • Access the Administration panel of your application by clicking the “Log In” button.

    WordPress

  • Check the application has been installed. You should see the screen below:

    WordPress Administration Dashboard

    Visit your WordPress site

Now, your WordPress is running on top of your NGINX web server!