WordPress: Migrate from Localhost to Server

After I finished the the basic setup for this wordpress blog on my local machine, I uploaded all the code to the server and exported/imported the content of the database.
I run into some trouble, and I created this short guide to help you do all the work neccessary to migrateyour wordpress blog.

1. Migrate Database

First migrate the database. Go to your database management tool and export the structure and data of your wordpress database. If you are working with phpMyAdmin, the following is the process.

Select the wordpress database and go to “Export”:

Choose export method “Custom”:

Set the maximum length of the query to a high number, like “10’000’000” to be sure to get everything. Then click on “Go” to save the file.

Login to your webhosting, create a database, and go to “Import”. Choose the file you have saved before and upload it. The database got imported.

2. Fix Database Settings

Previously you were developing on localhost. So now you have to update your settings to match the new URL. Therefore open the table “wp_options” and change the following two settings to match your URL:

3. Upload and adjust WordPress files

Now you can upload all your wordpress files, including all plugins etc.

On your server, open the file “wp-config.php” to adjust the settings:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'your_db');

/** MySQL database username */
define('DB_USER', 'your_dbuser');

/** MySQL database password */
define('DB_PASSWORD', 'its a secret ^^ ');

/** MySQL hostname */
define('DB_HOST', 'your.db.mysql.host');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'yourcharset');

4. Adjust .htaccess if needed

Sometimes, depending on your hosting and how you worked on localhost, it is needed that you update the .htaccess file in your root folder.
If you get one of the following issues you most probably want to check if this will fix it:

  • When editing a post you get “Update Failed” ord “Publishing failed”
  • You get an HTTP 500 Internal Server Error
  • You find the belowerror in the log file.

If one of above is the case, you might want to have a look into the .htaccess file. For me setting the content of the file to the following fixed my issues(adjusted the values “RewriteBase” and “RewriteRule”):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress



Leave a Reply

Your email address will not be published.