It is a common practice for WordPress developers to host websites on a local server (which is hosted on their laptop or personal computer) before taking them live.
Developing and Hosting Websites Locally has Following Advantages
- It provides security, you can test the changes on your website without affecting your visitors’ experience.
- You don’t need to have an internet connection, enabling you to work from a location with unreliable or slow internet.
- It reduces cost, as most local website development environments are free to use, you can save a significant hosting cost during the course of website development.
- It saves server resources, anything that you would do on your localhost will not affect your live server and its resources
Note – Even when you are working locally, it is important to have backups and use version control to avoid losing important data.
Once you’re done with website development, you can move it to a live server, making it accessible to the public.
Things you need before you start the migration process
There are two methods of migrating your website from localhost to a live server – you can either do it manually or with a plugin. Irrespective of the method you choose, you’d need the following things before you start the process:
- Web hosting compatible with WordPress – If your chosen web hosting doesn’t meet the WordPress requirements, you may still be able to migrate your website, but also create security vulnerabilities. You can go for Bluehost’s web hosting plans that are especially designed for WordPress websites.
- Domain name linked to web hosting – If your hosting company and domain registrar are different, you will need to connect your domain to the web host.
- Login credentials for your hosting panel – Usually, these are similar to the login information for your web hosting account. If you are unsure, check with your hosting provider.
- Hosting account’s SFTP (secure file transfer protocol) details – Under this, you’d need your live server’s IP address, username, password, and port number. These details are usually found in your web hosting control panel. If needed, you can contact your web host’s support team.
You will also need an SFTP application to transfer files from your local host to the live server.
Now that you know the prerequisites, let us take you through the migration process using a plugin.
Migrating your website from localhost to live server using a plugin
For a majority of websites, migrating using a plugin works well and is a lot easier, produces fewer errors and is less time-consuming. We’ll use the Duplicator plugin here, though DesktopServer and Transferito are other options you can opt for. The process should be mostly similar.
1. Create a package
- In the WordPress dashboard, Go to Plugins → Add New
- Search for ‘Duplicator’, and click install → Activate
- Now, in your WordPress admin menu, find ‘Duplicator’ and then click on ‘Packages’. You’ll be taken to the packages screen
- Create a new package by clicking ‘Create New’ in the screen’s upper right corner.
- Check the package settings. In this, you can change some options, but majorly, the default settings will be fine. Click ‘next’.
- Run the test scan, which aims to ensure that everything is working fine. Once the test is complete, the results should all be ‘good’, barring the size checks. You may get a ‘notice’ on the size checks if your website is fairly large, but despite that, you can continue the process.
If anything fails, you can simply click on the item to get details and suggestions on how to rectify the problem before proceeding.
- Build the package. Once the test results are ‘good’ (except for the size check notice), you can hit the ‘Build’ button. This may take a while but keep the browser window open until the process completes.
- Download the files. You will need to download two files – An intaller.php file and a ZIP containing the website files.
2. Create a database on your live server
- To install the package that you built in the previous step, you need to create a new database on your web server.
- Log in to your web hosting panel, navigate to the ‘MySQL databases’ section, and create a new database. Herein, it is known as ‘tutorial_mydb’
- Create a user for this database by scrolling down to the ‘MySQL Users’ section. As always, you should have a strong and unique password for your database user.
- Add this database to the user and assign permissions. To do this, scroll down to the ‘Add user to the database’ section, select the user as well as the database you just created, and click ‘Add’
- Assign all the privileges to the user account and click on ‘make changes’
3. Copy your files from the localhost to the live server
- For this, you need to place your installer.php file and Duplicator package on the web server. To execute this, you will need SFTP client and SFTP login details. If you are not sure about what these are, contact your web server.
Alternatively, as you are uploading only two files, you can upload them through your web hosting control panel file explorer (if it has one).
- Log in to your web server with your preferred SFTP client
- Navigate to the location where you saved your installer.php files and Duplicator package on your local computer. In most SFTP software, your server files appear in the right pane and local files in the left.
- Navigate to the public directory on your server. Typically, this is a folder called ‘www.’ or ‘public_html’. As this varies from host to host, check with your hosting provider if you are unsure. If you are hosting your website in a subfolder, you will have to navigate to that subfolder.
- Select your installer.php files and duplicator package and drag them to the web server (moving from left to right). This may take a little while depending on your Duplicator package’s size.
4. Install Your Duplicator Package
Go to https://yoururl.com/installer.php (replacing yoururl.com with your real URL).
On visiting the above URL, your hosting’s suitability for Duplicator to install the package will be checked. If you notice any failures at this stage, get in touch with your hosting provider. There are some options available here, but mostly, defaults will be fine. If everything seems fine and passes, click ‘Next’.
And, your Duplicator package will be extracted.
2. Install database
After your package is extracted, you will be asked for the database information. Enter the details from the database you created in the previous steps. The default is to remove information present in the database (if any), which won’t be a problem if you created a blank database.
Your web host is likely to be still set to ‘localhost’ despite this being a live server. This may vary across hosting providers. So, if you face any problems, contact your provider.
Once again, you’ll find some options here, but in most cases, the defaults will be perfect. Click ‘Test Database’.
If this passes, it would mean that the Duplicator can successfully connect to your database. Click ‘Next’.
If you see any errors here, then cross-check the details you have entered and contact your hosting provider if you’re unable to resolve it on your own.
Now, your database will be installed. It may take some time, depending on your database’s size.
3. Update data
Now that the database has been installed, you will have to fill in your new URL, website title and the path to where the database should be installed on the server.
Though Duplicator attempts to fill this out automatically, it is recommended to check if the information is correct. Once done, click ‘Next’.
4. Test site
Now, your website should be live. You can click on the ‘Admin Login’ link. Ensure that you check ‘Auto delete installer files’ after login.
5. Delete Installer files
Once you have logged in to your WordPress dashboard, the installer files will be deleted automatically if you had checked the ‘Auto delete installer files after login’ checkbox. Even if you forgot to do it, you can still delete the files (manually) using SFTP.
6. Flush your permalinks
Permalinks are links to the posts and pages on your website and their underlying structure. Sometimes, your page/post URLs may not work on your recently migrated website unless you flush out your permalinks first. You can do this with a simple process –
- Login to your WordPress dashboard
- Go to Settings → Permalinks
- Click on ‘Save Changes’
7. Test your live website for errors
Check if – the links and interactive elements are working fine, you’re able to install new plugins ad submit forms, admin pages are loading correctly, the front-end looks as expected, you can add/edit posts/pages, and other functionalities.
Once you are sure your website is working perfectly fine, set up regular backups (you can do this with the Jetpack Backup plugin) and your website is ready to be accessed by the public.
Hope this article was helpful for you.