Sélectionner une page

Migrating A Local WordPress Installation To A Live Web Server

Migrating A Local WordPress Installation To A Live Web Server


This article is a follow up to a previous post How To Create A Local WordPress Installation On A Mac. A lot of people requested we show how to take a local installation of WordPress and move it to a live web server. Because of the demand, I will walk you through how to go about doing this.

The task of moving your website can always be a scary one but it doesn’t need to be. A lot of assets, code, and structure can change in the process of moving your site. There are proven steps to take to avoid headaches and even some notable services that can do the process for you. If you’re interested in doing it yourself then I invite you to follow along with this article about migrating a local WordPress installation to a live web server.

Setup

If you already have WordPress installed locally then you have completed the very first step. If you are not sure how to install WordPress on your local machine then view my other article How To Create A Local WordPress Installation On A Mac or Kevin’s on How To Install WordPress Locally On A Windows Computer (if you’re a Windows user) to find out how to get things setup. For the purposes of this tutorial I will assume you already have WordPress installed on your local machine and your site is ready to push to a live web server.

Backup Your Files and Database

If your site is indeed ready to push live, make sure you make a copy of all your files within it to keep a backup handy. For good measure it is also wise to backup your database used when you installed WordPress locally.

To backup your database you’ll need to have your local server running. I personally use MAMP for my locally installed WordPress websites. You can use whichever option your prefer.

Launch MAMP and start your local server.

mamp-start-server

MAMP server is running

To verify your server has started MAMP should tell your by its status indicators but if you still aren’t sold then click on Open start page and you should see the screen below:

Our MAMP server is successfully live.

Our MAMP server is successfully live.

Success!

To backup our database we need to head to our phpMyAdmin section within the MAMP tool list.

php-my-admin

Click on phpMyAdmin to get access to your local databases.

Once you click on the link you’ll be redirected to the phpMyAdmin dashboard. Find the Databases tab and click on it. Here you will want to find the database you used on your website. If you don’t remember the name of the database then you’ll need to reference your wp-config.php file inside your WordPress installation. If you open your entire WordPress installation in a code editor your should see something like below. I currently have my wp-config.php file open.

wp-config

WordPress wp-config.php file.

If you look at the first line below the larger block of comments you should see a comment indicating what our database name is. You should see the equivalent inside your phpMyAdmin database list.

Here’s how the database looks on my end:

migrate-db

Our database and it’s contents

The database I used for this tutorial is called migrate_wordpress. Yours will obviously be different but the process I’ll go through is exactly the same.

With your database all set head to the Export tab and choose the Quick option. The rest of the settings can be left as defaults. Click go and a large chunk of SQL code will be generated. Copy the code and save it into a new file with a .sql extension. You can name the file however you please.

Now we have our database backed up. Any posts, images, or other data you generated during the life of your local WordPress installation can be reproduced if ever needed.

Note – If you already have a WordPresss site live on a testing directory of some sort then you can do the same thing we did here by backing up your files as well as the database.

Live Server Optimization

When you upload any file to a web server from a local installation, the file path to that file will always change. This is probably the trickiest endeavor when moving WordPress to a live server. WordPress relies on it’s permalink structure as defined in it’s general settings to operate correctly. In order to get our website live we need to make sure all the permalinks change to the proper path.

I’ll be using a subdomain of my own website to use as an example for this tutorial. You’ll need access to your web host to optimize your server for the new WordPress Installation. For this tutorial I’ll be installing a completely brand new WordPress site on a live server. The local installation will be copied to my server rather than creating a whole new WordPress installation first.

One-Click Installs

Most web host’s offer a one-click install of WordPress or other popular Content Management Systems. While these are really easy, I prefer to install WordPress on my own and the reason for this is that the web host will typically assign some really unique and hard to remember database names and passwords to your installation. While this is great for security, I can never remember these credentials. If you’re in a pinch then by all means feel free but I won’t be covering how to go about setting WordPress up this way in this specific tutorial.

Create a new database

In order for WordPress to function on the live server we need to add a database. Your web host provider will likely have a database section when you login to your control panel. You’ll want to create a new database and assign yourself as a user with all privileges. Every web host is different so If you can’t figure this part out you’ll need to look for support online. A lot of web host providers offer tutorials on topics such as this one.

For your site you will need to name the database with a unique name. For this tutorial I’ll just be naming my database migrate_wp

With your database created, you will need to login to your web host’s control panel and find your phpMyAdmin tool. This tool is almost identical to the one we used locally except you will likely be presented with a login form. When you access it you’ll see your new empty database.

Change wp-config.php

To get WordPress to connect to our live database correctly we need to modify our wp-config.php file. Add the credentials used for your web host to your local wp-config.php file. I won’t reveal my own credentials so I’ve added some placeholders which you can see below 🙂

wp-config-live

WordPress wp-config.php file.

Upload Your Files

Now we need to upload our local site’s files to the web server. I’ll upload mine to a subdirectory for example purposes since my main root level website is already being used.

FTP access is a way to get access to certain directories on your web server. If you’re the admin of your site you can get complete access as well as share limited access to others. We may cover this feature in another tutorial.

The web server has a folder and file structure much like a regular computer. You use your FTP application to upload your files easily. If you are unsure how to get FTP access to your site then defer to any guides your web host provides on the matter.

I’ll use Transmit to copy my files from my local machine to my web server. You can use any FTP client. There are a lot of free ones out there. If you are for a high quality and easy to use free application I would recommend CyberDuck.

transmit-dual-window-view

Our live and local site files.

On the left side of Transmit’s window I have my local site. On the right side I have my live site which is connected via FTP and my new directory or subdomain which I created earlier (migratewp). This directory, as I mentioned, is a sub-directory of my main website so it will display at http://justalever.com/migratewp when it’s fully functioning and live. Your site might be at the root level of your www or public_html folders on your website. Either folder leads to the same place so don’t let that confuse you. If you want your site to be at www.yoursitesname.comthen just add your local WordPress installation files to your www or public_html folder.

upload-files

Uploading files to my web server.

Once your files finish uploading (this might take a few minutes) you should be able to navigate to your site at the address I spoke of above.

Since we created a brand new database on our live server WordPress will treat the upload as a first time installation.

wordpress-install

We are presented with the WordPress new installation screen because we have created a new database and added the WordPress core files for the first time.

If you’re following along you will need to setup your site by naming it and establishing a username and password. Once you do you can then login to your WordPress Admin area.

Link Structure

At this point we have our WordPress installation live on our site and functioning correctly.

There may be times where you have some stray links within your theme which you defined as non-dynamic links (these won’t automatically update ). These links will likely still have the http://localhost:8888 link url instead of what is live on your current site. There are several ways to go about updating these links which I’ll cover below.

Before moving forward you will need to make sure that your site’s url structure is set to your liking within your General Settings inside your admin area. There’s a chance it can still have the url http://localhost:8888 or something different if your using a testing server that’s live already. If it does then now is the time to change it to your new url that your site lives on.

general-settings

Edit your site URLs

If you navigate to your site after setting things you will probably get an error. WordPress is set up internally but the data inside our database is still pointing to our old url.

Editing the ‘wp_options’ database table

The more technical approach to changing your link structure can happen back inside your phpMyAdmin area. Head to your phpMyAdmin area and login from inside your web host control panel.

phpMyAdmin-live

phpMyAdmin live on our Web Host control panel.

Find your database and click on it to browse its structure. Inside your database you should see a table called wp_options. Within this table is all of the data that is bundled with your WordPress site.

wp-options-row

The options table that comes installed with WordPress.

Click on the wp_options to browse all the options it lists. You should see the top row option_name is your primary siteurl. You can click right on the row to edit the contents. If your “siteurl” is still set at a localhost link (http://localhost:8888/) you can change it to your live site’s URL now (http://yourwebsite.com).

edit-option-url

Edit your site url if it’s different than your live site’s domain address.

A common error at this point is to assume you have updated all of your options to use your new url. We have one more option to change. You will need to go to the next page of options to find it.

The option name you are looking for will be the home option. Make sure to edit this field to include your new site url as well.

home-option

Update the home option value to include your new URL.

With these settings in place your links should update to your new URL thus making your site live.

Using a Plugin

An easier approach to changing the links throughout your WordPress site is to use a plugin. One that I tend to use is called Velvet Blues Update URLs.

This plugin eliminates the need to mess with your database manually. If you are moving your site from a local installation to a new domain name on your web server this plugin will search and replace the links you supply it.

update-urls-velvet

Update your urls using the Velvet Blues plugin.

Simply enter your old URL in the Old URL field and then your new URL in the New URL field. Then select which areas you want to update. Typically you can get away with selecting all the fields except Upadte ALL GUIDs simply because thats left for development sites.

Hopefully you won’t enter your URLs wrong but if by some chance you do be sure to make a backup of your database first. I covered how to go about doing this earlier.

After running the plugin you should notice all of your links update throughout your site. Some links that are hard coded by hand my have to be updated by hand if the plugin doesn’t quite find all of them.

It’s Alive

Our WordPress installation is live on our web server. We updated our links both within the admin area and inside our database. My site is now live and I’m a happy camper. Hopefully you are too!

Today I covered how to install a new version of WordPress on a live server. Some of you may have a development site that you use to test your WordPress sites on which is already live. In the event that you do the process of moving WordPress is extremely similar to this only you’ll be using an existing version of WordPress.

A great reference is the WordPress Codex itself for tips on Moving WordPress in the easiest way possible. There are a lot of things that can go wrong but they are usually quick fixes because it has to do with links and naming conventions. The more you move websites the better you become at it even though at first it seems extremely complicated.

I hope this helped anyone who has always wondered how to move a local installation to a live web server. It’s not all that hard but there is a checklist of items to remember when making the move. The key is to use common but unique naming conventions and make sure your links are all consistent.

Article thumbnail image by bgplanet / shutterstock.com



Source link

Poster le commentaire

Votre adresse e-mail ne sera pas publiée.