At the risk of profiling myself as some script kiddie .. here are my my notes on installing WordPress and its dependencies under Fedora Linux. It touches the surface of my plug-ins such as NextGEN Gallery, CAPTCHA, Google Docs, PHP Execution, playing video and migrating the web site.
Install dependencies
WordPress is a framework for HTTP, PHP and JavaScript. It keeps a database to store dynamic information such as posts. For the database we will install MySQL; for the HTTPd we will install Apache; and we will add PHP to that mix.
My host (called www.vonk) runs Fedora 12 Linux. This is also my development system, that does not run SELinux. If you have SELinux enabled, you most likely will have to punch some holes in the firewall (http, https, ftp, ssh), and you may have to change some permission (/sbin/restorecon -R -v /var/www/html/uP/wp-content/themes).
HTTPd, MySQL, PHP and FTPd
Prepare the environment for WordPress by install the web server (Apache), database server (mysql-server), PHP and FTP server (vsftpd). (details at catsgarden.com or fedorasolved.org.)
[cvonk@linux]$ sudo su
yum -y install httpd system-config-httpd
service httpd start
chkconfig httpd on
mozilla http://www # give httpd it a spin, should show the test pageyum -y install mysql mysql-server php php-mysql mcrypt # mod_python MySQL-python perl mod_perl perl-DBD-mysql
service mysqld start
chkconfig mysqld on
echo “<?php phpinfo(); ?>” > /var/www/html/phpinfo.php
mozilla http://www/phpinfo.php#module_mysql # give mysqld/PHP/httpd a spin
rm /var/www/html/phpinfo.phpyum -y install vsftpd
service vsftpd start
chkconfig vsftpd on
ftp www
exit
Change the mysql admin account to your user name, assign a password and disable anonymous access (more infor about security here).
[cvonk@linux]$ mysql -u root -p # or “mysqladmin -u root -poldpasswd” if you already have a password
status;
show databases;
drop database test; [removes the test database, assuming you have one]set password for root@localhost=password(‘newpasswd‘);
use mysql;
update user set user=”cvonk” where user=”root”;
delete from mysql.user where user = ”; [removes anonymous access]flush privileges;
exit;
First things first. Make sure your databases will be included in a backup by adding the command below to your cron jobs (details here).
mysqldump –all-databases –password=yourpassword | gzip > /var/backup/all-databases-`date -I`.sql.gz
MySQL web interface (phpmyadmin), Optional
If you prefer a graphical interface to MySQL, then phpmyadmin is your answer (details here).
yum -y install phpMyAdmin
Configure (vi /etc/httpd/conf.d/phpMyAdmin.conf)
# under <Directory /usr/share/phpMyAdmin/>, add “from 10.0.1.200″, or whatever the address of your system
service httpd reload
vi /etc/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['auth_type'] = ‘http’; // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user'] = ‘USERNAME’; // MySQL user
$cfg['Servers'][$i]['password'] = ‘PASSWORD’; // MySQL password (only needed
Install WordPress
Finally, it is time to install WordPress (details at wordpress.org).
[cvonk@linux]$ sudo su -m apache
cd /var/www/html
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress uP # change to whatever name you want (I use uP for micro processor stuff)
mkdir wp-content/uploads
exit
Create a database for our WordPress page.
[cvonk@linux]$ mysql -p
create database uP;
grant all privileges on uP.* to “cvonk“@”localhost” identified by “password“;
flush privileges;
exit;
create a configuration file
configurationdatabase name = uP
user name = cvonk
password = password
database host = localhost
database prefix = wp_run the install
blog title = Coert Vonk’s personal site
your email = youremail@provider.com
Username = cvonk
Permalinks
We will start by enabling permalinks using the structure “/%category%/%postname%-%post_id%”. I had to add the lines below to the httpd configuration (/etc/httpd/conf/httpd.conf), and instruct httpd to reload (service httpd reload).
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
</Directory>
We can then enable the permalinks to “Month and name” using Dashboard > Settings > Permalinks.
WordPress basics and your first post
There are posts and pages. Assuming permalinks is enabled (see below), the posts show up under the category name. Pages are typically used for static content such as Contact information.
The information typically shown in the side bars is generated by widgets. You can add them using Dashboard > Appearance > Widgets.
Write a post using Dashboard > Posts > Add New. You can either use the Visual editor, or write raw HTML code. Make sure you assign a category, and probably some tags, and press publish. Most themes will show the categories on the top of the page, so you can easily navigate to them.
Theme
Next we add our new theme using the same control interface, Dashboard > Appearance > Add New Theme. There is a magnitude of choices. I like “Atahualpa” for its top wide image and options for customization. Activate the new theme through the Dashboard > Themes. The theme can be tweaked through the Dashboard > Appearance > Atahualpa Theme Options.
Plug-ins
Again there are many choices here. My favorites are NextGEN Gallery, ReCAPTCHA Form, WP-reCAPTCHA, Embed Iframe, Inline Google Docs, Lightbox 2, PHP Execution and WP Gallery EXIF Reader. They can be installed through Dashboard > Appearance > Plugins > Add new. I will describe their usage in the paragraphs below.
NextGEN Gallery
I recently switched from Gallery2/WPG2 to NextGEN. The latter is much easier to configure, and offers all the functionality that I was looking for. Before installing the plug-in, we need a graphic PHP library.
[cvonk@linux]$ sudo yum install php-gd
Install the NextGEN plugin, and download the JW Image Rotator and copy its “imagerotator.swf” to the NextGEN Gallery plugin director (/var/www/html/uP/wp-content/plugins/nextgen-gallery). NextGEN is controlled through Dashboard > Gallery.
There is an important distinction in NextGEN Gallery. A “gallery” is a collection of images, often taken on a particular day. An “album” is a collection of galleries, such as photos taken during a specific vacation.
Start by upload some images using a flash enabled browser. Dashboard > Gallery > Add gallery/images and note the assigned gallery number.
Create a post under the new category Photography (details here). If you are editing in HTML mode, add the line
to show thumbnails of the pictures in gallery 1. In Visual mode you can simply click on “Add NextGEN gallery > Image list”. Everything after <!–more–> will not be shown in the excerpt.
This is a small selection from my photos taken in the USA or while travelling abroad. It includes pictures from my favourite hikes in the Sierra Nevada mountains; travels through in Middle East and Asia, the Netherlands, England, Wales, Scotland, France and Switzerland.
<!–more–>
Remember to copy the .css files to your theme directory!
NextGEN plug-in ImageFlow
Use the shortcode [imageflow id=1]
NextGEN plug-in FlashViewer
- Install and activate NextGen FlashViewer
- Go to airtightinteractive.com and download the SimpleViewer, Tiltviewer, AutoViewer and PostcardViewer
- Extract the .swf files from the archives
- Rename “viewer.swf” from the PostcardViewer archive to “pcviewer.swf”
- Rename “simpleviewer.swf” to “viewer.swf”
- Create the directory wp-content/plugins/nggflash-swf, and upload the *.swf files there
- Using WordPress’ dashboard, go to Gallery->FlashViewer and change the options to suit your needs.
- shortcodes are:
- [Gallery not found]
- [Gallery not found]
- [Gallery not found]
- [Gallery not found]
Organize series
Specify the series at the bottom of each posting/page.
Tweak for my theme, vi wp-content/plugins/organize-series/series.php
at the top of the file
<?php
include (TEMPLATEPATH . ‘/functions/bfa_get_options.php’);
require(‘./wp-blog-header.php’);at the bottom of the file
<?php get_footer(); ?>
<?php bfa_center_content($bfa_ata['center_content_bottom']); ?>
WP-reCAPTCHA
yum install mcrypt php-mcrypt
To prevent automated postings, or either force the users to create a login, or use a WP-reCAPTCHA.
you can use the To protect your email address, iInstall and activate “WP-reCAPTCHA” plugin (details here), and enter your key.
WP Dashboard > Aperance > Widgets and drag’n'drop
reCAPTCHA Form
To prevent automated postings, or either force the users to create a login, or use a WP-reCAPTCHA. In this case, I will use CAPTCHA Form for a contact page. Install and activate this plugin. Then configure it using Dashboard > Settings > reCAPTCHA Form. Create a contact page using Dashboard > Pages > Add New.
You can contact me using the form below, or through linkedin or facebook.
PHP Execution
This plugin allows you to embed PHP code inside a post of page. Embedded php code will be executed when the post is shown. In doing so, the plugin offers the possibility to utilize dynamic content inside of posts. Two examples are my Recipes that pulls information from a MySQL database and the calculator in my Endurance Running article. Here is an easy start:
<?php phpinfo(); ?>
Below is a more advanced example showing access to a MySQL database. A slightly more enhanced version is available as a plug-in (download).
The vast majority of these over 400 recipes are vegetarian. While many originate from external sources, most are adjusted to fit our personal taste and ingredients available in our area.
<!–more–>
We use Electronic Recipe Manager for our recipes and menus. To make them accessible from this web site, I migrated these recipes to a <a href=”http://www.mysql.com”>mysql</a> database.
<?php
// Display information from the “recipe” database
//
// The behaviour of this function depends on the parameters passed
// no parameters passed
// displays a list of all recipes
// title=brood
// displays all recipes with “brood” in the title
// id=12
// displays the recipies with ID=12
//
// The original recipes are kept in a MS Access Dbase, and have
// been migrated to MySQL using the Migration Tool.
//
// Display this as a “full post”. When displayed as excerpt, the hyperlinks
// and other formatting will be lost.
//
// November 2009, Coert (dot) Vonk (at) gmail (dot) com$db_host = “ws.vonk”;
$db_user = “apache”;
$db_pass = “iw2bipdx”;
$db_name = “recipes”;if (!extension_loaded(‘mysql’)) {
$prefix = (PHP_SHLIB_SUFFIX === ‘dll’) ? ‘php_’ : ”;
dl($prefix . ‘mysql.’ . PHP_SHLIB_SUFFIX);
}$id = $_GET['recipe'];
// $search = mysql_real_escape_string( $_GET['title'] );
$title = $_GET['title'];
$sort = $_GET['sort'];mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());function isEmpty($par) {
return ($par == “” or $par == “—” or $par == “00:00″ );
}if ( ! is_numeric( $id ) ) {
if ( $title != “” ) {
$where = “WHERE r.title LIKE ‘%$title%’”;
} else {
$where = “”;
}// display all the recipe titles, when no specific recipe was specified
if ( $sort == “” ) {
$sort = “title”;
}
// $query = “SELECT COUNT(*) FROM recipe”;
// $result = mysql_query($query) or die(mysql_error());
// $count = mysql_fetch_row($result);
// echo ”
//<p>The vast majority of these $count[0] recipes are vegetarian. While many originate from //external sources, most are adjusted to fit our personal taste and ingredients available in our //area.</p>n
//<p>We use Electronic Recipe Manager for our recipes and menus. To make them accessible //from this web site, I migrated these recipes to <a href=’http://www.mysql.com’>mysql</a>//</p>\n”;$query = “SELECT r.* FROM recipe r $where ORDER BY r.$sort”;
$result = mysql_query( $query ) or die(mysql_error());
echo “<table border=’0′>\n”;
echo “<tr><th><a href=’?sort=title’>Title</a></th>”.
“<th><a href=’?sort=cuisine’>Cuisine</a></th>”.
“<th><a href=’?sort=category’>Category</a></th></tr>\n”;
while ($row = mysql_fetch_array($result)) {
echo “<tr><td>”.
“<a href=’?recipe=$row[ID]‘>”.
“$row[title]</a></td><td>$row[cuisine]</td><td>$row[category]</td></tr>\n”;
}
echo “</table>\n”;} else {
// display the recipe identified by $id
// display the recipe header
$query = “SELECT r.* FROM recipe r WHERE ID=$id”;
$recipe = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($recipe);
echo “<h3>”. $row['title']. “</h3>\n”;if ( ! isEmpty( $row['notes'] ) ) {
echo “<p>”. $row['notes']. “</p>\n”;
}// print the fields that we are interested in
$head_array = array ( “source”, “category”, “cuisine”, “servings”, “prep_time”, “cook_time” );
echo “<table border=’0′>\n”;
foreach($head_array as $value) {
if ( ! isEmpty( $row[$value] ) ) {
echo “ <tr><td>$value:</td><td>$row[$value]</td></tr>\n”;
}
}
echo “</table>\n”;// display the ingredients from the “ingredients” table
echo “<h4>Ingredients</h4>\n”;
$query = “SELECT * FROM ingredients i WHERE recipe_id = $id”;
$result = mysql_query( $query ) or die(mysql_error());echo “<table border=’0′>\n”;
while ($row = mysql_fetch_array($result)) {
if ( ! isEmpty( $row['amount'] ) ) {
$amount = $row['amount']. ” “;
} else {
$amount = “”;
}
if ( ! isEmpty( $row['measure'] ) ) {
$amount .= ” “. $row['measure'];
}
echo “ <tr><td>”. $amount. “</td>”.
“<td>”. $row['ingredient']. “</td></tr>\n”;
}
echo “</table>\n”;// display the directions from the “directions” table
echo “<h4>Directions</h4>\n”;
$query = “SELECT * FROM directions WHERE recipe_id = $id”;
$result = mysql_query( $query ) or die(mysql_error());echo “<table border=’0′>\n”;
while ($row = mysql_fetch_array($result)) {
echo “ <tr><td>$row[step]. </td>”.
“<td>$row[direction]</td></tr>\n”;
}
echo “</table>\n”;
}
?>
Embedded Google Docs
This allows ypi to display contents of Google Documents in pages/posts, using shortcode for markup. Remember to configure your user name and password in its Dashboard. It currently can only access published documents, but can access both private/public spreadsheets.
Create cache directory
mkdir wp-content/plugins/inline-google-docs/cache
touch wp-content/plugins/inline-google-docs/cache/error.log.php
Embed Iframe
I used this for integrating my sourceforge.net pages. Not the cleanest, but it does the job.
FV WordPress Flowplayer
Plays .mp4 video files. Requires a Flash plug-in for your browser:
wget http://get.adobe.com/flashplayer/thankyou/?installer=Flash_Player_10_for_Linux_(YUM)
rpm -Uvh
yum install flash-plugin
I wrote a simple plug-in to demonstrate the integration (download).
Docbook integration
docbook integration
http://el-tramo.be/git/docbook-kit/snapshot/docbook-kit-master.zip
http://el-tramo.be/blog/docbook-kit
Migrating to a different web site
If your /var/www runs full, you can move the contents do another disk, and symlink /var/www to there. For example I symlink it to /home/www. Note in that case /home needs to have x permissions for the world.
I only had success doing so directly in mysql (details here)
[cvonk@linux]$ ( cd /var/www/html ; tar -cvpzf uP ~/uP.tgz ) # backup HTML/PHP pages and content
[cvonk@linux]$ mysqldump -p uP| gzip > ~/uP-`date -I`.sql.gz # backup database
[cvonk@linux]$ mysql -p uP
update wp_options set option_value=replace(option_value,’http://www.vonk/uP’,’http://www.vonk/’);
update wp_postmeta set meta_value=replace(meta_value,’http://www.vonk/uP’,’http://www.vonk/’);
update wp_posts set post_content=replace(post_content,’http://www.vonk/uP’,’http://www.vonk/’);
update wp_posts set guid=replace(guid,’http://www.vonk/uP’,’http://www.vonk/’);
exit
Static home page
Create a new page, and point to it in Settings::reading.
Role Scoper
Used to limit access to certain areas. (I used this to replace Category Visibility-iPeat Rev).
Also add “Role scoping for NextGen Gallery” (rs-config-ngg),
Cookie expiration
Edit wp-includes/pluggable.php:wp_set_auth_cookie(), and change the seconds “120960″ (2 weeks) to whatever you prefer
Google Custom Search
Sign up for Google Custom Search, and pull up its Control Panel. Under “get code”, enter the URL to your search page (i.e. http://www.yoursite.com/search) and your probably want to select the adds on the right. Leave the window open, we will need it later.
In your WordPress theme directory, create the file search.php. Paste the code snippets from the Google Custom Search Control Panel in the corresponding paces.
<?php
include (TEMPLATEPATH . ‘/functions/bfa_get_options.php’);
require(‘./wp-blog-header.php’);
get_header();
/*
Template Name: Search Template
Description: A template for the search page
*/
?><!– Google CSE Search Box Begins –>
<!– Google CSE Search Box Ends –><!– Google Search Result Snippet Begins –>
<!– Google Search Result Snippet Ends –><?php
get_footer();
bfa_center_content($bfa_ata['center_content_bottom']);
?>
Incorporate the Google search box in your theme. For the Atahualpa theme, that means changing the “cse-search-box” form in the “functions/bfa_header_config.php” file. Note that you will need to set the hidden fields to match the “Google CSE Search Box” like in the file above. As you see, I tweaked the form a little bit.
$logo_area .= ‘<div>
<div>
<!– Modified Google CSE Search Box Begins –><form action=”http://www.yoursite.com/search” id=”cse-search-box”>
<div>
<input type=”hidden” name=”cx” value=”valuefromGoogleCustomSearchControlPanel” />
<input type=”hidden” name=”cof” value=”FORID:9″ />
<input type=”hidden” name=”ie” value=”UTF-8″ />
<input type=”text”
onfocus=”this.value=\”.
(get_search_query() ? get_search_query() : ” ).’\'”
value=”‘ . (get_search_query() ? get_search_query() : $bfa_ata['searchbox_text'] ) .
‘” onblur=”this.value=\”.(get_search_query() ? get_search_query() : $bfa_ata['searchbox_text'] ).
‘\’”
name=”q” size=”31″ />
<!– <input type=”submit” name=”sa” value=”Search” /> –>
</div>
</form>
<script type=”text/javascript” src=”http://www.google.com/cse/brand?form=cse-search-box&lang=en”></script><!– Modified Google CSE Search Box Ends –>
</div>
</td>’;
In WordPress create an empty page called Search with permalink “http://www.yoursite.com/search”. Change the page attribute Template to search.php and publish the page.
WP-Syntax
Syntax hilight.
MediaWiki
[cvonk@linux]$ wget http://download.wikimedia.org/mediawiki/1.15/mediawiki-1.15.1.tar.gz
tar -C /var/www/html/uP -xvzf mediawiki-1.15.1.tar.gz
mv uP/mediawiki-1.15.1 uP/wiki
chown -R apache:apache uP/wiki
cd uP/wiki
Create a database for our MediaWiki page.
[cvonk@linux]$ mysql -p
drop database wiki;
create database wiki;
grant all privileges on wiki.* to “cvonk“@”localhost” identified by “wikipassword“;
flush privileges;
exit;
Configure using the web interface, and finish up.
mv config/LocalSettings.php .
WikiMedia and WordPress
Allow WikiMedia to use WordPress for user authentication (details here).
wget http://insites.ingenesis.net/wp-content/uploads/2008/08/authwordpressphp.zip
cd /var/www/html/wiki/extensions/
unzip authwordpressphp.zip
Then add the lines below to your MediaWiki LocalSettings.php file. Be sure to change DBSERVER, DBNAME, DBUSER and DBPASSWORD to the correct settings for connecting to your WordPress database.
## Added for WordPress login support
require_once( ‘extensions/AuthWordpress.php’ );
$wgAuth = new AuthWordpress();
$wgAuth->setAuthWordpressTablePrefix(‘wp_’); // Should match the DB prefix in wp-config.php
$wgAuth->setAuthWordpressDBServer (‘DBSERVER’); // wordpress host (eg. localhost)
$wgAuth->setAuthWordpressDBName(‘DBNAME’); // wordpress database
$wgAuth->setAuthWordpressUser(‘DBUSER’); // wordpress db username
$wgAuth->setAuthWordpressPassword(‘DBPASSWORD’); // wordpress db password
