I have a local virtual host for my main site, local.mysite.com. I also have other virtual hosts for other projects I am working on. For instance, local.mygame.com. For some reason, after adding in the virtual host information and adding the string to my hosts file, whenever I access local.mygame.com, or local.phpmyadmin.com, it redirects to local.mysite.com everytime.
<VirtualHost *:80>
ServerName local.mysite.com
ServerAlias local.mysite.com
DocumentRoot /mysite/content
</VirtualHost>
<VirtualHost *:80>
ServerName local.mygame.com
DocumentRoot /www/mygame
LogLevel debug
</VirtualHost>
Hosts file contains:
127.0.0.1 local.mysite.com
127.0.0.1 local.mygame.com
It does a 302 redirect from local.mygame.com to local.mysite.com
Try adding "AllowOverride none" in case a .htaccess file is overriding your settings here
Related
I'm using XAMPP v3.2.4 and I don't know if this makes any difference but Joomla 3.9.14
In my local environment I access my Joomla site by visiting localhost/mysite. I now want to have a sub domain localhost/apps.mysite.
I've created a folder called apps and placed this in my Joomla root directory, which is C:\xampp\htdocs\mysite\apps. This folder contains a single index.html file.
I've made the following changes;
In my Windows hosts file I added the following line;
127.0.0.1 localhost/apps.mysite
In my httpd-vhosts.conf file I added;
NameVirtualHost 127.0.0.1:80
<virtualhost *:80="">
DocumentRoot "C:/xampp/htdocs/mysite/apps"
ServerName localhost/apps.mysite
ServerAlias www.apps.mysite.localhost.com
</virtualhost>
I haven't made any other changes to config files. I've restarted Apache a few times, no change.
When I visit the URL http://localhost/apps.mysite I see the following error;
Object not found! The requested URL was not found on this server. If
you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404 localhost Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.3.9
What do I need to change in order to access my subdomain at http://localhost/apps.mysite
First host file does not handle folders, just map IP addresses to hostname.
Host file should be
127.0.0.1 localhost apps.mysite
or
127.0.0.1 localhost
127.0.0.1 apps.mysite
I prefer the second method because I can comment the line..
Second Your virtual host ServerName localhost/apps.mysite does not work with sub folders.
Valid Servername values can be: domain.com, example.com, site1.example.com, user.site1.example.com and son on.
A virtual host example to map the apps.mysite should be:
<VirtualHost *:80>
ServerName apps.mysite
ServerAlias www.apps.mysite
## Vhost Document Root
DocumentRoot "C:/xampp/htdocs/mysite/apps"
</VirtualHost>
This is a minimal example, no logs defined or directory specific rules. With this configuration you will be able to reach your site by using http://apps.mysite only on your computer because the host file is resolving the "apps.mysite" to your localhost (127.0.0.1).
What do I need to change in order to access my subdomain at http://localhost/apps.mysite
http://localhost/apps.mysite is not a sub-domain is a domain localhost with a folder apps.mysite, a valid subdomain is subDomain.domain.com.
.com is a top level domain
domain.com is a domain name
subDomain.domain.com is a subdomain of domain.com
Hope it helps.
Start by creating a VirtualHost for localhost in case you want to use that for a bit of fiddling
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs"/>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
## then add main site
<VirtualHost *:80>
ServerName mysite.local
ServerAlias www.mysite.local
DocumentRoot "C:/xampp/htdocs/mysite/"
<Directory "C:/xampp/htdocs/mysite/"/>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
## then add the sub domain
<VirtualHost *:80>
ServerName aps.mysite.local
ServerAlias www.aps.mysite.local
DocumentRoot "C:/xampp/htdocs/mysiteapps/"
<Directory "C:/xampp/htdocs/mysiteapps/"/>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
You will need to add these 2 sites to your C:\windows\system32\drivers\etc\hosts file like this
127.0.0.1 mysite.local aps.mysite.local
::1 mysite.local aps.mysite.local
For the change to the HOSTS file you will either need to reboot or refresh the DNS Cache like this from a command window
>ipconfig /flushdns
I know I'm probably missing something simple, but I've exhausted all resources trying to get this working.
I'm running my Apache on Port:5000 and trying to direct to lsapp.dev instead of http://localhost:5000/lsapp/public/ with:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lsapp/public"
ServerName lsapp.dev
</VirtualHost>
I have tried VirtualHost *:5000 but still can't get it work?
you can use this on command line in your project root
php artisan serve --port=your_port_number
or do this:
edit httpd-vhosts.conf that is located in C:\xampp\apache\conf\extra\httpd-vhosts.conf and add following lines at the end of the file:
# VirtualHost for LSAPP.DEV
<VirtualHost lsapp.dev:80>
DocumentRoot "C:\xampp\htdocs\lsapp\public"
ServerAdmin lsapp.dev
<Directory "C:\xampp\htdocs\lsapp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
our apache is listening to lsapp.dev connections, but we have to configure our hosts file that allows to redirect lsapp.dev to the localhost that is located in C:\Windows\System32\drivers\etc
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 lsapp.dev
Set your Virtual host file like this.
<VirtualHost *:80>
DocumentRoot "D:\laravel Task\laravel\blog" //here set your project storage path
ServerName localhost.test.com // set your url for your project
<Directory "D:\laravel Task\laravel\blog"> // again set your project storage path
AllowOverride All
Order allow,deny
Allow from all
Require all granted
set your hosts file like this
127.0.0.1 localhost.test.com
Now you can Run your project
localhost.test.com
//OR//
If you dont want to use virtual host, then you can run your project like this
goto your project folder=>
command line in your project root=>php artisan serve
your project will run in
http://127.0.0.1:8000/
Currently, I have XAMPP setup to where typing 127.0.0.1 in the browser redirects me to the home page found within htdocs.
I would like to be able to type "devtest" and have that be an alias for 127.0.0.1.
What I have tried so far is modifying: C:\xampp\apache\conf\extra\httpd.vhosts.conf where I added an entry that looks like:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot C:\xampp\htdocs\Workspace\MyProject
ServerName devtest
ErrorLog C:\xampp\htdocs\Workspace\MyProject\MyProject-error_log
CustomLog C:\xampp\htdocs\Workspace\MyProject\MyProject-access_log common
</VirtualHost>
Is there another step I'm missing?
Open the hosts file in Notepad:
C:\Windows\System32\drivers\etc\hosts
Add the line:
127.0.0.1 devtest
Navigate to: http://devtest
Use this, and make sure you enable using vhosts config file in apache.
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\Workspace\MyProject"
ServerName devtest.local
<Directory "C:\xampp\htdocs\Workspace\MyProject">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I just started learning php and I am trying to host locally my own php website by using XAMPP.
I wanted to create virtual host with:
URL: myphpwebsite.local
Port: 8088
But when I attempted to access this website through the browser I got a:
Not Found
HTTP Error 404. The requested resource is not found.
Does anyone know what the problem is?
My httpd-vhosts.conf
NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost myphpwebsite.local>
DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
ServerName myphpwebsite.local
ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined
<Directory "C:/Microsoft/Workspace/myphpwebsite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And my C:\Windows\System32\drivers\etc\hosts file:
127.0.0.1 localhost
127.0.0.1 myphpwebsite.local
Any help would be appreciated!
make sure there's file/htaccess/index or whatever in directory you want to open, 404 may comes from that ;)
try using one below, eventually replace your port:
<VirtualHost *:80>
DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
ServerName myphpwebsite.local
</VirtualHost>
the question is your Apache running/serving on port 8088?
For example my xamp is running on 80 and 443...
xamp control panel is very handy, it has nice logs button that will open your log files to show you php and apache errors etc. check it out.
Try going with default port, if it works it means that you need to play with ports if you really want to.
just a quick tip, .com is shorter than .local and if you're using chrome and it works like mine then most of the time something.local will redirect you to google search (and I like my search there, you can switch it off ;))
I don't know if I am much help, but using WAMP, here are my settings. I am listening on port 80, I use 8080 for my tomcat server.
hosts file
127.0.0.1 local.mysite.com
httpd-vhosts.conf
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
....
<Directory "c:/wamp/www">
Options Indexes MultiViews FollowSymLinks
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/wamp/www"
</VirtualHost>
<Directory "c:/wamp/www/path/to/site/root">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName local.mysite.com
DocumentRoot "c:/wamp/www/path/to/site/root"
ServerAdmin me#email.com
ProxyPreserveHost Off
RewriteEngine On
AllowEncodedSlashes NoDecode
#AllowEncodedSlashes On
ErrorLog "c:/wamp/www/path/to/logs/error.log"
CustomLog "c:/wamp/www/path/to/logs/access.log" common
</VirtualHost>
....
Then I can access my local site like this: http://local.mysite.com
Hope this helps...
The NameVirtualHost directive needs to match the value of VirtualHost exactly, and you need to specify the port in each instance. If you want to use port 8088 for myphpwebsite.local, you'd need to do:
NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1:8088>
DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
ServerName myphpwebsite.local
ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined
<Directory "C:/Microsoft/Workspace/myphpwebsite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Notice the VirtualHost opening tags are identical; it's the ServerName value that actually tells Apache which domain this particular directive applies to. Restart your server after making the changes. Check out this page for more information: http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Hope this helps!
Make sure that the port you are using is not being used by another service.
I’m having a hard time getting multiple sites working with MAMP using Virtual hosts. Below is what I have set up on my MBA. If I open up my web browser and go to "http:local.login.dev" or "http://dev.login.localhost" (after reconfigure) I get the index page that’s saved in /Users/aaron/localhost. First item listed in my Virtual hosts section Not the index page saved in the Virtual Host I want to get to. Other sites I have setup give me the same result.. "http:next.site.localhost" = displays the index page in /Users/aaron/localhost.
Does anybody have any thoughts? My final goal is to configure MAMP Virtual hosts to work and test with SSL.
Bottom line is it seems like ONLY the first Virtual host entry is read and that's whats used for every host listed. Am I missing some setting somewhere??
Environment:
- MBA with OS X, Yosemite
MAMP 3.0.7.3 using ports 80, and 3306 for http and mysql respectively
httpd.conf File:
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
127.0.0.1 localhost
127.0.0.1 local.login.dev
<VirtualHost *>
DocumentRoot "/Users/aaron/localhost"
ServerName localhost
</VirtualHost>
<VirtualHost *:80> — I tried both with and without :80
DocumentRoot "/Users/aaron/localhost/training/login/public"
ServerName local.login.dev
</VirtualHost>
Also tried configuring my hosts and httpd-vhosts.conf this way - From another post:
127.0.0.1 localhost
127.0.0.1 dev.login.localhost
<VirtualHost *>
DocumentRoot "/Users/aaron/localhost"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/training/login/public"
ServerName dev.login.localhost
ServerAlias dev.login.localhost
<Directory "/Users/aaron/localhost/training/login/public">
Allow from All
AllowOverride all
Options -Indexes +FollowSymlinks
</Directory>
</VirtualHost>
Just playing around more I commented out the first "Localhost" in my httpd-vhosts.conf file and looks like I can now navigate to my local sites correctly. Below is what I currently have configed..
httpd-vhosts.conf:
# <VirtualHost *>
# DocumentRoot "/Users/aaron/localhost/"
# ServerName localhost
# </VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/training/login/public"
ServerName dev.login.localhost
ServerAlias dev.login.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/site1"
ServerName dev.site1.localhost
ServerAlias dev.site1.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/aaron/localhost/site2"
ServerName dev.site2.localhost
ServerAlias dev.site2.localhost
</VirtualHost>
Hosts File:
127.0.0.1 localhost
######Locahost Dev Sites
127.0.0.1 dev.login.localhost dev.site1.localhost dev.site2.localhost
Now to see if I can get SSL working.
If any of this is incorrect, please let me know... but this config is the only way I can get the Virtual hosts working, as of now, using port 80... If I have issues mixing with 443 I'll update