To set up a virtual host configuration for a local WordPress setup on XAMPP, follow these steps:
Open the Apache configuration file: Navigate to the XAMPP installation directory and locate the httpd.conf file. It is typically found in the apache\conf subdirectory. Open the file in a text editor.
Uncomment the virtual hosts include: In the httpd.conf file, search for the line that includes the httpd-vhosts.conf file. It will look like this:
# Include conf/extra/httpd-vhosts.conf
Remove the # character at the beginning of the line to uncomment it.
Save and close the httpd.conf file.
Open the virtual hosts configuration file: Navigate to the apache\conf\extra subdirectory within the XAMPP installation directory and locate the httpd-vhosts.conf file. Open the file in a text editor.
Configure the virtual host: Add the following code to the httpd-vhosts.conf file to create a virtual host for your local WordPress setup:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/wordpress"
ServerName mywordpress.local
<Directory "C:/xampp/htdocs/wordpress">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Modify the DocumentRoot path to the directory where you have installed WordPress on your XAMPP setup. Also, update the ServerName to the desired hostname for your local WordPress site.
Save and close the httpd-vhosts.conf file.
Edit the hosts file: Open the hosts file on your computer to map the hostname to the local IP address. The hosts file is typically located at C:\Windows\System32\drivers\etc\hosts. Open it in a text editor.
Add an entry in the hosts file: Add the following line to the hosts file:
127.0.0.1 mywordpress.local
Replace mywordpress.local with the same hostname used in the virtual host configuration.
Save and close the hosts file.
Restart Apache: Open the XAMPP Control Panel and stop and start the Apache service to apply the changes.
Access your local WordPress site: Open a web browser and enter the configured hostname (mywordpress.local in the example) in the address bar. You should now be able to access your local WordPress site using the configured virtual host.
By setting up a virtual host, you can access your local WordPress site using a custom domain name (hostname) instead of using localhost or an IP address. This allows you to simulate a live website environment for your local development.