WordPress on localhost{:port number}

I run a few Virtual Host instances on Apache that are assigned different port numbers. For example, the dev instance of this site was hosted on http://localhost:8080/.

On a new WordPress installation, if I hit http://localhost:8080/ on a browser, I will get a HTTP 301 redirect to http://localhost/ (sans port number) because of the built-in Canonical URLs feature. As you can probably tell, I wasn’t able to access the WordPress instance on port 8080.

Fortunately, Mark Jaquith has provided an aptly named Disable Canonical URL Redirection plugin.

Drop the plugin into your wp-content/plugins directory and we will then need to activate it outside the admin area by fixing the database directly (I used Sequel Pro). Here’s how:

  1. Locate the wp_options table
  2. Set active_plugins to a:1:{i:0;s:31:"disable-canonical-redirects.php";}
  3. Change the values of siteurl and home to / (might not be strictly necessary)

http://localhost:8080/ should now work correctly.

Just remember to disable/remove the plugin in production environment. The SQL values you just fudged would be correctly resaved once you have access to the admin section.

15 thoughts on “WordPress on localhost{:port number}”

  1. Heya,
    I just tried this with 2.8.3 and I can’t get it to work. It will still redirect to /wordpress which 404’s.

  2. I have a couple of 2.8.3 installations working fine, so the instructions above should still work. Curiously, I just discovered that one of them does not even have the “Disable Canonical URL Redirect” plugin activated, but I can still hit http://localhost:8082/ just fine.

    Can you try changing siteurl and home in the db to include the host:port-number?

  3. I cannot thank you enough. I have been messing around for 2 days trying different configurations with Apache. I was initially running WAMP server on :80 using virtual hosts for seperate WP installations. I then installed IIS 7 and it hogged port :80 so I have had to configure WAMP to :8080 but couldn’t get WP to work. This worked a dream, I needed step 3 too. Thank you.

  4. Thanks for the good info. If you have info for a fix for joomla too please email me. Thx.

    Because of my ISP blocking the 80 port I had to go around this issue by using another port. Regular websites would work now, but not wordpress and joomla. I checked the HTTP headers and I noticed I was getting a 301 redirect without the port number attached. You information is very good, that fixed the wordpress redirection issue. Now it’s time to figure out Joomla.

    (btw this website came out very helpful for checking the HTTP headers: http://www.rexswain.com/httpview.html. I needed to use an external tool as locally of course wordpress worked fine.)

  5. Brilliant. Works like a charm.
    I’ve wasted hours Googling for “wordpress ssh-tunnel”

    You wouldn’t believe the search term that turned up this working solution :
    “wordpress url 301 ssh-tunnel”

    I had to search for the plugin directory though.
    If it helps someone, it’s in wp-content/plugins/

  6. Thank you very much, i spent a lot of time struggling with my ADSL connection, and this tip came like a light in the end of the tunnel

  7. Hey, question; this doesn’t work anymore?
    I’m trying making a script for fixing this but is not working, this are my steps they are all executing well but the webpage on my vhost it won’t come up:

    echo “Getting disable redirects plugin”
    curl http://txfx.net/files/wordpress/disable-canonical-redirects.phps > $home/public_html/$vhost/wp-content/plugins/disable-canonical-redirects.php || error “cannot download the disable canonical redirects plugin”

    echo “Activating plugin”
    sql_query “update wp_options set option_value=’a:1:{i:0;s:31:\”disable-canonical-redirects.php\”;}’ where option_name=’active_plugins'” || return 1

    echo “Changing siteurl and home values”
    sql_query “update wp_options set option_value=’/’ where option_name=’siteurl'” || return 1
    sql_query “update wp_options set option_value=’/’ where option_name=’home'” || return 1

    your help or guidance will be appreciated.
    Best regards.

  8. If you use Wampserver you can install multiple instances without the need for a port number change at all. This will allow you to run http://localhost/site1 and http://localhost/site2 in parallel and it’s scalable (not sure the upper limit). I have done this for about 10 installations of WP on localhost with no change to default port number the browser looks at (80) and it works fine.

Comments are closed.