I have multiple websites in folders that I need to switch back and forth too constantly. Each time I have to go to the httpd.conf file to find them and change DocumentRoot and Directory lines. I was wondering if there is a faster way to do this, maybe with a cmd prompt? Or maybe a php inc file I can create.
Thanks.
You would be much better off setting all your sites up as Virtual Hosts. They are always available and you dont have to change anything other than the url to access each individually.
HowTo: Create Virtual Hosts in WAMP
BEFORE DOING ANY OF THIS PLEASE ENSURE APACHE AND MYSQL ARE WORKING PROPERLY FIRST!!!
Create a new folder outside the wamp directory structure. For example
C:\websites\www
but this can be on any disk drive visible to the PC running wamp
Create a subfolder in c:\websites for each site you want to create. for example:
C:\websites\www\site1
C:\websites\www\site2
Edit the file C:\wamp\bin\apache\apachex.y.z\conf\extra\httpd-vhosts.conf where x,y and z are the version numbers of apache that you actually have installed.
NOTE: If you are switching between 2 or more versions of apache this will have to be done to all your versions of apache in turn.
SUGGESTION: I like to use the format sitename.dev to make it obvious to me that I am dealing with my localhost development copy of a site, you may prefer another notation, thats ok, the word dev has no actual defined meaning in this case, its just my way of naming my development versions of a live site.
NOTE: Remove or better still comment out ( using the # in column 1 ) the lines that already exists in this file. They are just examples.
example contents:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
## must be first so the the wamp menu page loads when you use just localhost as the domain name
## Also NEVER change the security to anything other than Allow from 127.0.0.1 localhost ::1
## Then a drive by Ip address hack should return a 403 denied access
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
**Using Apache 2.2 syntax**
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
## For every ip in the subnet, just use the first 3 numbers of the subnet
## Check you actual subnet for the actual values to use here
Allow from 192.168.0
</Directory>
**Using Apache 2.4 syntax**
<Directory "C:/wamp/www">
Require local
## And possibly allow access from you local network
## Check you subnet for the actual values to use here
Require ip 192.168.0
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/websites/www/site1"
ServerName site1.dev
ServerAlias www.site1.dev
Options Indexes FollowSymLinks
**Using Apache 2.2 syntax**
<Directory "C:/websites/www/site1">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.nnn
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
# If you want to allow access to everyone
#Allow from all
</Directory>
**Using Apache 2.4 syntax**
<Directory "C:/websites/www/site1">
AllowOverride All
Require local
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Require ip 192.168.0.nnn
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Require ip 192.168.0
# If you want to allow access to everyone
#Require all granted
</Directory>
</VirtualHost>
Add as many as you require so each of your sites have one, changing the DocumentRoot, ServerName and any other of the parameters as appropriate.
This also allows you to make SITE SPECIFIC changes to the configuration.
NOTE: This will make the wamp manager "Put Online" function no longer have any effect on these new vhost'ed sites as the security for each one is now part of the vhost definition, so leave WAMP, OFFLINE.
If you want to put one or more sites online you will have to change the Allow commands MANUALLY in the httpd-vhosts.conf file.
To check your subnet do the following:
Launch a command window, and run
>ipconfig
Look for the line "Default Gateway" in the output and use the third number in your Allow commands.
Edit your httpd.conf file and search for these lines, they are near the bottom of the file.
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Remove the '#' comment character on this line to Include your newly changed vhosts, this will cause apache to register their existance. eg
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
While still editing your httpd.conf file search for
# onlineoffline tag - don't remove
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
DO NOT CHANGE THESE LINES!
Add the following after the <\Directory> tag to secure your new C:\websites folder.
<Directory "C:/websites/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
This is to set security on your new directory structure so that access to these new sites is only allowed from 127.0.0.1 (localhost) unless amended from within a specific VHOST.
P.S. Your internal network will probably be something like 192.168.x.y, check your system first!
Now in order for your browser to know how to get to these new domain names i.e. site1.dev and site2.dev, we need to tell windows what IP address they are located on. There is a file called HOSTS that is a hangover from the days before Domain Name Servers (DNS) were invented. It is a way of giving nice easy rememberable names to IP address's, which of course is what DNS Servers do for us all now.
Edit your HOSTS file, this can be found in C:\windows\system32\drivers\etc , the file does not have an extension.
Windows protects this file so you must be an Administrator to be allowed to save changes to this file.
If you are using VISTA or Windows7/8 you may think you are an Administrator BUT YOU ARE NOT!!!!
So to edit this file you must launch your editor, or Notepad in a specific way to gain Administrator rights. To do this find your editors icon and launch it using the following key strokes:
Shift + Right Click over its icon, this will display a menu, click the item "Run as Administrator", and click "Allow" on the challenge dialog that will appear.
Now you are ready to edit the hosts file so navigate your editor to c:\windows\system32\drivers\etc\hosts
Add the following lines to this file
127.0.0.1 site1.dev
127.0.0.1 site2.dev
NOTE: You will need to add one line in this file for each of your new virtual hosts.
Once you have saved these changes you need to make windows refresh its 'domain name - ipaddress cross reference' cache.
To do this launch a command window as an Administrator ( Shift + Left Click over the command window icon ) and run these 2 commands.
>net stop "DNS Client"
>net start "DNS Client"
Note: The quotes are required as there is a space in the services name.
In order for Apache to pick up these changes you must bounce ( restart ) apache.
DO this by: Wamp manager -> Apache -> Service -> Restart Service
You should now be able to use the address site1.dev in your browser to get to your new sites.
Copy your sites code into the "C:/websites/xxxx" folder if you already have a site coded or,
place a quick and simple index.php file into the "c:\websites\xxxx" folder to proove it all works.
example:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>SITE1</title>
</head>
<body>
<?php
echo '<div style="background-color:red;color;white;text-align:center;font-size:18px">HELLO FROM Site1</div>';
?>
</body>
</html>
TROUBLE SHOOTING:
If you have used the new domain name ( site1.dev ) and it has not found the site.
a. Check the changes to the hosts file.
b. Restart the "DNS Service" that runs in windows. This caches all doman names that you use in a browser so that the browser does not have to query a DNS Server each time you re-use a domain name. This may have cached your failed attempt but a restart is easy and should solve the problem and is quicker that re-booting windows, which should also work.
Related
I use wamp. My PC is in a Lan. everybody in the Lan can see my localhost and I don't want that.
I want to limit people on Lan to just be able to see localhost/site/ but now everybody can see localhost and every files and folder that are in localhost.
How can I solve this?
I edit httpd.conf and change "deny from all" to "deny from none"
Knowing the IP address is the main goal here, of course you can deny from specific folder by opening .htaccess file:
<Directory specific_folder/>
Options FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.0(Replace this IP to allow access)
</Directory>
Let me know if this works for you
Localhost is actually your loopback address which resolves to 127.0.0.1 and this is only accessible from your PC. I think what your trying to ask is to allow IP's from your subnet to access certain directories but not others. If thats the case then to do this you will need to edit your httpd.conf and find the <Directory> section. The below example shows you how to enabled access from any PC with an IP from 192.168.1.0/24 (1-254) and localhost (127.0.0.1) to the following path /var/www/sub/folder/ then deny all.
<Directory /var/www/sub/folder/>
Order allow,deny
Allow from 192.168.1.0/24
Allow from 127
</Directory>
As you can see it firstly allows all from the the config and then deny's everything else. If you wanted access for just your local PC then you would do something like this:
<Directory /var/www/sub/folder/>
Order allow,deny
Allow from 127
</Directory>
This will only allow 127.0.0.1 (Localhost) to access the folder.
You can add multiple Directory settings within the httpd.conf for specific folders, just make sure you restart Apache for the changes to apply.
I'm not sure what your problem is, but localhost is only available from your own computer. (localhost resolves 127.0.0.1)
In order to display the webpages to other users on your LAN network you can use your LAN IP or a service like xip.io
I am trying to setup virtual host for Magento, but its not working, I created magento.localhost.com.conf in the Apache2/sites-avaliable directory, this is my file :
<VirtualHost *:80>
ServerAdmin magento#localhost.com
ServerName magento.localhost.com
DocumentRoot /srv/www/magento_dev/public_html
<Directory /srv/www/magento_dev/public_html/>
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /srv/www/magento_dev/logs/error.log
LogLevel warn
</VirtualHost>
I am following instructions from book actually ,also changed /etc/hosts file , I added 192.168.36.1 magento.localhost.com. at the end , but when I try to open the site, it says :
This webpage is not available
I enabled apache rewrite, give permission to all this folders ,basically did everything as instructions, but still not working. My os is Ubuntu 14.04, any tips ?
Follow recommendations in comments for a2ensite and for testing with a simple index.php file.
Also make sure to restart Apache.
When that works, then try with the Magento index.php file.
What you do next depends on if this is a brand new copy of Magento or a copy of a previously installed one. If it's new, you should see the setup page. Follow the instructions. If it's a copy, you will need to change the database core_config_data values relating to your website urls.
Edit:
You say
changed /etc/hosts file ,I added 192.168.36.1
On what machine did you change this? Also is your Magento running in a virtual machine on your Windows machine? And the VM machine has that IP?
Edit 2:
Also change your web server name to "Magento.mysite.com" or something like that. localhost has a special meaning! And it doesn't make sense if you are accessing a remote we server!
Check web server ip with ipconfig or ifconfig on the command prompt. Put that ip in the hosts file of the web browser machine.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 months ago.
Improve this question
I need your help here in creating a virtual host in wampserver. In office I can create a virtual hosts but when I try to create in my laptop it doesn't work. I still can't figure out what's wrong. Here's what I did.
I copy the wordpress file in this folder. This will be the path of my project
E:\Subversion\chelle.wpblog.local
I edit the host file
C:\Windows\System32\drivers\etc\hosts
I added it to the end of file
127.0.0.1 chelle.wpblog.local
Next is I enable the virtual host in Apache
C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf
I uncomment this
Include conf/extra/httpd-vhosts.conf
Next is I setup the virtual host in WAMP
C:\wamp\bin\apache\Apache2.4.4\conf\extra\httpd-vhosts.conf
I add this at the bottom
<VirtualHost *:80>
ServerName chelle.wpblog.local
ServerAlias chelle.wpblog.local
DocumentRoot "E:/Subversion/chelle.wpblog.local/"
<Directory "E:/Subversion/chelle.wpblog.local/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Last is restart wampserver and open the chelle.wpblog.local in the browser. And it doesn't display. It display only google search results.
I was installing the zend framework on my local wamp using apache server.
First go and decide what will be your domain name for the local url.
Ex->www.test_zend_tutorial.com
then go and open the file located at "C:\WINDOWS\system32\drivers\etc"
hosts
write
127.0.0.1 (use one tab space) www.test_zend_tutorial.com
then go to the folder located at
D:\wamp\bin\apache\Apache2.2.17 (whatever is your version) \conf\
and open the file
httpd.conf
and search for text
Include conf/extra/httpd-vhosts.conf
and uncomment it by removing the # tag from the start of the line.Save the file and close it.
Now go to another folder located at
D:\wamp\bin\apache\Apache2.2.17\conf\extra
and open the file
httpd-vhosts.conf
and paste the code below at the last in this file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "D:\wamp\www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName www.test_zend_tutorial.com
DocumentRoot "D:\wamp\www\(your project folder name)\public"
SetEnv APPLICATION_ENV "development"
<directory "D:\wamp\www\(your project folder name)\public">
DirectoryIndex index.php
AllowOverride all
Order Allow,Deny
Allow from all
</directory>
</VirtualHost>
and restart the wamp, now write the www.test_zend_tutorial.com in the browser and you will see the things working.
If when you use the new domain in the browser it goes to a google search or something like that then the change to your hosts file has not been recognised.
You have to either reboot after changing the hosts file or more simply run these 2 commands from a command windows ( as administrator )
net stop dnscache
net start dnscache
This will refresh windows DNS cache and pick up your hosts file changes.
It is also a good idea to ping your new domain to check it is being seen, use
ping chelle.wpblog.local
If it reports 127.0.0.1 as the ip address and 4 send and 4 receieved packet then the domain is now known to Windows, if it reports some other ip address the hosts file change has not succeeded.
Also it is a good idea when creating VHOSTS to also create one for localhost or the wamp home page will not work.
You also have old Apache 2.2 syntax (Order allow,deny allow from all) you could try using the Apache 2.4 syntax, see below
So try this
## must be first so the the wamp menu page loads
<VirtualHost *:80>
ServerAdmin webmaster#mail.net
DocumentRoot "D:/wamp/www"
ServerName localhost
<Directory "D:/wamp/www">
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#mail.net
ServerName chelle.wpblog.local
ServerAlias www.chelle.wpblog.local
DocumentRoot "E:/Subversion/chelle.wpblog.local"
<Directory "E:/Subversion/chelle.wpblog.local">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
In WampServer 3.0.4 you do not need to run through all those setting up.
Go to local host and under Tools area for "Add a Vertual Host" in the first time it will say turn on "Vertual Host sub menu" in wamp server settings.
To get there right click on wamp icon > go to wamp server settings > and click on Vertual Host sub menu. Then re-fresh the page and follow the setup process, you just need to provide the server name and path. It will do all the works for you.
Simple as that
Method 1:
in hosts file
127.0.0.1 mysite
::1 mysite
in C:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vosts.conf file add your virtual host as follows
<VirtualHost *:80>
ServerName mysite
DocumentRoot "<path_to_your_local_site>"
<Directory "<path_to_your_local_site>">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Make sure vhost configuration is enable in httpd.conf file is enabled as follows
C:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
After you have changed configuration as above, restart all service in wamp and load website as follows
http://mysite
your local site should open.
Method 2:
In latest versions of wamp, you can do this configuration via webpage.
Open localhost in your browser. You would see wamp welcome page.
Down below under Tools, there is option to add virtual host. click on the link which would take you to add virtual host page.
In Name of the host, enter your site name eg: mysite
Under Complete absolute path of the VirtualHost folder, enter the path of your site.
Save the config and restart all services. you should be able to open mysite with the link http://mysite
As pointed in another answer, in newer versions of wam
The answers above are overcomplicating the problem somewhat, and in fact the question is including extra information that's misleading the responders.
The clues lie in step 2 and the symptoms described in 5. The hosts file is set up but when the request is made to "blah.local", google responds. Apache is not involved.
The first step to diagnosis would be pinging blah.local and seeing that it maps correctly to 127.0.0.1. I have never (in many years as a developer) found it necessary to restart local DNS on either Windows or Linux/Mac so I would expect this to work out of the box. But if it doesn't, of course restart DNS and see that it does.
However, late versions of Chrome at least do not recognize the TLD '.local' and so when you put the URL back in the browser, it's passed on to Google as a search term. There may be a setting in your browser to tell it to handle the unsanctioned TLD, but your simplest solution would be to use a TLD that's sanctioned by W3C like '.com'.
In short, if your hosts file reads something like
127.0.0.1 local.chelle.wpblog.com
rather than
127.0.0.1 chelle.wpblog.local
everything should work.
Create the folder for your local website
Go to localhost (browser)
Click Add a Virtual Host button
Add the name of the virtual host
Add the complete absolute path
Restart DNS
I have a PHP system inside a server which is not yet uploaded in the internet and can only be accessed using networking. (E.g. 192.168.1.190/php_system/index.php) How can I fix the URL of this to avoid other computers to accessing files inside the php_system folder? And how can avoid them to accessing file using CTRL + Left Click or opening files inside iframe using another window?
Edit your Apache Virtual host to allow access only from certain IPs. Something like this:
<VirtualHost *:80>
ServerName EDIT.THIS.com
ServerAlias EDIT.THIS.IF.YOU.HAVE.ONE.com
DocumentRoot "/full/path/to/root"
<Directory /full/path/to/root>
Options FollowSymLinks
Order Allow,Deny
Allow from 192.168.0.1 EDIT.TO.ANOTHER.IP AND.ANOTHER
</Directory>
</VirtualHost>
Alternatively, add a "auth" value (that will require a login and password) like this:
<Directory /full/path/to/root>
AuthType Basic
AuthName "Admin"
// NOTE: do not include this in your website folder
AuthUserFile /path/to/.passwd_file
Require user user1 user2
</Directory>
Edit: Corrected the Order values.
Try http://httpd.apache.org/docs/trunk/platform/windows.html. this will show you directives on how to configure your Apache server on windows.
In the directory you want to protect, add a file called .htaccess (the period matters)
In this file, put the following three lines (EDITED based on Sven's inputs)
order deny,allow
allow from 127.0.0.1
deny from all
Now it should be impossible for anyone but you (logged in on the machine where Apache is running) from seeing the contents. Any file sharing that is active has to be turned off separately. Alternatively, you add a line that includes the IP address of the machine from which you want to access the server instead of 127.0.0.1 - you can even have multiple lines of allowed addresses, include ranges, ...
You will find a ton more information at http://httpd.apache.org/docs/2.4/mod/mod_access_compat.html#order
Virtual host not working in the NETWORK
I just followed this site tutorial,
Virtual host steps
The tutorial was excellent but when I try this alias URL in another system, its not working. I have checked in my other system, I am able to see my application, after I did these changes I am not able to see my application on the other system.
I have even changed Allow from 127.0.0 to all but that is not working.
My C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
This what I added
<VirtualHost *:80>
ServerAdmin webmaster#developertalk
DocumentRoot "C:/wamp/www/developertalk"
ServerName developertalk
ServerAlias www.developertalk
ErrorLog "logs/developertalk-error.log"
CustomLog "logs/developertalk-access.log" common
<directory "C:/wamp/www/developertalk">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
When hitting URL in another system, getting following error:
Server not found
In my local host i am having 3 web application.
Due to above changes my local host other sites not working.
How to make it work other sites.
You need to use local DNS to say every PC in Your network, that You have on Your PC host 'myApp', also You can add to every client's hosts file something like myapp 192.168.1.2 where 192.168.1.2 Your static IP in network
For every computer you want to have access to http://developertalk, you need to edit the Hosts file in each one.
Located at (xp/win7): C:\Windows\System32\drivers\etc\
You need to add only 1 line on every computer.
(your static internal ip) www.developertalk
example:
192.168.1.71 www.developertalk
you can check your internal ip address on your windows by opening cmd and typing ipconfig.
Look for the IPv4 address under the Ethernet adapter Local Area Connection column.
If you don't request or assign a static internal IP to your computer, others will not be able to connect to http://developertalk which was forwarded to your old internal IP.
Egor Sazanovich has actually answered your question and provided you with extra information, so accept his instead of this one, if this helped at all.