Hacks and Hints TechieVarta

Icon

Another Techie Varta

Archive for the ‘Blog Software’ Category


Backing up Wordpress MU Site

Monday, February 9th, 2009

Several of us don’t have need for and enthu for an elaborated backup system. Here is a small script that will backups the WPMU site including database and the file system and e-mails it to provided e-mail address. For small site this works perfectly. You can also use it to e-mail the backups to Gmail or msn mail. For automatic backup you can add this script to crontable of your host.

#!/bin/bash
DB=mu
WPMU_ROOT=/srv/www/mu-blogs

dirname=mu-backup-`date +”%m-%d-%y”`
cd /tmp
tmpdir=${dirname}

email=foo at bar . com

/bin/cp -R $WPMU_ROOT $tmpdir
/usr/bin/mysqldump mu > $tmpdir/db_backup.sql

/usr/bin/tar cfz $tmpdir.tgz $tmpdir

echo “Backup of WPMU $dirname” | /usr/bin/mail $email -s “WPMU Backup $dirname” -a $tmpdir.tgz
rm -rf $tmpdir*

Wordpress MU: Latest Posts on a single Page

Sunday, February 1st, 2009

One of the thing I had to decide is the main blog page on my new WordPress Mu site. I decided that I wanted this page to show off latest posts from all the blogs.Using Sitewide Tags was not an option since that does not have a way to import existing posts. I eventually decided to hack my own solution.

Doing this involved some PHP hacking, googling and WPMU Feed plugin. The overall design of the page now uses WPMU Feed to send site-wide post feed. This main page just uses this feed to display posts First download the WPMU Feed plugin and install it. I host feed plugin to http://techievarta.com/feed/.

I cloned my theme to create another copy used by the main site. Than I changed index.php to use the feed. A typical index.php looks like the following:


if there are posts

      show posts;

else

    show error;

endif

The changes required removing else part. So the new index.php looks like”:


if there are posts

     show posts;

endif

<-- Catch the feed and display --->

To catch the feed and display, the code (which is based of feed.php of wordpress installation) looks like the following:


 if ( $rss = fetch_rss( 'http://<site>/feed/',20 ) ) {
       echo '<ul>';
       if ( $num_items !== -1 ) {
          $rss->items = array_slice( $rss->items, 0, $num_items );
       }

       foreach ( (array) $rss->items as $item ) {
          printf('<a href="%1$s" ><h4>%2$s</h4></a><p/>',
             clean_url( $item['link'] ),
             htmlentities( $item['title'] )
             clean_url( $item['link'] ),
             htmlentities( $item['title'] )
          );
         echo "Published ";
         echo $item['pubdate'];
         $dc = $item['dc'];
         if( !empty($dc)){
           echo ' by ';
           echo attribute_escape(  $dc['creator']  );
         }
         echo '<p/>';
         echo attribute_escape(  $item['description']  );
         echo '<p/><br/>';
     }
     echo '</ul>';
 }

Replace <site> with your site’s URL and 20 with number of the contents you want.

Happy Blogging!

Installing Wordpress Mu

Sunday, February 1st, 2009

I recently consolidated several of my blogs to a single WordPress Mu blog site. This allowed me to have a streamlined single user and site administration across all my blogs. Wordpress Mu which stands for WordPress Multi User, is implemented as an extension to our beloved WordPress suite and can run most of the WordPress plugins and themes although there are differences.

Installation

  1. Download latest WordPress Mu from the dowload site.
  2. Unzip WordPress Mu to a place where your web server can find it.
  3. Configure the web server and point it to the Mu site. For Apache the configuration looks like:
  4. 
    <VirtualHost>
     DocumentRoot /srv/www/mu-blogs
     ServerName example.com
     ServerAlias *.example.com
     ServerAdmin root@localhost
      AllowOverride FileInfo Options
     # AllowOverride All
      Order allow,deny
      Allow from all
     CustomLog /var/log/apache2/mublogs-access_log combined
    </VirtualHost>
    

    Look at ServerAlias directive. This allows blogs to have addresses of the form <blogname>.example.com.
    If you would rather use the blog names of the form:
    example.com/<blogname>, you don’t’ need to add the server alias directive.

  5. Now make sure DNS for *.example.com correctly points to your site.
  6. Point the browser to your newly created site, answer simple question and let WordPress Mu install the site and the site is up and running.

Themes

Most of the WordPress themes should work with WordPress Mu theme. For themes to be available for individual blogs, they must be enabled in the admin menu. I wanted all my blogs to use the same theme and did not want to manually edit theme setting in every blog. To achieve this, I replaced the default theme with the theme of my choice. Any future created WordPress blog will automatically inherit the default theme.

Plugins

One thing you noticed when installing plugins is that MU has two plugin directories: <wordpressroot>/wp-content/plugin and <wordpressroot>/wp/content/mu-plugin. Any plugin placed in the <wordpressroot>/wp-content/plugin are available to every blog but still must be activated just like any normal wordpress plugins. The mu-plugin directory is special. Any plugin placed in this directory is automatically activated and all the blogs automatically get it. In addition WordPress Mu does not scan subdirectories under mu-plugin directory. The plugin’s php must be directly placed in the mu-plugin directory.

Happy Blogging!

Drupal: Impressions and Plugins

Saturday, November 3rd, 2007

Readers of this site know that this site runs WordPress for theblogs. Today I want to talk about what I run for my web site. I use great Web Site management software called Drupal. Both WordPress and Drupal are similar in several aspects. Like WordPress, this software is written in PHP and can use MySql as the backend. Both the software are extensible using modules and have a wide variety of modules providing various extensions. Both software allow themes and have a wide variety of themes available.

However, there are several key differences. Drupal is full WebSite management software which also has a blog management feature. WordPress on the other hand is a blog only software and does a great job at it. I could have used Drupal for blog however, I found WordPress before I found Drupal and I was already running WordPress before I built my main site. I am extremely happy with WordPress and do not see a reason for change. I have not experimented with Drupal’s blog feature to know more.

To use Drupal, you should install several plugins.

Essential Drupal Plugins

Site Management Related Modules

  • Category: This software allows you to hierarchically structure your site in tree-like structure. It automatically builds menu as needed.
  • Path Auto: This module automatically creates your URL alias based on page titles and various rules. this can significantly increase search engine ranking.
  • Global Redirect: If path aliases are enabled, the pages on your site are generally accessible using two different paths: default Drupal path and alaised path. This module changes that such that the default Drupal URL results in sending a redirect to the aliased page rather then serving the page. This makes sure that your site is not unnecessarily put in sandbox by Google.

Search Engines Related Plugins

  • Google Analytic: This module provides support for Google Analytics
  • GSiteMap: This module provides on demand Google sitemap generation.

Content Creation Related Plugins

  • TinyMCE: This plugin brings in rich WYSIWYG editor inside Drupal for content creation.
  • Image: : This module allows users to manage Images inside Drupal.
  • Upload Image: This module allows users to upload images on the Drupal website.
  • Weather: I wanted to display weather on my Drupal site. I tried this module and found it to be not very useful. I eventually ended up creating a custom modules. After trying HTML code from Weather.Com and AccuWeather.com, I ended up using AccuWeather.com’s weather related HTML in my custom module.

What I did not like about Drupal?

The Drupal software menu system is non-intuitive. “Site-Building” what does that mean? Modules are enabled in “Site Building” and configured in “Site Configuration”. I wished there was a way to configure the modules as a button as soon as they were enabled. With software like Drupal, you land up with 10s of module. I wish there was a way to organize modules in categories.

The way user authorization is separated from actual module configuration is another thing I don’t like. It is nice that you can see authorization level at a single place, but equally nice will be a way to configure authorization level whenever a module is configured. I suggest that we provide a method to configure authorization both in module level and in user management section.

Drupal and WordPress on the same Site

The great advantage of Open Source Software is that the users have choice. I can run software from different sources and use their strongest parts to come up with a very useful end result. I and based on my reading from the web many others, believe that Drupal is great site management tool and WordPress blogging infrastructure is superior to that of Drupal’s . It is rather easy to run Drupal and WordPress on the same server however it is very difficult to run them in integrated fashion. It will be wonderful to develop a WordPress Module for Drupal and have WordPress site inherit Drupal’s theme or even have its own theme. But, that way they can share the same users.

Another area where the integration will be useful is in sitemap generation. It will be good if there was a way to have Drupal’s sitmap include WordPress sitemap. I had to do some php hacking to get that working.

Wordpress essential plugins

Wednesday, October 31st, 2007

As the readers of this site know, I use WordPress as the blog management software. One of the great things about WordPress is its capability to use plugins. The WordPress websites includes 100s of plugins. This is the great thing about the open source software. It gives you choice. You editor tested several different plugins before came up to the list of plugins for this site and will like to share it with you. Here is the list:

  • Next Gen Gallery: If you are going to host several pics on your site, you need this plugin. It allows easy organization of your album and allows you to select one of the several effects for your pics.
  • WordPress Video Plugin: If you like including YouTube, Google video, etc. on your sites, you want this plugin, unless of course you want to start coding in HTML which I don’t necessarily enjoy.
  • Enhanced Links: The default presentation of links in WordPress is pathetic specially if you want any significant number of links on your site. This plugin makes job of managing links significant easier.
  • TinyMce Advanced: The visual editor for WordPress is called TinyMCE. This plugin enables several new toolbar buttons for your site.
  • WP Cache: As the name suggests, this plugin significantly improves performance of your WP site.
  • Google Sitemap Generator: This plugin generate sitemap.xml for your site and informs all major search engines about it.
  • All in one SEO Pack: This pack tries to optimize your site for major search engines.
  • Ultimate Google Analytics: This provides an easy way to use Google Analytics with WordPress sites.
  • WordPress.com Stats: This plugin provides another useful way to mine users of your site.

Wishlist

I wish there was a plugin which rewrote the URL to something clearer.  Something like clear url for Drupal.

Create a full featured web/blog host at your home: Part 2

Thursday, October 25th, 2007

Part 1

As promised here is the part 2 of the post.

Setting up Web Server

The next task is to setup your web server. There are several servers you can choose. My favorite is Apache. It comes bundled with most Linux distributions. You probably want to setup the apache server as a virtual host. To setup the virtual server, fire up your favorite editor to configure apache configuration and add something like the following:

<VirtualHost  *:80>
	DocumentRoot /srv/www/htdocs
	ServerName example.com
	ServerAdmin root@localhost
	<Directory /srv/www/htdocs>
		AllowOverride None
		Order allow,den
		Allow from all
	</Directory>
	CustomLog /var/log/apache2/example.log
</VirtualHost>

Restart apache by doing something like /etc/init.d/apache restart. If you took my earlier warning about security seriously, you would have firewall on your server blocking all accesses to your web server. Use your favorite firewall management tool for the server to open hole through server firewall. Suse’s yast makes this process relatively straightforward. I am sure other distributions have something similar.

Edit /etc/hosts on the web server machine and add a host entry for the web server’s IP address as your machine’s NATed IP address. This step is not absolutely essential but it makes life a lot simpler. Fire up firefox on the Linux machine and make sure you can access http://<your-machine’s name>/. If you try to access the same web page from another machine in your network, this is probably very slow. That is because the DNS is resolving your machine’s the hostname as external IP address of your NAT box and the packets are not directly going to your Linux machine. If you have this problem open /etc/hosts on Linux and c:\windows\system32\drivers\etc\hosts on Windows machine and add an entry with webhosts name and its NATed IP address. The entry will look something like:

 192.168.32.8    example.com

At this time you should be able to go to the newly configured host and access the web site. You are now ready to configure blog software.

Setting up Blog Software

Now it is time to setup you blog software. After evaluating several blog software, I decided to use WordPress. I will strongly recommend WordPress to nearly everyone trying to host their blog site. It is easy to administer. There is a very strong community out there. You can easily find plugin for almost anything you want to do. WordPress is based on PHP so make sure you have PHP installed before you start. WordPress also has dependency on MySql make sure you have MySql installed. The next step is to create MySql user.

To create the MySql user do the following:

>mysql -u root -p

Password: <enter mysql password>

mysql>create <db-name>

mysql>use <db-name>

mysql>GRANT ALL PRIVILEGES ON *.* TO

        '<user>'@'localhost' IDENTIFIED BY

        '<db-pass>' WITH GRANT OPTION;

Note down the db-user and db-pass entered in this process.

You are now ready to configure and install the WordPress. Download WordPress and unzip it at a place where your webserver can serve. In the wordpress home directory, there is a file wp-config-sample.php. Copy it to wp-config.php. Edit this file to provide DB name, DB username and DB password.

Fire your Web Browser and point it to the blog’s home directory. Follow on screen direction to complete the WordPress install. You are all set. Drop me a word if you have problem installing.

Happy blogging.

Next time essential WordPress plugins.

Running Multiple WordPress blogs on the same machine

Monday, October 22nd, 2007

My initial plan was to divide posts by categories and not create blog per category. But it quickly became clear that this option was rather limiting since my wife’s and my interest are very different and two of us have variety of interests of our own. WordPress by default allows only one WordPress blog per machine.

To create new blog we had to do the following:
- Move existing blog to a new location
- Create a new blog

To move existing blog to a new location, first I moved directory from base blogs directory to blogs/Random (new home for the blog) directory. When I retried logging on to the site, I was presented with logon screen without any graphics. I tried logon with success and click on options/general and configured new location for the blog. After submission everything works.

The next step was to create a new blog. I started by unzipping the WP code in the new location. There are two ways to create a new blog. Either you can create a new database (one per blog) or you can keep one database and create new table prefix. I decided to use a different table prefix for every blog. Based on what you decide edit wp-config.php to reflect the decision.

Follow usual installation process and you have created multiple blogs on the same site.

Now I have another Technology blog . Future WordPress related blogs go in there.
Good luck!