Getting Started With WordPress On NGINX Using IBM Cloud

BM Bluemix is getting popular because of the ease of deployment of virtual hosts on the IBM Cloud. It provides faster customization of the Virtual hosts. That allows us to quickly choose & deploy the server as per the project requirement & size of CPU, Disk Space, & Memory.

WordPress is a very popular and widely used CMS in today’s scenario. With easy to manage structure, out of the box blogging & website framework – I’ve been a complete fan for past 5-6 years. Accessing and deploying WordPress on IBM Cloud seem much easier than having it on other cloud providers or managed hosting providers. Of course, sometimes you may end up going with the managed WordPress hosting for certain customers. But, IBM Cloud seems as competitive on reliability & pricing.

WordPress on IBM Cloud has obvious benefits such as huge reliable network across the world, easy scaling, high availability, security & API connectivity. For complex projects, you can take advantage of various services provided by the IBM Cloud & build your own project framework. Firewall security on IBM Cloud will ensure provide the needed shield to secure the WordPress installation.

How Much Will It Cost?

Being in the growing competitive cloud market, the IBM Cloud offers a quite aggressive pricing. The single Virtual Server will cost roughly $0.049 per hour for 1.5 GB RAM, 1 CPU, and 10GB Disk space. The cost includes 100mbps upload/download speed and unlimited Bandwidth. Sounds cool, eh?

Getting Started

Log on IBM Bluemix dashboard to find the shortcuts at the top such as; Create App, Start Containers, Run Virtual Machines and other API related shortcuts.

Getting Started With WordPress On Nginx Using IBM Cloud

Follow the steps to create a VM on IBM Cloud for WordPress

  1. Create a new Virtual Machine and customize as per your requirement
  2. Choose the OS from left side panel (Ubuntu 14.04 LTS is default) & good to use.
  3. Give a name to this Virtual Machine (any name that suits you & is easy for you to identify the project).
  4. Select the size of the server from “m1.small”, “m1.medium” or “m1.large”, etc.)
  5. Then you must click on the radio button for ‘Assign Public IP address’.
  6. Select Private network, the Public key to access the server and Security Group.

Getting Started With WordPress On Nginx Using IBM Cloud

It will take around a minute or two to create a Virtual Machine. That’s the beauty of using the IBM Cloud.

Access the server from the local computer using below command. Use your public IP of the virtual machine

$ ssh -i /path/to/private_key ubuntu@XXX.XXX.XXX.XXX

Getting Started With WordPress On Nginx Using IBM Cloud

Once the server is connected, WordPress configuration is as easy as any virtual host.

Install Nginx on Bluemix Virtual Server

$ sudo apt-get update

Get the repo for the latest version of Nginx. For that, edit the file below;

$ sudo vi /etc/apt/sources.list

Append at the end of the file

deb xenial nginx

deb-src xenial nginx

Update the repository

$sudo apt-get update

W: GPG error: xenial Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY $key (ABF5BD827BD9BF62)

If you get the above error during the Nginx repo update, please do the following

$sudo apt-key adv --keyserver --recv-keys 'Enter the Key value from above error (ABF5BD827BD9BF62)'

Update the repository again

$sudo apt-get update

Install the Nginx server, you will get the latest stable version of the Nginx.

$ sudo apt-get install nginx

Verify the installation by accessing your server using the IP address. You can do that by entering http://webserver_ip/ in any browser. You should see the Nginx welcome page.

You can further tune the Nginx for better performance.

Step 2 – Install MySQL server

$ sudo apt-get install mysql-server

It will prompt for MySQL root password, type twice with confirmation to complete the setup.

Tell MySQL to generate the structure it needs to store its databases and information. We can do this by typing:

$ sudo mysql_install_db

Then secure your mysql.

$ sudo mysql_secure_installation

Remove the root access & the test DB. You will receive prompts to remove test users and databases. You should just hit “ENTER” through these prompts to remove the unsafe default settings.

Step 3 – Install the PHP

$ sudo apt-get install php-fpm php-mysql php-gd php-mbstring

The command will download the latest stable version of PHP-7.1

Most attacks happen due to bad implementation of PHP. It is recommended to secure the PHP.  Open the configuration file for your PHP setup.

$ sudo vi /etc/php/7.1/fpm/php.ini

Search for the parameter that sets cgi.fix_pathinfo. This should be commented out with a semi-colon (;) and set to “1” by default. We will change both these conditions by uncommenting the line and setting it to “0” like this:


Save and close the file. Restart the PHP service to imply the changes.

$ sudo service php-fpm restart

Configure the Nginx to use the PHP. Delete the default Nginx config file.

$ sudo rm /etc/nginx/conf.d/default.conf

Create the file by name of your website to locate easily

$ sudo vi /etc/nginx/conf.d/techzoom.conf

Create a new file using below details;

server {

listen       80;


access_log  /var/log/nginx/website-name.access.log  main;

location / {

root   /usr/share/nginx/html;

index  index.html index.php index.htm;


location / {

# try_files $uri $uri/ =404;

try_files $uri $uri/ /index.php?q=$uri&$args;


error_page  404              /404.html;

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   /usr/share/nginx/html;


location ~ \.php$ {

root           html;

try_files $uri =404;

fastcgi_pass; # or use fastcgi_pass unix:/var/run/php/7.1/php-fpm.sock

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; #Verify the root path

include        fastcgi_params;



Then create a test page to verify the settings for the PHP.

$ sudo vi /usr/share/nginx/html/info.php

Add below lines to the file. Save and exit.

<?php phpinfo(); ?>

Restart the Nginx service.

$ sudo service nginx restart

Try & access this newly created file through your browser by locating this newly created file. It should be similar to: http://webserver_ip/info.php

Once you confirm all configurations are in place, move to next.

Step 4 – Create DB for WordPress

$ mysql -u root -p

You’ll need to use the root password to be able to get inside of the database.

> CREATE DATABASE wordpress;

Create user to access the newly created database;

> CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

Allow this new DB user to access the newly created db;

> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;

Flush the privileges


Exit the database

> \q

Step5: Download and Configure WordPress

$ wget

untar the downloaded file

$ tar -xzvf latest.tar.gz

This will create a folder ‘wordpress’. Move this folder to your document root. You can also choose to use different folder or put files on the root. But if you intent to integrate WordPress with complex app structure, you should put this inside a folder than on the root.

$ sudo rsync -avP ~/wordpress/ /usr/share/nginx/html/

Go to this newly created ‘wordpress’ folder;

$ sudo cd /usr/share/nginx/html

Create a copy of wp-config-sample.php to wp-config.php

$ sudo cp wp-config-sample.php wp-config.php

Edit this new file

$ sudo vi wp-config.php

Make the necessary changes as needed for the configuration file;

/** The name of the database for WordPress */

define('DB_NAME', 'wordpress');

/** MySQL database username */

define('DB_USER', 'wordpressuser');

/** MySQL database password */

define('DB_PASSWORD', 'password');

Save and exit the file.

Then you’ll need to create a ‘uploads’ directory under ‘wp-content’ folder.

$ sudo mkdir wp-content/uploads

Change the ownership and permission for the location /usr/share/nginx/html/

$ sudo chown -R www-data:www-data /usr/share/nginx/html

$ sudo chmod -R 775 /usr/share/nginx/html

$ sudo chmod g+s /usr/share/nginx/html

This will enforce the directory permission to default www-data, this will help if you upload anything on wp-content/uploads folder the permission will change to www-data instead default username.

$ sudo find /user/share/nginx/html -type d -exec chmod g+s {} +

This will make all newly created files inherit the parent directory’s group, instead of the user’s.

If there is any default index.html file in above location, please remove or rename it.

Visit URL by webserver IP address or DNS name if you have set


Getting Started With WordPress On Nginx Using IBM Cloud

Follow the onscreen instructions. Once the installation is complete, you can now log in to the WordPress admin panel


Use the same admin user and password which you have configured while installing the WordPress.

After you review that everything is great – use your domain DNS manager to change the A record for the domain name.

What’s More

There are some security & optimization tweaks you can do to improve the performance of WordPress. That, however, is for some another time, to ensure this article stays focused only on the setup.

Wait, There’s Another Way Too

For much simpler way to get started with WordPress on IBM Bluemix, they’ve covered a nice article on how easily you can deploy the same. Read it here.


Please enter your comment!
Please enter your name here