Notes on Installing WordPress on Ubuntu

All references to XXX should be replaced with the intended name/username for the new blog.

All references to YYY refer to the password for the new blog.

Account and wordpress setup

1
2
3
4
5
6
7
8
9
useradd -d /home/XXX -m XXX -s /bin/bash
passwd XXX
su XXX
cd
wget http://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/ public_html
cd public_html
cp wp-config-sample.php wp-config.php

Edit wp-config with the new database settings and save.

Database setup

1
2
3
4
5
6
mysql -u root -p
create user 'XXX'@'localhost' identified by 'YYY';
create database XXX;
grant all on XXX.* to 'XXX'@'localhost';
commit;
exit;

Add user to www-data group:

1
usermod -a -G www-data XXX

Add user to FTP list.

Edit /etc/proftpd/proftpd.conf:

1
2
3
4
<Limit LOGIN>
AllowUser foosite barsite  XXX
DenyALL
</Limit>

Add .htaccess file to installation directory:

1
2
touch .htaccess
chmod 664 .htaccess

Other notes

Change database password:

1
2
3
mysql -u root -p
SET PASSWORD FOR 'XXX'@'hostname' = PASSWORD('YYY');
flush privileges;

Fix permission on wp-content

1
chown -R www-data:www-data wp-content/
Posted in Uncategorized | Comments closed

I’ve trashed WordPress after an upgrade and my site no longer loads (HTTP 500)! What do I do???

Well, my automatic upgrade to WordPress 3.4 went about as smooth as 30 grit sandpaper. What happened? My guess is that the installer tried to write into a directory that it didn’t have permission to access:

Downloading update from http://wordpress.org/wordpress-3.4-no-content.zip…

Unpacking the update…

Verifying the unpacked files…

Installing the latest version…

Could not copy file.: /usr/share/wordpress/wp-includes/js/tinymce/plugins/directionality/editor_plugin_src.js

Installation Failed

I did the following to fix this problem:

  1. Copied /usr/share/wordpress to /usr/share/old_wordpress
  2. Downloaded the newest, stable version of WordPress and unzipped it into /usr/share/wordpress
  3. Copied wp-config.php from old_wordpress to wordpress
  4. Copied all the plugins from old_wordpress to wordpress
  5. Copied wp-uploads from old_wordpress to wordpress
  6. Removed the default .htaccess file from the wordpress directory and relinked it back to /etc/wordpress/htaccess (ln -s /etc/wordpress/htaccess .htaccess). I needed this, since I rewrite the URL for blog posts.

After bringing up the wp-admin interface, it will prompt you to perform a database update (which I did).

So far, everything seems to be okay, although I will take their warning about backing up before an upgrade much more seriously…

Posted in Uncategorized | Comments closed

log4net: ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.

I ran into this runtime error when attempting to integrate log4net into a project that I was working:

log4net:ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize —> System.Configuration.ConfigurationErrorsException: Only one element allowed per config file and if present must be the first child of the root element. (C:\Projects\Services\MyService\MyService\bin\Debug\MyService.vshost.exe.Config line 9)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
— End of inner exception stack trace —
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
at System.Diagnostics.TraceInternal.InitializeSettings()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at System.Diagnostics.Trace.WriteLine(String message)
at log4net.Util.LogLog.EmitErrorLine(String message)

Well, the culprit turned out to be the order of the sections in my App.config file. I typically put <appSettings> as the first section in that file, but when using log4net, it expects that the <configSections> come before it. The fix for this turned out to be changing the order from this:

...
<configuration>
<appSettings>
   ...
</appSettings>
 
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

To this:

...
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

<appSettings>
   ...
</appSettings>
Posted in .net, C#, coding, log4net, programming, vs2010, Windows, XML | Comments closed

InvalidOperationException when attempting to read from the console

This was a bug that I got today when trying to call Console.ReadKey():

Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.

Well, it turned out to be an issue with the way my project was configured. The fix for this is simple:

  1. Right-click on the project and go to the Properties page
  2. In the Application pane, go to Output type and change it to Console Application
  3. Save the change and hit F5 to run the application again
Posted in .net, C#, coding, programming, vs2010, Windows | Comments closed

Run C# Services on the Console

If you are debugging a C# service or you want to have the flexibility to run a service as a console application, it may be useful to use the Environment.UserInteractive flag:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
static void Main(string[] args) {
    Program p = new Program();

    if (Environment.UserInteractive) {
        p.OnStart(args);

        Console.WriteLine("Example WCF Server");
        Console.WriteLine("------------------");
       
        p.UserInteractiveMode();

        Console.WriteLine("Goodbye!");
        Console.ReadKey();

        p.OnStop();
    }
    else     {
        ServiceBase.Run(p);
    }
}

If you only want to have this ability when debugging a service, you could use the System.Diagnostics.Debugger.IsAttached flag, rather than Environment.UserInteractive:

1
2
3
4
5
6
7
8
9
10
11
12
MyService     myService   = new MyService();
ServiceBase[] serviceList = new ServiceBase[] { myService };

if (System.Diagnostics.Debugger.IsAttached) {
    myService.ConsoleStart(args);
    Console.WriteLine("Press any key to quit...");
    Console.ReadKey();
    myService.ConsoleStop();
}
else {
    ServiceBase.Run(serviceList);
}

For the above example, I needed to provide publically-accessible wrapper methods to start and stop the service manually:

1
2
3
4
5
6
7
public void ConsoleStart(string[] args) {
    OnStart(args);
}

public void ConsoleStop() {
    OnStop();
}

NOTE: The above snippets are only valid for a single service, not multiple ones…

Posted in .net, C#, coding, programming, tasks, Windows | Comments closed

Using /keyfile in place of AssemblyKeyFile

One of the issues I ran into today when building a legacy C# library was the following warning:

Use command line option ‘/keyfile’ or appropriate project settings instead of ‘AssemblyKeyFile’

The offending code was in AssemblyInfo.cs:

1
2
3
#if (!DISABLE_STRONG_NAME)
[assembly: AssemblyKeyFile(@"./Key.snk")]
#endif

I had to do a little research to find out why this was happening, and the best solution I found was provided in this post on the MSDN website:

  1. Open the Properties page for the project.
  2. Click the Signing property page.
  3. Modify the Choose a strong name key file property.

After doing the above, I went back and commented out that code in AssemblyInfo.cs:

1
2
3
//#if (!DISABLE_STRONG_NAME)
//[assembly: AssemblyKeyFile(@"./Key.snk")]
//#endif

After a rebuild, the issue was resolved!

According to this MSDN blog post, it turned out that putting the reference to the key file into AssemblyInfo.cs caused both security and maintenance headaches. AssemblyKeyFile embeds the path to the .snk file into the assembly, revealing information that some developers/publishers would prefer to have unknown to the outside world. It would also cause build issues with Visual Studio, since the path to the .snk file was relative to the build directory.

Posted in .net, C#, coding, programming, vs2010, Windows | Comments closed

Migrating away from XmlValidatingReader

You may have run into the following error when building a C# project:

‘System.Xml.XmlValidatingReader’ is obsolete: ‘Use XmlReader created by XmlReader.Create() method using appropriate XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202′

As the message so aptly indicates, this is because the XmlValidatingReader is now deprecated. To fix this, use XmlReader in its place.

Before:

1
2
3
4
5
6
7
8
9
XmlDocument         doc              = new XmlDocument();
XmlTextReader       textReader       = new XmlTextReader(configStream);
XmlValidatingReader validatingReader = new XmlValidatingReader(textReader);

try {
    validatingReader.Schemas.Add(m_mappingPluginSchema);
    doc.Load(validatingReader);

...

After:

1
2
3
4
5
6
7
8
9
10
11
12
XmlDocument         doc      = new XmlDocument();
XmlReaderSettings   settings = new XmlReaderSettings();
           
settings.ValidationType      = ValidationType.Schema;
settings.Schemas.Add(m_mappingPluginSchema);

XmlReader xmlReader          = XmlReader.Create(configStream, settings);

try {
    doc.Load(xmlReader);

...

See also:

http://www.meadow.se/wordpress/xmlvalidatingreader-is-obsolete/
http://stackoverflow.com/questions/630641/xmlvalidatingreader-class-is-obsolete
http://blogs.msdn.com/b/johnls/archive/2005/12/28/refactoring-xmlvalidatingreader-in-net-2-0.aspx

Posted in .net, C#, coding, programming, Windows, XML | Comments closed

Add a context menu to remove .svn directories

This tip is absolutely fantastic when dealing with unneeded

1
.svn

directories on a Windows system.

Create a file called

1
delete_svn_special_dirs.reg

and copy in the following text:

1
2
3
4
5
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

After you save the file, simply right-click on it and select Merge and follow the prompts. Once this is done, you will now have a menu item called Delete SVN Folders that will be available when you right-click on folders. Run it when you need to purge your working copy of obnoxious

1
.svn

directories.

NOTE: When copying and pasting the above code, make sure there are no newlines in the last line.

Posted in coding, programming, source control, subversion, svn, Windows | Comments closed

WordPress Plugins: My current favorites

Here’s a list of plugins that I’ve really grown to appreciate when developing WordPress sites…

Smart Youtube PRO

Table of Contents Plus

Easing Slider

Social Media Widget

Sociable

Flickr Gallery

Photo Dropper

Posted in Uncategorized | Comments closed