Having a working copy of WordPress hosted on your local Desktop or Laptop is very advantageous. You can easily test any kind of scripts. You can modify the PHP script and test whether it is working or not without taking any risk of making your blog/website down for a single moment. It also help in designing anything on your blog. After testing everything is working as the way you want, you can compare and upload your code to live blog. It will work as a good backup of your system too.
(This guide is more about importing and installing WordPress working copy from live server and not for installing fresh copy of WordPress).
Importing and Installing WordPress on Localhost (127.0.0.1):
Before importing your WordPress code and make it working on you local system you need a FTP client and working Apache, PHP and Mysql. Filezilla is my preferred free FTP client. For Downloading and installing Apache, PHP and MySQL, I will suggest using XAMPP. It is one package and install everything you need at a time. It also include phpMyAdmin for working with Database. After installing everything you are ready to rock and experiment with WordPress coding.
Installing WordPress on Localhost:
- Download Database,
- Create Database on localhost
- Import downloaded sql file through phpMyAdmin,
- Download PHP + all files and folder. You will get three folders and several files inside docroot of your live hosting. Three folders are wp-content, wp-admin, and wp-includes and few files will be on the root folder.
- Now, dump all the files and folders into htdocs folder of your xampp installation. If you have installed xampp in C: directory then your xampp's htdocs folder path will be C:xampphtdocs. You may not want to clutter your root (htdocs) folder with lots of files inside it. So, you can choose to install in inside a folder in htdocs. Create a folder inside C:xampphtdocs. For example, I will create a folder- ws. So, dump all the files and folders into C:xampphtdocsws.
- Open wp-config.php inside 'ws' folder. (in our example, we have planned to install WordPress inside 'ws' directory. Change database setting. Below you will find sample code and example.
- You need to add two lines of codes also so that the downloaded WordPress installation can understand that the URL has changed. Or, you can changed the table - wp_options. Look for the field - siteurl and change the value to - http://localhost/ws .
If you want to mention change in wp-config.php file itself then add these line there:
- Now, check in your browser. It should be working.
- You may need to make changes in .htaccess file and plugin as well. As many plugin need to be updated for this big change. You can un-install any plugin and install it again and it will start working. For uninstalling any plugin you can rename the folder of the plugin. According to our example, you will get your plugins inside C:xamppwswp-contentplugins. Plugin which are related to changing path/redirection may be needed to disable. You need to think of it, what kind of plugins you are using.
- Check the .htaccess file inside C:xamppws and open it in any text editor. Search for any path mentioning old address. Replace with new address. Wherever you see path mentioned without http, think of it as a relative path. For this you need to modify it according to current local environment. Example old Path: /wp-content/themes/inove/style.css will become /ws/wp-content/themes/inove/style.css. For the plugin you think may be causing problem, also delete the htaccess configuration for that plugin. Plugin generally mark their setting with # Begin plugin and # End plugin. Delete all the lines between them for any plugin you want to disable. One line you also need to search for the current installation style. The line is:
RewriteRule . /index.php [L]
Change this line to:
RewriteRule . /ws/index.php [L]
Database info inside wp-config.php file:
define('DB_NAME', 'ws'); /** MySQL database username */ define('DB_USER', 'root'); /** MySQL database password */ define('DB_PASSWORD', 'rootxyz'); /** MySQL hostname */ define('DB_HOST', 'localhost');
Hopefully, this may have helped you in set up and installation of wordpress on localhost. Care this by sharing this!
Update: I have found that installing WordPress in a folder inside localhost will give you little difficulty. Your path will be become little different at many places. Like in my example, path will be '/ws/wp-content/uploads/2009/11/webscript.png' on localhost whereas on live it is '/wp-content/uploads/2009/11/webscript.png', So, it is better to install wordpress directly inside localhost! In this case in the above guide, you need to discard 'ws' in the all the path.
You can remove two lines of codes (path) you have added in wp-config.php, so that it cannot go live mistakenly.
If you struck in Path/Location related changes check, use this guidelines.