How To Replicate A WordPress Website From Server To Localhost

You are here:
< All Topics

Replicating Website from to http://localhost on laptop.


First install Apache, MySQL/MariaDB and PHP on laptop.


Then create a database with the same name and connection/login credentials as on the server.



Next, install the WordPress Duplicator Plugin on on the server. We are using the Duplicator Lite (free version) not the paid for pro-version.


This has one drawback: the links within the website to https:/ cannot be changed using Duplicator, so we have to use other means to do this.


A further problem (not Duplicator related) is the use of https SSL/TLS on the server, while the localhost on the laptop uses http (http://localhost).




We were not able to convert the localhost instance to http.



This meant that when calling up http:/localhost in the web-browser, the link would automatically default to https and connect to the https:/ external public url. This also meant we could not access the WordPress admin account on the localhost.


The only way around this problem was to temporarily change the configuration of from https to http, then perform the Duplicator export.



We would then be exporting to http:/localhost and not https:/



This was possible.



This is done by modifying the sites-enabled file /etc/apache2/sites-enabled/ on the server:


the lines with double hash sign ie ## have been temporarily commented out for this purpose:

root@gemini:/etc/apache2/sites-enabled# cat


<IfModule mod_ssl.c>
##<VirtualHost *:444>


<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.




ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf


##Include /etc/letsencrypt/options-ssl-apache.conf




SSLCertificateFile /etc/letsencrypt/live/
##SSLCertificateKeyFile /etc/letsencrypt/live/




Then execute:


systemctl reload apache2




systemctl reload apache2


The site should now be operating in http mode instead of html.


After exporting the site using Duplicator, return the config to the original state and perform the a2dissite and a2ensite steps again. https service will then be restored.



The export file was 2.4GB in size. There is also an installer.php provided by the plugin specifically for this export file. You manually copy these two files to the laptop destination machine.


From there, these two files are moved to the root document folder of the website on the localhost, in this case /var/www/html.


The installer.php from Duplicator is then executed from a webbrowser:




Then follow the instructions from Duplicator installer.php in the browser display.


The process takes several minutes.



We then still had a problem with the links. Entering http://localhost would only display the home page of the site. All other pages were not accessible.


Further configuration was necessary.


In phpmyadmin we changed the kevwells database table wp_options entries for siteurl and blogname from and to http://localhost and localhost respectively.


We then added






to wp-config.php


this file also has to contain the definitions for the database connections:


// ** MySQL settings – You can get this info from your web host ** //

/** The name of the database for WordPress */

define( ‘DB_NAME’, “kevwells” );

/** MySQL database username */

define( ‘DB_USER’, “wordpressuser” );

/** MySQL database password */

define( ‘DB_PASSWORD’, “*****” );

/* password is commented out here for security reasons */

/** MySQL hostname */

define( ‘DB_HOST’, “localhost” );



the .htaccess file is empty:


kevin@asus:/var/www/html$ cat .htaccess
# BEGIN WordPress
# The directives (lines) between “BEGIN WordPress” and “END WordPress” are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

# END WordPresskevin@asus:/var/www/html$



We then installed a further WordPress plugin: Go Live Update Urls


this is to change the Url site references within the website from to http://localhost


However the content would still not display, although we could open the WordPress Admin for localhost successfully.


The solution was to execute the Permalinks settings in WordPress Admin, changing them from custom to plain, saving the settings.


The website then displayed correctly.


The only part of the content which gives a not found error are the pages (eg terms and conditions, disclaimer etc), posts are ok.


We now have a static replica of the instance running on the laptop as http://localhost


Table of Contents