setting up vhost in xampp - php

I am facing a minor problem while setting up vhost in xampp os - windows. here is the httpd-vhosts.conf in C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/yiisite/basic/web/"
ServerName yiisite
and in hosts file located C:\Windows\System32\drivers\etc\hosts
127.0.0.1 yiisite
so when i hit i get http://yiisite i get what i want, but all other folders inside htdocs that i use to open in localhost/abc is all going to yiisite template 404 not found . cannot access other projects inside htdocs with localhost . if i change the port in vhosts.conf i can access localhost/abc but not yiisite

changing the httpd-vhosts.conf to
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:/xampp/htdocs/yiisite/basic/web/"
ServerName yiisite
</VirtualHost>
solved the issue of conflicting with other projects inside htdocs and can access with localhost/otherproject

Related

How to Fix 404 Error After Fresh Magento 2 Installation

I'm trying to install Magento 2 to run on my local machine. I've followed the tutorial here: https://javapocalypse.medium.com/install-magento-2-4-on-windows-10-2021-a0c433e4ffc4, but when I go to localhost/magento I get a 404 error and am not sure how to fix it. I've tried replacing the .htaccess file in the root directory with the .htaccess file from /pub, and I've also tried moving index.php from /pub to the root directory, but have had no luck.
Any guidance would be appreciated.
Check if you did below steps
Add entry in host files C:\xampp\apache\conf\extra\vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/magento/pub"
ServerName localhost/magento
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
Add entry in hosts file
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 localhost/magento
I suggest you to use a different url like dev.magento.com instead of localhost/magento.

local assets(css/js) not found when using apache virtual host

I've added 127.0.0.1 my.pro to my hosts file
and add below code to httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/ci4/public"
ServerName my.pro
ErrorLog "logs/myproject-error_log"
CustomLog "logs/myproject-access_log" common
</VirtualHost>
the problem is i can't reffer to my assetes. assetes and project index page are in defferent directories.
-ci4
--public
---index.php
--assets
---css
C:/xampp/htdocs/ci4/public is project root and i locate assetes in C:/xampp/htdocs/ci4/assetes .
when I try to load a CSS file with this resource http://my.pro/assets/css/style.css it shows 404 error.
I know apache tries to load file from C:/xampp/htdocs/ci4/public/assets/css/style.css which doesn't exist.
but I have no idea how to fix it!

Why I can't set a vhost for this PHP website on my XAMPP?

I am finding the following problem trying to create a vhost for a PHP website that I have into XAMPP.
So basically this is where is the index.php file of my website is deployed: C:\xampp\htdocs\MyProject-Panda
Then into the C:\xampp\apache\conf\extra\httpd-vhosts.conf** file I have declared 2 vhost:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/MyProject-Panda"
ServerName panda.dev
</VirtualHost>
(the first one works fine, the second one no).
Finally into the C:\Windows\System32\drivers\etc\hosts file I have:
127.0.0.1 localhost
127.0.0.1 laravel.dev
127.0.0.1 panda.dev
So I am enabling the panda.dev domain on my local machine.
The problem is that when I open the panda.dev domain into my browser it is automatically "rewrited" into http://www.panda.dev/ and it says that can't contact the server.
Why? What could be the problem? How can I try to solve this situation?
You should use .local for local sites. .dev must not be interpreted correctly by browsers, even if you have hosts record.
In this case I think problem is - you have some .htaceess in C:/xampp/htdocs/MyProject-Panda with redirect to WWW version. Windows hosts does not work for subdomains automaticly (as www.panda.dev is subdomain of panda.dev). You eighter has to remove this redirection or add 127.0.0.1 www.panda.dev record to your hosts file.

Apache VirtualHost Issues

I have two installations of laravel. One in a folder called "laravel" and the second in a folder called "learningLaravel". Both of them are siblings in the same parent folder. Before i installed "learningLaravel" i used to access the site in "laravel" through localhost/laravel/public, and everything works fine .
After i installed "learningLaravel", i decided to create a virtual host for it on my WAMP server with the name "learningLaravel.dev" . My [windows/system32/drivers/etc/hosts] file looks like this:
127.0.0.1 localhost
127.0.0.1 localhost
// I added this entry. The first two entries above was already there
127.0.0.1 learninglaravel.dev
I added the following to my Apache "httpd-vhosts.conf"::
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
</VirtualHost>
Now i can access "learningLaravel" through learningLaravel.dev. But when i want to access the site in the "laravel" folder through localhost/laravel/public, i get a message ::
Not Found
The requested URL /laravel/public was not found on this server.
I try localhost also and i get ::
Not Found
The requested URL / was not found on this server.
The problem i have now is anything that begins with localhost doesn't work, but learningLaravel.dev works.
What changes do i need to make? thanks.
Just define 2 virtual hosts:
The first catches all domains which don't have their own virtual host. In this example these are domain1.dev, domain2.dev, domain3.dev and localhost.
The second host catches the domain learninglaravel.dev
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>
<VirtualHost learninglaravel.dev:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learninglaravel.dev
ServerAlias *.learninglaravel.dev
</VirtualHost>
windows/system32/drivers/etc/hosts
127.0.0.1 learninglaravel.dev
# you don't need the following this is just for explanation:
127.0.0.1 domain1.dev
127.0.0.1 domain2.dev
127.0.0.1 domain3.dev

How to rewrite url like a sub domain

I want to change my localhost project URL as:
http://localhost/project_directory to http://project_directory.localhost
and http://localhost/project_directory/backend to http://backend.project_directory.localhost
Can you help me someone how to write rule in .htaccess?
You can create a virtual host in Apache.
<VirtualHost *:80>
ServerName project_directory.localhost
DocumentRoot "C:/public_html/project_directory"
</VirtualHost>
And add this line to your hosts file:
127.0.0.0 project_directory.localhost
Your hosts file is located in: C:\Windows\System32\drivers\etc
Edit the hosts file with Administrator rights.

Categories