homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

How to deal with URLs when deploying a Wordpress site

 11:38 pm on Jul 9, 2014 (gmt 0)

One incredibly annoying aspect of Wordpress is that the site root URL is set in the database.

Normally, I would
- create a local site
- commit to git
- push the code to the repo
- pull down to the server

The site config should be in code and the content in the database, but in Wordpress it's mixed pele-mele, so you can't maintain a simple workflow, because every time you pull your live data down, your site breaks. If you forget and push your dev data up, your site breaks.

The solution is simple:

- make sure your wp-config.php is in your .gitignore so it's not tracked by version control. That means you can have a different one on your dev and live servers

- in your wp-config.php file, add two lines to override whatever the siteurl and home page urls are in the DB


- now you can develop locally and push to your test and live platforms normally without borking your site and without having to manually edit your database every time you pull down your live data.




 12:40 am on Jul 10, 2014 (gmt 0)

Nice tip ergo!


 2:08 pm on Jul 15, 2014 (gmt 0)

Exactly the kind of tip that makes you wonder "Why I did not think about it?" :)


 1:59 am on Jul 22, 2014 (gmt 0)

Turn out this method and the related ones have their limits. Some plugins seem to tap into the system and call the site_url() function before the override settings take effect (I would think nothing could happen before wp-config.php fires) and pull the value from the DB.

I've always thought this was one of the stupidest "features" of Wordpress... arrgghh


 12:01 pm on Jul 22, 2014 (gmt 0)

I think the WordPress dev team would welcome your thoughts if you were so inclined.


 7:24 pm on Jul 22, 2014 (gmt 0)

Where does one submit that sort of thing to Wordpress?

I'm curious what their logic is on this. In any case, I set up wp-config.php as follows

- remove all DB connection info
- have three include statements that use absolute paths that are environment specific in the form

if (file_exists('/path/to/subdomain/on/test/machine/config-test.php')) {
elseif (file_exists('/path/to/docroot/on/live/machine/config-live.php')) {
elseif etc...

Then each file has site-specific info like the DB connection and


Aside from a few plugins it works fine. Everything I've worked with except WP uses root-relative URLs, so it's easy to put it in version control and run a dev/test/live workflow.

What is the expected workflow with Wordpress? Do people just do everything on their live sites? If not, how do other people handle the URL problem?


 7:32 pm on Jul 22, 2014 (gmt 0)

@ergophobe You could have two similar WP on the same server. One your main root site and another one set in another dir.


 9:37 pm on Jul 22, 2014 (gmt 0)


You'll need a forum membership but then you can submit a ticket and or get involved with building out the core. You can also join in on the IRC chats. Otherwise, just engage @nacin on Twitter.


 11:19 pm on Jul 22, 2014 (gmt 0)

So of course the absolute vs root relative question has been discussed ad nauseum in the WP community issue queue

e.g. https://core.trac.wordpress.org/ticket/17048

It will probably never be accepted, but there is a plugin to make WP use root relative URLs if you so choose.

@henry0 - Are you referring to my file_exists() calls?

The actual implementation would be up to the developer to make sure that there is no ambiguity or you would never have multiple hits. Some situations will be harder than others.


 11:56 pm on Jul 22, 2014 (gmt 0)

It regards: Do people just do everything on their live sites?


 4:22 pm on Jul 23, 2014 (gmt 0)

Got it. In that case my critique holds. Doesn't matter how similar your server is. If it doesn't have the same URL, then you have to muck with the Wordpress database manually every time you import your production DB to your development platform. Makes no sense.


 7:57 pm on Jul 23, 2014 (gmt 0)

Point well taken, thanks


 7:51 pm on Jul 25, 2014 (gmt 0)

my simplistic approach is to develop the site in a sub folder on the server while using a password protect plugin. Then I move the wordpress files to the root and use a search and replace plugin to revise the url site wide. I also use a maintenance page plugin that supports html content to shut it down for a few minutes to make sure the theme hasn't been trashed. Usually it goes pretty well and takes about 5 minutes tops. I run the search and replace plugin several times during the process to make sure all instances of the subfolder url are changed.


 4:24 pm on Jul 26, 2014 (gmt 0)

Hi Maggymae. Thanks for joining in.

That's similar to what I used to do, minus the plugins. The root problem for me is that all such processes are prone to error and can bring a live site down unnecessarily.

Ideally, I should be able to take my exact live data, inject it into my test platform, and if it passes all automated tests (see [webmasterworld.com...] I should be able to just git push and git pull without going into maintainence mode or anything like that.

In any case, there shouldn't be steps in the process that, if I forget them (search and replace all instances of the URL in the DB, which is a crazy requirement from a CMS), bring the system down.


 11:43 am on Jul 27, 2014 (gmt 0)

:) gotcha... I haven't seen a site go down as of yet... but some themes have gotten a bit mangled.


 6:08 pm on Jul 27, 2014 (gmt 0)

The "root relative" plugin I referenced above helps too. Now I can move the database willy nilly without worrying about taking sites down.


 7:03 pm on Sep 14, 2014 (gmt 0)

Okay, scratch that. Wordpress still has serious migration problems. I think you have to run your dev site in a virtual machine that has the same file strucutre as your target machine and which has your main domain resolve to localhost.


 3:18 am on Sep 15, 2014 (gmt 0)

Actually, it works fine for WP core. The problem is themes and plugins that use absolute file paths and URLs that mess everything up.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved