Manually migrate locally developed WordPress site to a live server
Every developer has its own developing methods and tools they like to use. Some will develop on live servers while keeping the front facing side ‘in development’ mode – usually by installing some coming soon plugin, or modifying the htaccess. Some have their own servers, where they develop the theme, and have all the developing tools set up so that they can receive the feedback from the client (like TrackDuck for instance). Some will set up a XAMPP, Wamp or even Vagrant which will enable development on their local machine.
We all have our rationale why we do things. Most of the time it’s because we’ve learned how to do stuff one way, and are really good at it, so we don’t bother looking the other (maybe better) solutions. I tried setting up Vagrant on my computer, but I failed, and said to myself: I’d get to it eventually (I still plan to do it tho :D). Like that I’ve done my developing by creating a site on my paid server, in a subfolder (protected ofc.). I’m doing it purely because of convenience. So when I create the site the client asked for (and supplied the designs and the content for), I can set my site up, do my developing, and after I get the green light from the client, I migrate the site to his own server.
You may wonder: but isn’t this kinda unnecessary? If the client has paid for the server where his site will be, isn’t it easier just to develop there? Well, it depends. There are some hosting companies like godaddy, or one.com, that will have sever built cache. And developing on such servers (where you cannot turn it off), is nothing short of a nightmare. Any serious developer will steer clear of such hosts, and developing anything on them. This is why I like to work on an environment I’m familiar with. The only thing you’ll need to look out for, when you finally move your site or app on their servers, is that it actually works. Not all servers have the same OS on them (CentOS, Ubutnut, Debian, Windows), or are built on the same web servers (Apache, Nginx, IIS, GWS). So these are some things you’ll have to take in consideration when developing web sites or apps.
But let us turn to the question at hand: Once I’m done with development, how do I move everything to a live server and make it working?
Just copy pasting whole thing won’t work. Sorry guys, it’s a bit more complicated than that.
WordPress CMS relies on its sql database to work. So just copying everything from the installation folder (theme, plugins, wp-includes and wp-admin), won’t do the trick if you don’t connect it to the database.
The work ahead
So let’s say that you’ve set up a live database, prepared the server and it’s all looking fine. How do we migrate the site?
First thing you’ll need to do is to make an export from your developer database. If you are using phpMyAdmin, then just select your WordPress database, and click on the export button in the toolbar. If you have a command line interface instead of phpMyAdmin, then you’ll need to (assuming that your command line recognizes mysql command) type in
mysqldump -u YourUser -p YourDatabaseName > mysql_dump.sql
You’ll be prompted the database password, and you’ll have the .sql file exported to the path you’re currently in.
So now you can copy all the contents from the development server to the live one. And import your database in the new one you’ve set up. Be sure to change the database details in your wp-config.php file so that they match the new database.
Do not run your website just yet!
If you were to just go to your site, you’d pretty much mess it up, because you’d connect the database on the new server. And you still have old links in the database. You need to change them first, so that they point to your new server. I like to use a great script from guys at interconnect/it called Search Replace DB. This script will go through your database, and look for the signs of the old links and replace them with the new ones.
For instance, your uploads folder url could look like this:
But your site’s uploads folder points to
You’ll need to replace localhost with www.yoursite.com. Once you’ve downloaded your script, place it in a /sr folder and go to www.yoursite.com/sr. You should see something like this
The database details should be automatically pulled from the wp-config.php file. After you’ve put the names to search and replace for, do a dry run. This will simulate the replacing, so that you can see if the replacement links look ok. If they do, just do a live run, and let it run. After it’s done be sure to delete the /sr folder. Because this is a security risk if you leave it up (anybody could go to it and replace anything they like, so be sure to remove it). Just a note – the delete me button that you see on the image above doesn’t work. Just log in to your server and delete it manually (from command prompt or from FTP).
And that’s it. You can connect to your WordPress backend, and you’ll maybe need to flush rewrite rules – you can do that by going to Settings > Permalinks and just re save the permalink settings. After that all your content, and links should point to your live installation, and you should have a fully working live site.
Hope this helps people out there. If you have any questions ask them below in the comment section. Happy coding :)