WordPress

WordPress is one of the most popular blog platforms out there. WordPress works out of the box on DotCloud; but some features (like permalinks) require some specific setup. We will describe here how to install WordPress on DotCloud on a “best practice” basis.

Deploy the stack

WordPress usually runs on PHP + MySQL. Therefore, we will need to deploy a PHP service and a MySQL one:

$ dotcloud deploy -t php louis.wordpress
$ dotcloud deploy -t mysql louis.mysql

Note

Replace louis.wordpress and louis.mysql with the deployment names of your choice.

Download and configure WordPress

Download WordPress, and unzip it:

$ wget http://wordpress.org/latest.zip
$ unzip latest.zip

Everything should have been decompressed into a “wordpress” directory.

We need to edit “wp-config.php” to configure the database, some magic WordPress variables, and the language of your blog.

First, retrieve your database parameters with the following command:

$ dotcloud info louis.mysql
cluster: wolverine
config:
    mysql_password: U9a6FgZ3
deployment: sanfran
name: sanfran.db
ports:
-   name: mysql
    url: mysql://root:U9a6FgZ3@mysql.louis.dotcloud.com:1234
-   name: ssh
    url: ssh://dotcloud@mysql.louis.dotcloud.com:1235
type: mysql

Copy wp-config-sample.php to wp-config.php, and open the wp-config copy in your favourite editor.

Edit the following lines:

/** The name of the database for WordPress */
define('DB_NAME', 'mysql');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'U9a6FgZ3');

/** MySQL hostname */
define('DB_HOST', 'mysql.louis.dotcloud.com:1234');

Note

To simplify setup, we do not create a database and user for our WordPress blog: we will be using the built-in database “mysql” with the “root” user. It will certainly look weird for those of you used to MySQL administration; but if you do not plan to use this MySQL server for anything else, it does not matter if you use the “root” user.

Note

Be careful to include the port of the MySQL server (in our example it is 1234). Also, be careful to select the host and port on the mysql:// line, not the ssh:// line.

A little farther in the wp-config.php file, you will see a section similar to the following one:

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

Point your browser to https://api.wordpress.org/secret-key/1.1/salt/ (or just run “curl https://api.wordpress.org/secret-key/1.1/salt/”) and use the lines generated by the online service.

Note

If you want to install WordPress in your own language, just download the corresponding tarball and follow the same instructions. We already verified that it worked with the french version of Wordpress!

Add DotCloud specific files

WordPress will need to create all sorts of files while it is running: when you upload a media file, but also if you install a plugin through the web administration interface.

If we don’t do anything special, those files will be erased each time you do a new “dotcloud push”. We could chose to never do “dotcloud push” again, but that would bar you from leveraging all the power of DotCloud, should you decide to tweak or scale your blog. So let’s see how we can work around that.

We are lucky, because all those files are located under the “wp-content” subdirectory. So we just have to take care about this specific directory. Create the following script, “wordpress/postinstall”:

#!/bin/sh
if [ -d ~/data/wp-content ]
then
      rm -rf ~/current/wp-content
else
      mkdir -p ~/data
      mv ~/current/wp-content ~/data/wp-content
fi
ln -s ~/data/wp-content ~/current/wp-content

The “postinstall” script is run each time you push your code to DotCloud. The first time, it will move the “wp-content” directory in a safe place (straight under /home/dotcloud), and replace it with a symbolic link. From the second time you push (and onwards), the symbolic link will just be recreated.

Don’t forget to set this script as executable:

$ chmod +x wordpress/postinstall

If you want to enable nice permalinks (i.e., http://www.myblog.com/my-post instead of http://www.myblog.com/?p=123), you also have to create the file “wordpress/nginx.conf” with the following line:

try_files $uri $uri/ /index.php;

Push your WordPress install to DotCloud

Just run the following (from the wordpress directory):

wordpress$ dotcloud push louis.wordpress .

Then go to http://wordpress.louis.dotcloud.com/: you will be prompted to create the admin user for your blog.

Note

The admin login and password are stored in the database. Therefore, they won’t be erased if you do a “dotcloud push” again.

Your blog is ready!

Plugins installation and setup

You can safely install WordPress plugins from the admin dashboard. The PHP code for the plugins is downloaded into the “wp-content” directory, which will not be touched by “dotcloud push”, thanks to our custom postinstall script.

WordPress upgrades

If you perform a WordPress upgrade through the online dashboard, it will be undone next time you do a “dotcloud push”. The preferred way to upgrade is to:

  • fetch the latest source zip,
  • uncompress it,
  • copy over wp-config.php, postinstall and nginx.conf,
  • “dotcloud push” the new directory.

Note

If you upgrade WordPress (or a plugin) through the online dashboard, you should use “dotcloud restart” on your service to ensure that the PHP opcode cache gets correctly reloaded.

Back to Contents

Previous: Resque Next: Deploying a Celery worker on DotCloud