I love using WordPress, but there’s one process that really annoys the heck out of me when I’m developing websites with it and that’s deployment from a localhost server to a live web server. There’s no set way to do this, but this guide attempts to solve that problem. This is the method I’ve found most reliable when deploying websites from localhost to a web server.
Tools Used In This Guide
- phpMyAdmin
- jEdit (or other editor able to do global string replacements and save in UTF-8 format)
- FileZilla
Steps to Deploy WordPress From Localhost To Your Web Server
- Export your DB from the localhost using phpMyAdmin as a .zip
- Extract the zip locally somewhere for editing
- Open the .sql file in jEdit (or equivalent UTF-8 capable editor) and do a string search for localhost
- Find the string you need to replace, usually http://localhost/your-site depending on how you’ve setup your local server.
- Do a global string replace using the replacement string you found and replace it with your new domain, something like http://your-domain.com
- Save in UTF-8 format. You might want to save as a new file just in case you need to revert.
- Using phpMyAdmin on your destination web server create a database and import the new .sql file. With some cPanel hosts like Bluehost it’s easier to create using cPanel’s tools then edit in phpMyAdmin for importing the file. If all is okay you should now have your database setup.
- Using FileZilla (or equivalent FTP program) upload your website’s files to the web server.
- While the upload is happening, it’s time to create the wp-config.php file for your production instance, make a copy of the existing wp-config.php file in your WP root directory.
- Open and change the database value to the name of your web server’s database for your site. Also, change the username and password for the database as required.
- Save this as wp-config.production.php and upload to your web server.
- Once all uploading is complete, using FileZilla rename the existing wp-config.php file on your web server to wp-config.development.php and also rename wp-config.production.php to wp-config.php. Your new config file is now in effect.
- Before you get all happy and try to visit your website you need to login to the WordPress admin and navigate to the Permalink settings. Once there just click the save button (don’t change anything, just re-save it). This resets the permalinks to your new URLs so the links to pages and posts will work throughout your site.
And that’s all folks!
Any questions, send me a comment below and I’ll see if I can help you.




Why not set up /etc/hosts and your httpd.conf to point the domain at 127.0.0.1 instead? That’s a bit of pain, but not as much as doing this. I know this from experience!
Good point! And yes, very doable that way. I might play that for my next website design project.
I guess doing it my way avoids having to keep things in sync, especially if you don’t own the server on the other end. Also, the major reason for me is domain names can change partway through a project. I’ve had this happen a couple of times and it can be a pain in the neck.
Whichever way you choose to do it, it’s good to document the workflow
Here’s a related “gotcha.”
If you use this (or similar) technique to move a site from one db to another db on the _same_ server, don’t forget to restart the server at some point.
It really helps. Heh.
Hello,
I still have some trouble importing the .sql file to the web server. it always give error
Error
SQL query:
–
– Database: `web1`
–
– ——————————————————–
–
– Table structure for table `wp_commentmeta`
–
CREATE TABLE “wp_commentmeta”(
“meta_id”bigint( 20 ) unsigned NOT NULL ,
“comment_id”bigint( 20 ) unsigned NOT NULL default ’0′,
“meta_key”varchar( 255 ) default NULL ,
“meta_value”longtext,
PRIMARY KEY ( “meta_id” ) ,
KEY “comment_id”( “comment_id” ) ,
KEY “meta_key”( “meta_key” )
) AUTO_INCREMENT =1;
MySQL said: Documentation
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘”wp_commentmeta” (
“meta_id” bigint(20) unsigned NOT NULL,
“comment_id” bi’ at line 11
Please help
Most common problem is that you forgot to use UTF8 character encoding.
If you’re using jEdit check your buffer options under utilities menu and start again with the original file (always make a back up).
Hi
Good guide, but it should include that one may encounter an error such as:
—————————-
Error
SQL query:
–
– Database: `samfunnet`
–
CREATE DATABASE `samfunnet` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
MySQL said: Documentation
#1044 – Access denied for user ‘****’@'localhost’ to database ‘samfunnet’
—————————-
I found an answer somewhere (sorry, I closed the tab). Ach, but that did not fix it either.. all in all moving my WP site online is a great hassle for a newb like me ._.
Hey Nicholas,
Yeah it can be a pain in the ass the first time you do it. But it gets easier once you find a method that works.
First up, check the character set that your database uses and make sure you are exporting under that character set and importing under the same set. You’re using latin1 and swedish for your database. That means step 6 will be save in whatever format you’re using.
I just find UTF-8 is the most common storage character set on mysql databases and causes the least problems with character replacements. Some of the latin sets insert funky characters which will screw up all your posts.
Second, when exporting, you usually don’t need to export the whole database, just the tables. So in phpMyAdmin make sure you’ve clicked on the database before pressing export and it will just export the tables.
Most hosts will have a special tool for creating the database, so this is an important step as you won’t be able to create a new database in phpmyadmin with your user (which is the actual error you’ve received).
All the best and feel free to comment again if you’re stuck.
I know the question is old, but just to help others that might get here with the same problems.
Delete line “CREATE DATABASE `samfunnet` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;” and add this right where it was:
USE `samfunnet`;
It should wokt now.
Thanks for the tip Julio!
thank you this really helped
Glad you found it helpful Blruk
Great tutorial, would have been very tricky without this guide. Thanks Josh!
Thanks Naim! Glad you found it useful
Thank you very much for your tutorial. I really needed it.
No problem, glad you found it helpful Erdei!
Hi,
This is a very useful post, just wanted some clarifications. I have a php mysql application package and I am trying to do web hosting for this application. I am told to do cPanel, Filezilla. Do I have to upload mysql separately and then the php part? or could I just upload the entire application zip through the filezilla?
Hi Viji,
Use filezilla to transfer the file to your server. Then you’ll need to setup the database via cPanel and then import it.
Hope that helps!
I have deployed wordpress from my local machine to server. I am getting the content but the images are not coming also the content is in the format,
Please let me know what changes i have to do to get the blog in proper shape .
you can visit the blog by clicking http://www.ileaf.in/blog
Please help
Thanks in advance
Hey Mustafa,
Looks like a lot of your files are still referencing localhost. If you look at the source for the page you’ll notice your stylesheet for example is pointing at localhost, you need to adjust all the addresses in any PHP files in your theme to point to your web server.
Cheers,
Josh
Hi Josh,
Thanks for your reply, I have done the necessary changes. My blog page is getting displayed . But after logging to the Admin Page (wp-login.php) while clicking on log in the next screen became white without any error message.
Please let me know what the issue here.
Thanks for your help
Mustafa
Hey Mustafa, did you replace the localhost entries in your SQL file before uploading to your server? Sounds like you might still have some entries as localhost rather than your url in your database.
Hi
I have created a website on my local PC under localhost/website. Now I wanted to upload this site to the actual URL which is under my college domain. The main website of the college is hosted from someplace else and I do not know the configuration of:
1. PHP [mail function] for sending email to the registered users of my website to activate their account, which is currently not working.
2. MySQL username, password, database name and hostname.
3. I only have the username and password for FTP uploading for a website sub-domain.
For uploading the website, I tried to:
1. Export the current database to a .sql file using phpMyAdmin
2. Create a new database
3. Change the URL from http://localhost to http://mywebsite in the .sql file and wp_options table
4. Import the .sql file to the new database
5. Created a MySQL user and granted it all the rights for the new database with username and password
6. Change the wp-config.php file with the name of new database, username, password and hostname as localhost
7. Uploaded the contents of the website directory via FileZilla
The problem is:
The site is not accessible. It shows HTTP Error 500.
My question is:
1. What have I done wrong?
2. Do I also need to upload the .sql file or should I ask the person who is hosting the main site to change the MySQL server settings (dbname, user, passwd, hostname) at his location?
3. What can I do enable sending of emails from the site: Ask the hosting person to give the addr and port of smtp server and change it at my location or ask him to change it at his location?
I have started using WP 2 days back and I would be thankful if someone answers my questions about MySQL and PHP [mail function].
Thanks
Hey Raj,
That’s one big comment
I’ll do my best to help…
My question to you: If you don’t know the MySQL details of your host then where did you upload your .sql file after changing the URL? Do you have access to the remote server’s phpMyAdmin console?
If you’re receiving a HTTP Error 500, my first step is usually to goto the wp-config.php and turn on debug mode which will give you the PHP error output.
Look for the line:
define('WP_DEBUG', false);And replace it with:
define('WP_DEBUG', true);As for the mailing issue.. that’s usually PHP mail isn’t setup on the host. It could be that your local machine doesn’t have it setup (some copies of XAMPP don’t have it on by default for example). I’d wait until you sort out the other issues before troubleshooting this, but it’s likely something your host will need to change.
Cheers,
Josh
Thanks for replying Josh… nobody was replying on other sites
I do not have access to the remote server’s phpMyAdmin or MySQL… now that you asked I think I have been doing it locally and this seems to be the fault.
I think I will ask my employer to give me a MySQL and phpMyAdmin username so that I can access server control panel remotely. Is this right?
Thanks Again
No worries mate.
Yep you’re exactly right, the SQL needs to be uploaded to the remote host’s MySQL which would be why your site can’t find what it needs.
Come back if you have more problems, sounds like you’re a cluey guy though so I’m sure you’ll figure it out if you’ve managed to work out WordPress in 2 days!
Thanks a lot
I will get back to you once I get access to server’s MySQL and phpMyAdmin
Thanks man! It works like a charm!
Hi…
We are creating one site in wordpress at localhost using xamplite. But when we deploy it on server its shows some database error, we solve it by using phpmyadmin import and export function. And also change the name in localhost to our current domain name in .SQL file.
But still its shows the category page as http://localhost/demo/ or http://localhost/demo/?page_id=2
so please help us. Where we want to change.
Thanks,
Sudhakar & Team
Hey Sudhakar, if it’s still showing localhost then there must still be some entries in the SQL as localhost. Make sure you do a string replace using a tool like jEdit otherwise you’re likely to miss some if you’re just going over the file by hand.
Is there any way to upload the .sql file without bluehost. I got filezila to upload the site but my problem to upload the database
Hey Arun,
Yep you can, do you have access to phpMyAdmin? If not, you can import the database using mysql command line.
hi, i have prob i make wordpress website in my own folder. when i transfer site all time wp-admin page not open original site but open old site please help me.
Hey Rajan,
So you put WordPress in a subdirectory? Well you need to add that directory to your URL before the wp-admin bit to login. You’ll also need to make sure that you change your links in your database. It’ll be a real mess if you didn’t have it in it’s own subdirectory when you were developing it in your localhost though… best of luck!
Thank you for sharing such a great tip! It helps a lot.
Hey Josh,
You just save me from a nervous breakdown! Your solution works like a charm even if you mix up the steps…
Haha that’s brilliant Samuel. Glad you got it all sorted!
Hi Josh Kohlbach,
Please I really need your help in details. I have follow the 13 steps to upload my local site to live website but here is the message received whenever I visit the site:
401 – Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
I set up the database but i don’t know how to allot “full user permissions” to the user.
elp please.
Hey William,
401 unauthorized access sounds like it could be a htaccess problem. Delete the .htaccess file from your root directory and see if that helps.
Cheers,
Josh
Thanks. It really helped. immediately you mentioned .htaccess, i used google to search for all .htaccess related problems and i found out that there is a need to request for .htaccess setup by my host. They did and call it web.config. Thereafter, i am able to visit and login-in to admin panel.
But, I discovered that all the products pictures are not showing unless you select and zoom. I used eshop template. Please, visit nbcpublications.com and help me out.
Thanks for the great job you’re doing. More grease to your elbow.
Cheers.
No problems William, glad you figure that one out.
The picture problem looks like permissions. You’re using a script called TimThumb which needs write permissions on your server.
http://nbcpublications.com/wp-content/themes/eShop/thumb.php?src=http://nbcpublications.com/wp-content/uploads/products_img/2020.jpg&w=256&zc=1&q=80
Show your server guys that error and they should be able to figure it out.
Cheers,
Josh
thanx sir, it really worked for me.
This worded perfectly. The only other thing I needed to do was use WP Migrate DB to move MYSQL Database over. Check it out, what do you think?
Thanks by the way for posting this. I learned a lot from this. Noob here.
Thanks Jack, glad you found it helpful!
Thanks a lot man!!!
You’re my life savior!!!
No worries Acao