How to set up virtual hosts on Windows

The one in my post #18 above. I think that covers it all. :smiley:

I think you mean Stack Path tut - I tried that - deleted file, replaced with -

    <VirtualHost *:80>
    DocumentRoot "c:/xampp/htdocs/WordPress"
    ServerName WordPress.localhost
    <Directory "c:/xampp/htdocs/WordPress">
    </Directory>
    </VirtualHost>

but will still only accept paths like -

<link rel="stylesheet" href="css/bootstrap.min.css">

and not with the preceeding ‘doc root’ / like -

<link rel="stylesheet" href="/css/bootstrap.min.css">

Page loads but not css

OK, well Im stupid because I replaced with example code from tutorial which is a wordpress example and I’m not using wordpress !

So replaced entire file with just -

<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/MyProjects/learning"
ServerName WordPress.localhost
<Directory "c:/xampp/htdocs/MyProjects/learning">
</Directory>
</VirtualHost>

as this is my current project folder - and it works !!!

Now when I type localhost in my browser it goes straight to this folder and both path types work no / and with / so now I can code locally and update to remote and don’t have to change code - perfect!. Awesome - thanks so much.

One more question if you don’t mind - do I have to overwrite conf file for every project or can I add multiple procect folders in the conf file ?

Yes, you can add how many* you want! I think the tuts cover that too. Otherwise you have the Apache docs:

https://httpd.apache.org/docs/2.4/vhosts/examples.html

Well done! :+1:

*)
The safest way to prepare for the dev site to work live on the web server without any database errors is to use the same domain name for the dev site as the live one.

But that would make it awkward to access the live site from the same machine if you’ve not temporarly commented out that line in the W10 hosts file.

Nooo - well done to YOU my friend !!!

1 Like

Forget Xampp, Use Laragon. Among other things, it automatically creates the V host for you. You will access your app with http://foldername.test

https://laragon.org/

I have used all the Windows WAMPS. Laragon is currently the best for many reasons.

1 Like

meh, that only works if you also use the same credentials for MySQL etc. Really would NOT recommend that.

At work we use domain.tld for production, dev.domain.tld for dev, staging.domain.tld for staging etc. Quite easy and predictable. Plus, since these are subdomains you can ensure it won’t accidentally leak cookies from prod to dev or vice versa.

2 Likes

Good to know. :smiley:

What I had in my mind was an old thread here where a local WP site had saved some complete absolute URLs in the database. I researched WP and found that it could happen even if all resources used dynamic URLs.

Had the local site used the same length of domain-name it would have been easy to search and replace the raw files when it was discovered.

I’m not, since many years, developing WP sites anymore so I’ll stop recommend that. :slight_smile:

Ah yes, that right there is the real problem - and a real bad practice. Never store full URLs in the database, only relative URLs if you really really have to.

2 Likes

I really appreciate all the helpful comments. I don’t really want to learn more technologies here and I think migrating fro xampp is too big a task at this point. For me I think I will go with the vhost file amendment and particularly thank @Erik_J for his assistance but am also grateful to all others.

This solution means I can code and test fully locally, even offline and then upload live with no changes, this is perfect for me.

Thanks again guys

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.