Deploy a WordPress Application on IBM Bluemix

5 min read

Deploy a WordPress Application on IBM Bluemix

WordPress is a free and open source blogging tool and a content management system (CMS) based on PHPand MySQL which runs on a web hosting service. Features include a plug-in architecture and a template system. WordPress is completely customizable and can be used for almost anything. You can use WordPress as a foundation of your web application to call social data APIs. In order to have WordPress work on the IBM codename: BlueMix Platform, do the following:

    1. Download a current stable version of WordPress from http://wordpress.org/download/.

    2. Untar or unzip the download and change to the base directory, usually “wordpress”.

    3. WordPress Security Keys are a set of random variables that improve encryption of information stored in the user’s cookies. Self-hosted WordPress deploys do not have the Security Keys defined by default. When you create and use a set of random variables, you’re changing the way that WordPress encrypts cookie data which in turn helps improve the security of the site.  We will populate a separate file called wp-salt.php with a set of random variables generated using the WordPress Online Salt Generator found @ https://api.wordpress.org/secret-key/1.1/salt/ and then require its inclusion within the wp-config.php file.

    4. From the base directory (e.g. “wordpress”), run

      #Create a file named wp-salt.php and append it with the string <strong>&lt;?php</strong> <br /><span style="color: #000080;">echo "&lt;?php" &gt; wp-salt.php<br /></span>
    5. Followed by ….

      #Fetch a series of automatically generated define statements and append it to the wp-salt.php file  <br /><span style="color: #000080;">curl https://api.wordpress.org/secret-key/1.1/salt/ &gt;&gt; wp-salt.php</span>
    6. One of the most important files in a WordPress installation is the wp-config.php file. This file is located in the root of a WordPress file directory and contains the WordPress website’s base configuration details, such as database connection information.  For the BlueMix platform, database connection information is dynamically generated during service instantiation and shared within environment variables.  Therefore, a config file structured to read the MySQL environment variable details is necessary. Insert or replace the wp-config.php within the WordPress directory with the one from this github repository

    7. Using the cloud foundry v6 cli, login to BlueMix and deploy your modified WordPress files using a PHP buildpack runtime.   To accomplish this, execute the command-line steps 0 – 4 outlined below. NOTE: <<random number>> is user provided input.

      # Browse to the root directory of your WordPress files <br /># Step 0: cf login -a &lt;api target url&gt; <br />$ <span style="color: #000080;">cf login -a https://api.ng.bluemix.net</span><br /><br>
      # Step 1: cf create-service &lt;service name&gt; &lt;service plan type&gt; &lt;unique service instance name&gt;<br />$ <span style="color: #000080;">cf create-service mysql 100 mysql-wordpress-service</span><br /><br /># Step 2: cf push &lt;unique application name&gt; -b &lt;url to php buildpack&gt; --no-manifest (No manifest.yml present) --no-start (Don't start application after push)<br /># Buildpack choices:  <br />#  Basic - https://github.com/dmikusa-pivotal/cf-php-build-pack.git<br />#  ZLib Support (Gzip compression)- https://github.com/cyberdelia/heroku-buildpack-php.git<br>
      $ <span style="color: #000080;">cf push mysql-wordpress-&lt;&lt;random number&gt;&gt; -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git --no-manifest --no-start</span><br /><br /># Step 3: cf bind-service &lt;unique application name used in Step 2&gt; &lt;service instance name used in Step 1&gt;<br />$ <span style="color: #000080;">cf bind-service mysql-wordpress-&lt;&lt;random number&gt;&gt; mysql-wordpress-service</span><br /><br /># Step 4: cf start &lt;unique application name used in Step 2&gt; (Start application)<br />$ <span style="color: #000080;">cf start mysql-wordpress-&lt;&lt;random number&gt;&gt;</span>
    8. Once the push is finished, navigate to http://yourapp.ng.bluemix.net/wp-admin/install.php to set up wordpress.

    9. That’s it!.

Please note:  At this time, BlueMix does NOT provide persistent file storage. In order to have custom themes and plugins persist with your instance of WordPress, you should save those themes and/or plugins within the application folder prior to pushing your application.

FAQ

Q:  What does the text content look like when issuing the command curl https://api.wordpress.org/secret-key/1.1/salt/

A:  Example.  Data collection changes with each subsequent refresh

Data collection changes with each subsequent refresh

Q:   BlueMix indicates that my application is running.  But I’m getting a blank page when browsing to the application route and I get a 404 “/install.php not found error”.  When I look into BlueMix’s stdout.log file, I see messages about a PHP Parse error:  syntax error, unexpected ‘ ” ‘  (quote character).

BlueMix indicates

A:  While rare, this can happen when double quote characters are inadvertently stored during the creation of wp-salt.php (Step #3).  Inspect the file and remove any double quote characters that may be wrapping the <?php text in the first line.

Be the first to hear about news, product updates, and innovation from IBM Cloud