virtualhost on xampp and accessible from external device - xampp

I'm running XAMPP on my WIN7 laptop for developing websites. Now I use virtualhost and a modified hosts file, so I can access my website "www.thisshouldbemysite.nl" through this URL. But it will be loaded from my XAMPP server.
For me locally, this is working fine. I can do what I want. But I also want to access this server from an external device, e.g. a smartphone or tablet so that I can see how the site is rendered on other devices. But entering the IP address of my XAMPP PC in a tablet browser will bring me to the C:\xampp\htdocs directory and I'm unable to access the C:\xampp\htdocs\thisshouldbemysite.nl directory.
Does anyone has an idea of how I can configure my server to get both working (local and remote). Remote should be in the same local network!
Here you can find my current settings.
hosts:
127.0.0.1 www.thisshouldbemysite.nl
httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot C:\xampp\htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:\xampp\htdocs\thisshouldbemysite.nl
ServerName www.thisshouldbemysite.nl
</VirtualHost>

I want to cover a few things to give you the full picture, maybe if you better understand each part of the process then you can identify where your problem is and therefore find an answer.
The first thing we need to understand is how your browser knows where to go when you type in a domain name. Your browser will check your local hosts file, then your local DNS cache, then make a request to a DNS server. The DNS server is either set automatically by your ISP / DHCP, or set manually in your internet connection settings. So, making a request to a domain name, your browser/OS will check those places in that order for matching entries. If no entry is found, then the domain name will not resolve.
A DNS server can have different kinds of entries. It can tell you where a domain name is hosted, it can tell you where a subdomain is, it can point a domain name to another DNS server...its a flexible multi-use spot where a domain name can point to anywhere. Also depending on the kind of DNS entries are set for a domain name, your browser will automatically know if it needs to ask another DNS server for where a domain name points, or if that it the final result it is looking for. Improperly setup DNS servers can cause a user to get stuck in a DNS loop - where one DNS points to another DNS, and the 2nd DNS points back to the first DNS. These kinds of things are very easy to figure out.
The Hosts file is basically like a local, manually set DNS-like system. It allows you to say that "any.domain" is at "any-ip-address". In this manner you can locally over write or disregard other DNS resources. It's good for local stuff, but if you are going to want to access things from over the internet or by many devices, I highly recommend using a DDNS service, which I will go over below.
---Apache VHost File---
In the vhosts file I set a default vhost. This way, if I type in my IP or a domain name that doesn't have a vhost explicitly defined, I still get some kind of response from my web server. This is just my preference, but totally unnecessary. After I set a default, I explicitly define what domains/subdomains I want to serve.
NameVirtualHost *:80
##############localhost
ServerAdmin webmaster#localhost
DocumentRoot "D:/xampp/htdocs"
ServerName localhost
<Directory "D:/xampp/htdocs">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
########othersite.local.whatever
ServerAdmin webmaster#localhost
DocumentRoot "D:/xampp/othersite.local.whatever"
ServerName othersite.local.whatever
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
After your VHost file is saved, restart apache. If apache starts then stops running automatically, then you probably have an error in your apache config / Vhosts file double check your work, try to start apache after saving each change you make until it works.
---Windows Hosts File---
Unless you have a DNS server setup, you will want to modify your Windows Hosts file in order to tell your machine that othersite.local.whatever points to your apache server. What this file does is locally point a domain name to an ip address. It does not effect other computers, it is only for this one machine that is also running your server.
The hosts file is located C:/windows/system32/drivers/etc/hosts
Depending on your windows permission, you may need to copy the hosts file to the desktop first, open it up with notepad or your fav text editor, make your modifications, save it and copy it back to its original location. On a new line, add a new entry:
127.0.0.1 othersite.local.whatever
After you save your hosts file back to C:/windows/system32/drivers/etc/ you should now be able to access othersite.local.whatever on the server machine without issues. If you have other local windows computers, you can modify their hosts files to point to the server's ip address (usually something like 192.168.1.xx) so that those computers can also access the vhost at othersite.local.whatever.
192.168.1.?? othersite.local.whatever
---Addressing your problem through alternate means---
Depending on what your needs are, you can do a couple things.
1) Modify the vhost file on all windows computers, do some research on how to do it on other devices. If all the devices think that othersite.local.whatever points to your server, your server should respond with the proper vhost page. That is how it works weather on a local network or WAN / internet.
2) Setup a local DNS server, point all your devices to your DNS, and add an entry in your DNS to point to the domain to your server. This is a complicated task if you have never done it before, but you might find it useful.
3) Set up a Dynamic DNS (DDNS). This one is a little complicated, but it is actually pretty easy to do. It can really help you open up your options.
Here is how it works - your home internet connection's WAN IP probably changes from time to time - A Dynamic IP assigned from your ISP by their DHCP service. If you turn your internet modem off and on again, your IP probably changes. This is no good because if you have an external DNS or link that points to your IP in some way, and your IP changes because either your power turned off and on or DHCP renewed your IP lease with a new IP, then you are cut off from your server. So to get around this we have something called a Dynamic DNS. You sign up with a DDNS service (many of them are completely free), you run a little DDNS program on your PC. The DDNS program simply checks your IP address every few minutes and updates the DDNS servers with your IP. If your IP changes, then within minutes the DNS servers are notified of the change and you are back to accessing your server.
To get this all setup you need to setup your local internet connection to forward incoming connections on port 80 (your website probably runs on 80 unless you changed it) to your web server. Set your server's local IP address to a static one (so it doesn't change on your local network, you know something like 192.168.1.100 or whatever suits your needs) and modify your internet gateway/modem/router to forward everything on port 80 to your server PC.
I like to use a free DDNS service called No-IP (http://no-ip.com/). It's free, simple and reliable. Create an account with them, pick a single subdomain - you could go with something.bounceme.net or other predetermined free DDNS names. After you pick a name, install the DDNS / No-IP program on your server PC. Now something.bounceme.net will always go to your home IP. If you setup port forwarding properly, anything on port 80 will automatically go to your webserver.
Now the last step is to get a normal domain name to point to your home IP instead of something.bounceme.net. You could either pay No-IP to do some fancy stuff, or you can do it the free way which is what I will explain here.
I used Godaddy as a domain registrar the last time I did this, and everything has changed so much, you may need to call Godaddy or your domain registrar and ask where/how you can do this with their service.
First is, you need a domain name. Let's say you own homesite.com and let's also say you want laptop.homesite.com to point to your home web server.
For the domain homesite.com, add a DNS record of the type CNAME with a key of "laptop" and a value of your DDNS name "something.bounceme.net". This will make it so that laptop.homesite.com will resolve to your home IP address. Make sense? Now when you type laptop.homesite.com the DNS will tell it to check something.bounceme.net and that will resolve to your home IP.
There are some limitations to the CNAME entry. You can't forward just "homesite.com" to your DDNS IP. You basically have to use a subdomain entry, like laptop or home or something like that. One thing you can do, though, is use the 'subdomain' entry WWW, so that www.homesite.com will point to your home IP. If you use Godaddy, you get a free limited hosting account with your domain name that shows Godaddy ads on it. You can set this account up for "homesite.com" and place some redirect code in it to send users to "www.homesite.com". This way, people type homesite.com and automatically get sent to www.homesite.com.
I hope this is all making sense.
So let's review - Set your servers Static IP, setup port forwarding so the port 80 points to your server's local IP, setup a DDNS (like http://www.no-ip.com) and install their DDNS program, set a CNAME with your domain registrar so that www.yoursite.com points to your home server (CNAME www -> your-ddns-url.bounceme.net). Now you should be able to access your server from anywhere in the world at www.yoursite.com, from inside your local internet connection or from a starbucks.
You can also setup port forwarding for an FTP server (usually 21) to remotely edit your website or access your home files. You can do all kinds of things when you can remotely access your home PC.
I hope this short walk-thru will help you understand each part that is necessary to access an apache VHost across all devices. I like using the DDNS setup/option because you don't need to setup hosts file for each device or anything like that. It's just like accessing a regular website!
Questions or comments welcome. I literally just wrote this all out off the top of my head, I hope it helps.

Have you tried this configuration for your virtual host?
<VirtualHost *:80>
DocumentRoot C:\xampp\htdocs\thisshouldbemysite.nl
ServerName localhost
</VirtualHost>

in this file there is virtual hosts definitions:
C:\server\apache\conf\extra\httpd-vhosts.conf
one virtual host already exist and you are using as default "localhost".
create another one for new project with different port number (81 is here)
<VirtualHost *:81>
DocumentRoot "C:\server\htdocs\YOUR_PROJECT_FOLDER"
ServerName YOUR_SERVER_NAME
<Directory "C:\server\htdocs\YOUR_PROJECT_FOLDER">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
than in this file contains default ports which apache will listen
C:\server\apache\conf\httpd.conf
#Listen 12.34.56.78:80
Listen 80
Listen 81
add your new ports here
Now you can open http://YOUR_SERVER_NAME from local machine
and open http://local_ip_adress_of_your_machine:81 from other local network connected pc.
Windows users need to add new server name to the C:\Windows\System32\drivers\etc\hosts file
127.0.0.1 YOUR_SERVER_NAME
i hope it helps someone who need

Related

Chrome is not loading my localhost with a subdommian [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
When i hit my local host to open my local site it dont perform any action it is working fine for firefox.dont know the reason.It has app before address.
http://app.127.0.0.1:8000/login
You can try to create a domain by editing your host file. Let's say your domain name is myapp.local.
Edit your host file and add the line
127.0.0.1:8000 myapp.local
Then in your browser, you just have to open HTTP://myapp.local
So with this configuration, you can use Laravel you can use the subdomain routine like so
Route::domain('{app.myapp.local')->group(function () {
// put your routes here
});
Please keep in mind that this is for your development environment. You'll need to have another configuration with the real domain name when you go live.
I assume you're either usng xampp or wamp to create your virtual hosts ( subdomain for localhost). I'm writing method for xampp as you've mentioned the hosts file and configuring virtual hosts.
For xampp:
Follow the steps below to create a virtual host:
1- Change to your XAMPP installation directory (typically, C:\xampp) and open the httpd-vhosts.conf file in the apache\conf\extra\ subdirectory using your favourite text editor.
2- Replace the contents of this file with the following directives:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "<path to your website folder>"
ServerName apps.localhost
</VirtualHost>
This contains two virtual host configuration blocks:
The first block is the default or fallback virtual host, which is used for all requests that are not matched by subsequent blocks.
The second block sets up a virtual host named apps.localhost. The DocumentRoot directive specifies the directory to be used when serving requests for this virtual host (in this case, the WordPress installation directory), while the ServerName directive specifies the custom domain name for the virtual host.
To add more virtual hosts, simply duplicate the second virtual host block and modify the port number, DocumentRoot and ServerName directives as per your requirements. For example, if you want to use SSL with your custom domain name, you can add a new virtual host block for port 443.
3- Restart Apache using the XAMPP control panel for your changes to take effect.
4- At this point, your virtual host is configured. However, if you try browsing to the apps.localhost domain, your browser will show a failure notice, since this domain does not exist in reality. To resolve this, it is necessary to map the custom domain to the local IP address. To do this, open the file C:\windows\system32\drivers\etc\hosts and add the following line to it:
127.0.0.1 apps.localhost
This takes care of mapping the apps.localhost domain name to the local machine, which always has the IP address 127.0.0.1.
On some versions of Windows, you will not be able to edit the C:\windows\system32\drivers\etc\hosts file without administrator privileges. You can edit the file by right-clicking the Notepad icon and selected the "Run as administrator" menu option, then entering administrator credentials (if required) and clicking "OK" or "Yes" to proceed.
At this point, you should be able to enter the URL http://apps.localhost in your browser’s address bar and see your WordPress installation.
You should try using chrome Developer Tools. You can access them from the menu or pressing f12 in default configuration. Try checking the console tab to see if you receive an error not present in Firefox (Same as chrome). This can help you troubleshoot if your site is having trouble on the client side or server side.
You can also check this answer and try to set your address in your host file or web server config to ensure your web server is actually responding through the address you need.
https://softwareengineering.stackexchange.com/questions/178734/add-a-prefix-to-localhost
#Hassaan is right and in addition to that if you want to add virtual hosts in wamp you can just click on Add virtual hosts in wamp options and fill out the form to add a new subdomain in your localhost.

Pointing multiple IP address from different hosts to a same domain name with different port

I tried creating an Amazon EC2 instance with an elastic IP address. In there I deployed a MEAN app by Bitnami.
On the other hand we have a CPanel (not deployed in amazon, I think it's Apache, not sure, I'm not the one who deployed it)
Cpanel is already pointing to www.example.com so we can access cpanel via www.example.com:2082 but the default www.example.com:80 is blank/empty. We are using Cpanel for our mailing server.
What I need to do is to point Amazon EC2 public IP and DNS to www.example.com:80. Can I set it up in Cpanel DNS Zone Editor? or do I need to set up Amazon Route 53? what do I need?
If I create a new A record in Cpanel DNS Zone editor for Amazon I lose access to Cpanel www.example.com:2082. I'm really confuse right now. Please Help.
You need to introduce a Proxy server in between to do this, As in DNS you can't set the ports, for each type of requests ports are already defined.
You can add nginx or haproxy or any other reverse proxy server, which will accept all the requests and passes on the request to appropriate hosts on appropriate ports.
I know it's a bit late but just in case you still need it or someone comes across this:
No need for a proxy.
You point the A record for example.com to EC2 IP.
CNAME for WWW to example.com
Then you should have an A record for mail.example.com for your cPanel IP
Your MX records should point to mail.example.com and not to example.com.
And you can access cPanel at mail.example.com:2082 or whatever the server's IP or main hostname is. The main hostname has the advantage that you can use port 2083 for SSL cPanel connections
Just make sure the e-mail clients use mail.example.com and not example.com as the connecting mail server.

Why is wamp Apache not allowing APIs to access my www folder?

I have a piece of code where an external API needs to access my "www" folder for images. When I load the url, "http://localhost:8001/images/1.jpg" from the browser, it does show the image. But when I access it through the code it says, "connection refused". I have turned off the firewall as well. I also tried using the IP address instead of the "localhost".That doesn't work either. Please help.
Remember the domain name localhost has a special meaning. It always means this PC, or more accurately this network cards loopback address.
I cannot access your PC from here using the domain name localhost, as it will always be looped back to my PC.
If you want an external site to make a call to your PC then there are a number of things you will have to do.
Buy yourself an domain name, you either buy a real one or use a Dynamic DNS service like dyndns.com or or noip.com
Or you use your routers WAN ip address.
Then you must amend the httpd.conf file so that Apache allows access
from all ipaddress's
Then you must Port Forward your Router so the the NAT firewall allows
external accesses on port 80 to be forwarded to the internal PC
running Apache, and only that PC.
And possibly amend your software firewall on the Apache PC to allow access from external sources on port 80

wamp server only running local

Ive been searching around the internet and I cannot not find the answer to why wampserver is only running on localhost. I have pressed Put Online and I still do not know why it is only running offline. Not sure if it is my wampserver setup or my router blocking me, so any help would be great.
To access your server from the internet you need to do a number of things not specifically related to WAMPServer.
First you need to port forward your router, this allows un-solicited traffic on port 80 throught the NAT router firewall protection, into your network where normally for security reasons it is not allowed in. This opens the port and makes sure that all traffic on port 80 of yor router is directed to the PC running WAMPServer i.e. Apache. So you will need to make sure that the PC running Apache has a STATIC ip address and is not being allowctae an IP by the routers DHCP server.
This site can be very helpful with learning how to do that
Once that is done you may also need to configure your software firewall running on the PC that has Apache on it to allow traffic on port 80 into the PC. Although you may have allowed this already when you first ran Wampserver after it was installed.
When you use the WAMPManagers Put Online and Put Offline that changes the Apache config (httpd.conf) and should change
# onlineoffline tag - don't remove
Require local
which tells apache to only allow connections from the PC running Apache
To
# onlineoffline tag - don't remove
Require all granted
which tells Apache that it is allowed to action connections from any ip address in the world
1) Check you firewall setting 80 port enable
2) Check anti virus Blocking
3) c:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
Order Deny,Allow
Deny from none
Allow from all

mac osx - apache - one website, multiple ports?

I'm building a website on my laptop that needs to be referenced via a custom hostname, instead of deep off of the localhost directory.
I need this site to be referenced locally via http://project.name/
I have this working by having created a new entry in my hosts file as well as a virtual host entry in my apache vhosts conf.
I also want to allow external users to view my site. They would need to access it by my ip address plus a port number, I imagine.
How do I do this?
I assume 'Listen 8080' needs to be added to apache.conf.
Do I create a new vhosts entry that duplicates the one I created before for the local host name, but with a "localhost:8080" name? (this smells bad).
Or can the existing vhosts entry be amended to also listen on localhost:8080?
To further clarify, I need:
http://project.name and
http://localhost:8080
to reference the same, exact site. This is because I need to create the site with a custom host name. My image references, for example need to start with "/images/example.jpg" instead of relative references. This is because the tech dept would have to do 10 mins of extra work. :^)
Thanks,
Scott
Rather than specifying a host (such as localhost) in your vhost directives, use * instead. This will allow you to reach that virtual host via different host names. If you omit ServerName from the block completely, that will allow you to hit the same site via http://localhost:8080, or from outside the machine via http://<ip address>:8080.
NameVirtualHost *:8080
<VirtualHost *:8080>
# your stuff
</VirtualHost>
You can then tune what interface these vhosts use with the Listen directive itself:
Listen 8080 # you can hit the sites from outside your machine, OR
Listen 127.0.0.1:8080 # no access outside your machine
Use apachectl -S to double check your vhost settings.

Resources