WordPress URL Rewrites On Plesk 10 Windows

We needed to get URL rewrites working on a Plesk 10 Windows server for a client wanting friendly URLs in WordPress. Turned out to be pretty easy ….

1. Make sure the Microsoft IIS URL Rewrite 2 extension is installed. You can find it here:

http://www.iis.net/download/URLRewrite

2. Create a web.config file in the folder where you have WordPress installed with the following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
<rewrite>
    <rules>
        <rule name="Main Rule" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php/{R:0}" />
        </rule>
    </rules>
</rewrite>
</system.webServer>
</configuration>
View Comments

Howto: Change Default Index On Plesk 10 for Windows

When you request a URL with no file name at the end like:

http://www.acme.com/

the web server consults a list of predefined “index” or “default” file names and returns the first matching file.

On Plesk 10 for Windows follow these steps to change the default index page list:

  1. Login to Plesk
  2. Drill-down to the control panel for the domain that you wish to change.
  3. Click on “Websites & Domains >> more” link.
  4. Click on “Show Advanced Operations” link.
  5. Click on “Virtual Directories” icon.
  6. Click “Directory Properties” icon.
  7. In the “Documents” section, find the “Default documents search order field”. From here you can add new default file names and change the order of precedence for the file names.
  8. When you’re finished making changes click the “OK” button at the bottom of the page.
View Comments

Install PHP SSH2 extension on RHEL 5.6 with EPEL repository

Here are the steps to install the PHP SSH2 extention on RHEL 5.6 with the EPEL repository.

  1. Install packages that may be needed:
    yum install php-pear php-devel libssh2 libssh2-devel
    
  2. Temporarily allow binary execution in /tmp
    mount -o remount,exec /tmp
    
  3. Install the extension:

    pecl install channel://pecl.php.net/ssh2-0.11.3
    
  4. Restore /tmp restrictions:
    mount -o remount,noexec /tmp
    
  5. Reload apache:
    /sbin/service httpd reload
    
View Comments

Putty SSH Tunnel for RDP

On occasion I need to use Remote Desktop Protocol (RDP) to access a Windows server that is not directly available on the Internet. For example I might have SSH access to a Linux host on the target network. Or the Windows host has source access controls limiting access to a specific network when I’m traveling. The solution if to setup an SSH tunnel with Putty from my Windows desktop to the “gateway” or “bastion” host and then send the RDP through this tunnel.

So here’s the example parameter:

  • RDP is a TCP protocol over port 3389.
  • My laptop has a dynamic address.
  • The target Windows server has an IP address of 10.10.10.10 and is located on a private network.
  • I have a Linux server inside the private network at 10.10.10.5. There’s a port forward on the firewall that allows SSH to the Linux server on the public address 123.123.123.123 on port 22.

To make this work we just need to create a new session profile in Putty. Follow these steps:

  1. Start a new Putty session.
  2. On the session screen: enter the public address of the Linux server (123.123.123.123) and enter a name for the new session profile (RDP Demo).
  3. Now go to the SSH->Tunnels screen:
  4. In the “Source port” field enter the local address that will be forwarded to the remote server. Normally this would be “localhost:3389″ but Windows does not like connecting RDP on the loopback interface so we need to use an alternate address of “127.0.0.2:3389″. In the “Destination” field enter the IP address of the Windows server and the port number which is “10.10.10.10:3389″ in our example>
  5. Finally return to the main session screen, click “Save” to save the new profile and then click “Open”.
  6. An SSH terminal window will open and you’ll be prompted to login to the Linux server. After login, I like to open a ping or run top to keep the session active and avoid timeouts on any firewalls. At this point, Putty, in cooperation with the SSH daemon on the Linux server, packets sent to 127.0.0.2:3389 will be tunneled over the SSH connection and resent on the remote network to 10.10.10.10:3389.
  7. Now just open your Remote Desktop client and enter “127.0.0.2:3389″ as the remote address.

This same technique can be used to tunnel other traffic, just adjust the port numbers as needed.

View Comments

WordPress Development Sites

Had a conversation with a client yesterday about how best to develop a new WordPress stie before the domain name was pointing to the server. This might be the case if you’re building a new site while the domain is still pointing to the old site.

If the new site has to be publicly available then the only real solution is to develop on a subdomain or alternate domain. So in Plesk or CPanel create the target domain like “acme.com”. Then create an alias domain like “dev.acme.com” or “acme.greatdesigns.com”. Now you’ll install wordpress and do the development on the alias domain. When you’re ready to go live you can point the final name in DNS to the new server.

But there’s are several possible issues that you’ll see when you go live:

  1. WordPress stores the domain name of the site at installation in the wp_options table under the “home” and “siteurl” keys. You’ll need to update these rows to the new domain.
  2. Sometimes a theme will contain an absolute url reference. This should not be the case but sometimes mistakes happen when your building a custom theme. So make sure you search/replace the theme folders for the new name.
  3. WordPress may contain domain name references embedded in the database. I usually do a two multi step process where I
    1. dump the entire database to a sql file
    2. Plus I dump the wp_options table to another sql file
    3. Then I search/replace the new domain into the full dump and load it to the server.
    4. finally I manually edit the wp_options dump to fix url references and load it to the database

Why the multi-step process to fix up the database? WordPress widgets like to store serialzed PHP strings to the wp_options table. These strings can not be changed with a simple search and replace because the include string length information. So to when I manually fix the wp_options dump file, I have to adjust the string lengths in addition to the domain names. Overall this is a real pain is there are many widgets.  So far I don’t know a good work around for these issues.

If the new development site does not need to be public then a much easier solution is to use a hosts file on your workstation. Start by creating the domain in Plesk or Cpanel. Note the IP address assigned to the site.

Now following the instructions in the articles here:

RP Knowledgebase Migration Category

Add a hosts file entry mapping the domain name to the assigned IP address similar to this:

192.168.0.123 acme.com
192.168.0.123 www.acme.com

Now your web browser will go to the new site instead of the old site. You can install WordPress and do your development on “acme.com” and you don’t need to worry about changing anything when the site goes live.

There is just one catch, if you want to install plugins or updates from within WordPress then you’ll need to edit the wp-config.php file and add the following line:

define('FTP_HOST', '192.168.0.123);

This change gives WordPress and explicit address for it’s FTP connection instead of using DNS so it will be able to install upgrades.

View Comments