Today i’am sharing with you little trick, which can help you when you build wordpress in your localhost and at the and to move it to server.
We know that for this purpose there are a lot of plugins and there is also manual way to do it.
- Moving filesystem – required step
- Moving(export->import) database – required step
- Changing DB details wp-config.php – required step
- Changing sitename and homepage rows in wp_options mysql table – required step
- Updating post content, post guid etc. which contains localhost strings – optional step.
But with performing little trick in our local computer we can avoid 4 of 5 steps above. What is this trick? It is called HOSTS.
Here is how to do it:
Before installing wp in your localhost (f.e. in public_html) open your system hosts file (for Windows it is in C:\Windows\System32\drivers\etc folder, for Linux it is in /etc/ folder, for OSX it is in /private/etc/ folder.)
put this line there:
127.0.0.1 mysite.com
Save it. That’s all. Now extract wordpress zip file to your public_html/ localhost folder. Then open mysite.com in your browser, you will see localhost wp installation there. All options for this localhost website will be considered for mysite.com. That’s why when you migrate it to server, it will not need any changes. You will only need to change database name,password in wp-config.php.
Note that installing wp to any subfolder in your localhost will need another config. Because hosts works with only IP based redirection. For example the row “127.0.0.1/mysite mysite.com” will not work there. So you need to set 127.0.0.2 for this new subfolder and then to set
127.0.0.2 mysite.com
on your hosts file.
So, if your localhost’s public_html folder is busy and you have to install new wp to localhost subfolder. You can do it in your webserver config files(Apache, Nginx etc.). You should create new localhost website for this subfolder there – how to do it? – In the next article i will explain how to create new 127.0.0.2 localhost for any subfolder of your main localhost with Apache. And they both will work perfect.