Thursday 24 September 2015

Installing Wordpress on a Local Server(local machine) and Database on a Remote Server or Hosting Server

I am new to Wordpress so any suggestions or corrects in the post are welcome.

Now one would think why would you ever want that kind of setup for a Wordpress site. But believe me it reduces a lot of effort. In a minute you'll realize what I am talking about.

I prefer customizing the look and feel plus a little here and there of Wordpress sites locally before deploying them on the server. Of course it is possible to edit the code once the site is deployed from the wp-admin panel but then I find it quite inconvenient especially when the bandwidth is low(slow net speed). So I prefer doing it locally using other editors available like Notepad++.

So that means you edit and fill in all the initial stuff you got locally and then perform the following steps:

  • Export the local database
  • Import the database into the Hosting Server
  • Using any client FTP (for eg. Filezilla )transfer your locally developed website to the Hosting Server
  • Then make changes in the database so now the website refers to the actual domain instead of the localhost.

This database thing is a nightmare especially for those who are not from the programming background. Sometimes due to encoding issues it becomes a headache even for those with experience.

A better way (actually a less painful way) is to have the Wordpress Database of your website on your Hosting Server right from the start of your installation. This way you won't have to go through the pain of migrating the database from your local machine to the Hosting Server.

  • Simply create a database on your Hosting Server.
  • Now if using WAMP extract the Wordpress Installation in the C:\wamp\www\ directory and rename the wordpress to your site name(or anything you want)
  • Open a browser and type localhost\your_wordpress_folder_name\
  • A page will open which will ask you to select the language of your choice. After selecting that you will be asked for your credentials.

Fill in all the credentials. 

  • Host name - url of database server   (for eg: mysql.yourdomain.com)
  • User Name - username of your database
  • Password - password of your database
  • Table Prefix - change this if you have(or want to in future) save content of several wordpress sites in the same database(i.e. one database for several sites)
  • Click on submit.
Now we come to the main focus of this Post

If all goes well then you will be directed to the Installation Page.

It is very likely that you'll get a error 'Error in Database Connection' inspite of filling all the credentials correctly.
This happens generally because your Hosting Service(for eg. DreamHost is what I use) does not allow connections from remote machines for security reasons.

There is a way to change this setting called 'Allowable Hosts'

On DreamHost the path to this is Goodies->MySQL Databases ->Users With Acess -> Click on the User 

On clicking on the user a new page will open where you will find a text-box of Allowable Hosts where you can fill in the IP address of the machine from where you want to allow access of this user to the database,

For your purpose DreamHost displays a 'You current computer is:xx.xx.xx.xx'. Simply paste that in the Allowable Hosts box and you are all set.

Try submitting the credentials again in your Wordpress installation and now it will successfully connect to your database and you can proceed with the installation.

Thats it! 

You can now customize/work on your Wordpress website on a local machine and when done simply just transfer the website to your Hosting Service using FTP without worrying about the database or other changes.

Note: Maybe this is not a clean and the only way but I find it very convenient to work in a editor of my choice. Synchronizing Databases from local to remote in PHPMyAdmin can also be another way but I haven't tried it out yet.

Thank You For Reading :D

No comments:

Post a Comment