Friday, July 22, 2016

anil

How to move your wordpress site from localhost to server?

 We always used to virtual web server installed on our computer (or localhost) for building up a WordPress website and customize a WordPress website with ease and speed. On the local server, it's so easy to develop a WordPress website because of all files and databases you can use with ease and speed and without any cost of the internet.

In this post, I’ll be going through the process of moving a WordPress website from a local server to a live server. This process allows you to safely move all of your site’s content (images, posts, and pages) as well as themes and plugins from a directory on your computer to your host’s production server. Obviously, there are a couple of handy plugins that can make this process a breeze, but it’s always advantageous to learn the manual process.

You will need FTP client and text editor tools for this operation.

Step 1:- Export Content Using Built-in WordPress Tools

The easiest way to move a WordPress site from local server to a production environment is by using the built-in export tool in WordPress. This method assumes that WordPress is already installed and setup on your hosting account.

To start, go to your website’s dashboard and scroll down to Tools. Select Export and check the “All content” radial button.



WordPress will download a file to your computer. This is an XML file that contains all details about your site’s content. Now move to the live location, login to the WordPress site, and activate the theme you developed/customized on the local server. Head to the dashboard again and 
select Tools > Import.


 If you’re prompted to install the WordPress import plugin, do so and then activate it.  Finally, use the plugin to import the .xml file you exported and saved to your computer.

This method will move your posts, pages, media and menus to your live site. You will of course have to set your menu locations and re-add your widgets, but considering that everything else is moved over for you, this is a quick and easy option.

Step 2: Move Database From Local Server To Live

This is the most recommended method if you’ve built everything on the local server from the ground up. Essentially, the process entails downloading the database file from the local installation, editing it for the correct paths before importing it to a new database on the server, and finally uploading all contents of the local WordPress installation.

 1. Export Database File

                                            To start, fire up your local server and navigate to phpMyAdmin—just type   http://localhost/phpmyadmin into the address bar. I’m using XAMPP and here is what my phpMyAdmin interface looks like:


                                             The panel on the left is where all databases are listed. Select the database for your local WordPress site and click on Export at the top of the phpMyAdmin window. The “Quick” export method is selected by default. Leave it intact and click Go.


A .sql file (such as my_test.sql) will be exported to the downloads folder on your computer.

2. Modify File Paths

When you build your WordPress website locally from the ground up, keep in mind that all your URLs will be absolute paths. In other words, all links to your content files (posts, images, post types) will start with http://localhost/. You have to modify this link structure for your live installation or your content will not display properly after uploading the database file.

To do that, use a code editor to perform a “find and replace” on the database file you just exported. I’m using Notepad++ and I’m going to search and replace for “http://localhost/my_test”  and replace it with “http://www.designboxug.com/my_test”.  I simply created a “my_test” folder at the root folder of designboxug.com. If you are going to install directly at the root, you don’t need to create any folder, so your replacement URL should be http://www.yourdomainname.com. You will be uploading your local WordPress folders to public_html (the root of your hosting account).


Once you’re done replacing the URLs, save and close. Don’t alter anything else.

3: Create New Database on Your Hosting Account

Now you’re done with the main part on the local server. It’s time to setup the live environment and finally get the files uploaded so that your website can go live. To setup a new database for your WordPress site, login to cPanel and browse to MySQL Databases.


When you select MySQL Databases, you will be prompted to enter a username and password. This is the new user account that will be associated with the new database for your website. Note the personal details  like your username and password because you’ll need them when configuring the database file in WordPress. The newly created database will have the same name as the username you chose.

4: Upload Database File into New Database

Now that you have a new (empty) database on the live server, it’s time to upload your database file saved on your computer. Browse to the phpMyAdmin interface of your host and select Import. Browse and choose the .sql database file you exported from your website on the local server.


If your host doesn’t have phpMyAdmin, use the Database Restore option in MySQL Databases. It does the same thing—allows you to browse and select a .sql file.



I used the restore option to import my database file. Remember, this is a crucial step because it allows you to restore your website exactly as it was on the local installation. Now all that is left is to edit the wp-config.php file, upload website files, and fix the permalinks and we’ll be up and running.

5: Fix wp-config.php File

Open the wp-config.php file in your code editor (browse to your local WordPress installation folder). Here are the only details you need to change:
  • define(‘DB_NAME’, ‘your_database_name’);
  • define(‘DB_USER’, ‘your_database_user’);
  • define(‘DB_PASSWORD’, ‘your_database_password’);
  • define(‘DB_HOST’, ‘localhost’);
Just fill in the settings you defined while creating the database on your live server in Step 3. For the host name, fill in the server IP address or leave it as localhost if your host explicitly says so. I’ll leave mine as localhost as it’s clearly stated here: “To connect to this database in a script running on your web server you should use “localhost” as the hostname.” When you’re done editing the settings, save and close the file. Don’t change anything else.
Note: Make sure to save a copy of your old values, just in case anything goes wrong you can always revert back.

6: Uploading Website Files

It’s now time to move the actual WordPress website files as we’ve setup everything on the live server. Fire up your FTP client and connect to your hosting account using your FTP connection details. You can get them from your host if you don’t have them already. For some hosting providers, the FTP logins are the same as the cPanel details.
Once you’re connected, browse to the public_html or www folder (or a folder at the root where you want to install your WordPress website) and copy all files from your WordPress installation folder on the local server to this directory on the live server.

7: Modify Permalinks

The final step is to modify the permalink structure of your new website to match that of your old site on the local server. To do this, go to the admin dashboard of your new website and browse to Settings > Permalinks. Select the structure you used for your local installation and save. Your WordPress website should now be live.

source: wpexplorer.com

If there is any type of difficulty you found in migrating your WordPress site from localhost to Server Live site, Please comment here I always ready to provide a best solution.






About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a huge information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :

4 comments

Write comments
Unknown
AUTHOR
July 26, 2016 at 4:57 AM delete

it's saved my a lot of time..thanks for the article

Reply
avatar
Anonymous
AUTHOR
September 12, 2018 at 2:13 AM delete

thanks it helps me a lot

Reply
avatar
Ben Kol
AUTHOR
September 25, 2018 at 5:59 AM delete

OH NO! Don't do search/replace to your DB!
From Wordpress' documentation: "If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break."
https://codex.wordpress.org/Moving_WordPress

Reply
avatar

Note: Only a member of this blog may post a comment.