Migrate Wordpress to Virtual host (Windows + XAMPP)

If you have tried to install Wordpress using XAMPP and just pasted the wordpress folder in your /htdocs folder I have bad news for you.

If you start using virtual hosts you will have to choose between two options.

Option 1: Install the site again once you have setup the virtual host

Option 2: Adjust the DB and the site files when moved to the virtual host

I would always vote for Option 1, if I haven’t made any content/adjustments. However life is not always easy so if you have many changes in your Wordpress it will be time for you to get your hands dirty.

1. Setup virtual hosts

Our first step will be related to setting up the virtual hosts. Check your C:\xampp\apache\conf\httpd.conf (Note: if you have installed XAMPP in different place find the apache/conf folder and search for the httpd.conf file) file.

Make sure that the line — Include conf/extra/httpd-vhosts.conf is not commented.

Once we have made sure that our XAMPP/Apache will load the vhosts.conf (C:\xampp\apache\conf\extra\httpd-vhosts.conf)file we could add the following lines to it.

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/exercises"
ServerName my-exercise.com
<Directory "C:/xampp/htdocs/exercises">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/wordpress"
ServerName my-wordpress.com
<Directory "C:/xampp/htdocs/wordpress">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>

We are defining two virtual hosts, one for PHP exercises and one for our Wordpress installation.

Note: We are planning to reuse the same folder for Wordpress!
Note 2
: If you are running older version of Wordpress you could check Changing The Site URL.

2. Alter your hosts file

Open C:\Windows\System32\drivers\etc\hosts file with notepad (You need to run Notepad as Administrator otherwise you won’t be able to save the file). Add the following lines

127.0.0.1 my-exercise.com
127.0.0.1 my-wordpress.com

We are stating that on localhost we will have two domains my-exercise.com and my-wordpress.com.

3. Create the structure for my-exercise.com

Create a folder exercises in C:\xampp\htdocs. Inside the newly created folder add a new file called index.php. The content of the file should be:

<?phpprint "Hello world!";

4. Adjust DB for Wordpress

Open phpMyAdmin or any other tool that you use for MySQL administration.

Open wordpress DB and find wp_options table. Modify siteurl and home options to have values of the new domain — which in our case is http://my-wordpress.com

5. Edit .htaccess file

Open C:\xampp\htdocs\wordpress\.htaccess and remove the code crossed in red

The updated file should look like this

Note: Don’t forget to restart your Apache server otherwise changes won’t be present!

If everything is running correctly when you open http://my-exercise.com/ you should see

When you open http://my-wordpress.com/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store