20130806 notes on configuring hyperdb - plembo/onemoretech GitHub Wiki

title: notes on configuring hyperdb link: https://onemoretech.wordpress.com/2013/08/06/notes-on-configuring-hyperdb/ author: phil2nc description: post_id: 6209 created: 2013/08/06 22:09:32 created_gmt: 2013/08/07 02:09:32 comment_status: closed post_name: notes-on-configuring-hyperdb status: publish post_type: post

notes on configuring hyperdb

HyperDB is a plugin for WordPress that enhances the shipping database connection class. My main interest is its support for connections to MySQL master and slave servers. The scenario here involves a pair of web servers that both point at a common NAS share that WordPress has been installed onto. To establish some semblance of high availability we created a master/slave MySQL database infrastructure that WordPress could reach from either web server. HyperDB ships with 2 files that are not automatically installed upon upload. In fact this is one plugin that can probably be deployed more easily by downloading (or uploading) via a terminal session on the web server. db-config.php contains the configuration for the plugin and belongs in the root of the directory WordPress is installed in (e.g. /nas_p/html/wordpress). db.php is the actual database management script that needs to be installed to the wp-content directory (e.g. /nas_p/html/wordpress/wp-content). Here is a really simple master and slave setup that starts at line 217 of the shipping db-config.php file (all other parameters are set to the defaults): [code language="php" firstline="217"] $wpdb->add_database(array( 'host' => 'host1.example.com', 'user' => DB_USER, 'password' => DB_PASSWORD, 'name' => DB_NAME, )); /** * This adds the same server again, only this time it is configured as a slave. * The last three parameters are set to the defaults but are shown for clarity. / $wpdb->add_database(array( 'host' => 'localhost', 'user' => DB_USER, 'password' => DB_PASSWORD, 'name' => DB_NAME, 'write' => 0, 'read' => 1, 'dataset' => 'global', 'timeout' => 0.2, )); [/code] Note that my master and slave MySQL databases each have a user named "wpadmin" with the same password. This user has been granted full rights over the WordPress database. There are three entries and sets of privileges for the user: one for "wpadmin@localhost", and the others as "[email protected]" and "[email protected]". This allows the wpadmin user from either server to connect to the database on the other. Also note that I have specified the FDQN for the master server and 'localhost' for the slave (both servers are mapped in each others /etc/hosts just in case DNS goes down/becomes unavailable). In each case the host name is enclosed in single quotes. Many thanks to alfred for his most excellent article on this subject, How to: Deploying WordPress over multiple servers for load balancing. It really cut through all the noise in the official (and unofficial) doc out there and set me on the right path to getting it done. God, I love the Internet! *You could use "wpadmin@%.example.com", allowing connections from any host in the .example.com domain, but unless you're limiting network access to the servers (using firewalls), it would be a less secure choice.

Copyright 2004-2019 Phil Lembo