Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gitwithravish's avatar

Getting 404 error in every laravel project after adding a virtual host in xampp.

I followed a video on youtube and did the following changes in my xampp files. C:/xampp/apache/conf/extra/httpd-vhosts

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/project1/public"
    ServerName project1.test
</VirtualHost>

C:\Windows\System32\drivers\etc\hosts

127.0.0.1    project1.test

Everything works fine for project1, but every other project in my xampp folder is showing 404 not found. I think I have done some silly mistake. Everything on localhost is redirecting to project1 and that is probably causing this.

0 likes
8 replies
mvd's avatar

Hi @ravish

Can you show us the whole C:/xampp/apache/conf/extra/httpd-vhosts and C:\Windows\System32\drivers\etc\hosts file?

Can you also give us a link to the Youtube video?

eggplantSword's avatar

@ravish This is how I have mine

httpd-vhosts

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/blog/public"
    ServerName blog.me
    ErrorLog "C:/xampp/htdocs/blog/public/error.log"
    CustomLog "C:/xampp/htdocs/blog/public/access.log" common
</VirtualHost>

hosts looks the same to me, did you try and restart the apache?

1 like
MarianoMoreyra's avatar

Hi @ravish

You should have one block like that for every project you have, and the same with hosts file.

For example, for 2 projects project1 and project2 you could have:

httpd-vhosts

<VirtualHost *:80> 
    DocumentRoot "C:/xampp/htdocs/project1/public"
    ServerName project1.test
    ServerAlias *.project1.test
    <Directory "C:/xampp/htdocs/project1/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80> 
    DocumentRoot "C:/xampp/htdocs/project2/public"
    ServerName project2.test
    ServerAlias *.project2.test
    <Directory "C:/xampp/htdocs/project2/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

and then at your hosts file:

127.0.0.1    project1.test
127.0.0.1    project2.test

Remember to restart your Apache server after this modifications

gitwithravish's avatar

@marianomoreyra so do u mean to say i cannot use localhost/... urls with a virtual host setup? Is it like i can use only one of the approach?

automica's avatar

@ravish that's correct. once you use virtual hosts, your localhost goes to the first named host as you discovered.

1 like
MarianoMoreyra's avatar

@ravish if those projects had no domain and you were accessing them with http://localhost/project-name then you should use a different root folder for project1, outside your htdocs.

Also, I think you should define a default configuration for localhost although I’m not sure right now if it’s necessary (and I’m not in front of my laptop to search through apache documentation)

1 like
MarianoMoreyra's avatar

@ravish if you have your DocumentRoot pointing to your htdocs directory, your localhost apps should works as always.

This is what I have (adapted to your path), and it works both ways for me:

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">

    Options Indexes FollowSymLinks Includes ExecCGI

    AllowOverride None
    Require all granted
</Directory>

Please or to participate in this conversation.