I would like my two sites: flowers.loc (Drupal 8) and honey.loc (Drupal 7) sites to work locally on Apache (v: 2.234).
First directory for flowers.loc:
Sites/drupal8/docroot
Second directory for honey.loc:
Sites/drupal7/docroot
I have this setting in httpd, apache configuration file:
<VirtualHost *:80>
DirectoryIndex index.html index.php
DocumentRoot /User/Vizzaro/Sites
<Directory "/User/Vizzaro/Sites">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Have a look at https://httpd.apache.org/docs/2.2/vhosts/examples.html to find out how to set up virtual hosts. Your configuration file has only one virtual host entry but you need one entry for each site. And furthermore your config is missing the ServerName. Try this: (untested)
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName flowers.loc
DocumentRoot /User/Vizzaro/Sites/drupal8/docroot
# Other directives here
</VirtualHost>
<VirtualHost *:80>
ServerName honey.loc
DocumentRoot /User/Vizzaro/Sites/drupal7/docroot
# Other directives here
</VirtualHost>
And be sure that honey.loc and flowers.loc both point to the IP of the machine on wich your apache is running. Try ping flowers.loc - if this results in an error like Name or service not known you probably have to edit your hosts file to fix it.
Related
I'm attempting to configure simpleSAMLphp within a MAMP/Apache environment on Windows 10 and below is my httpd-vhosts.conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/MAMP/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName simplesamlphp
DocumentRoot C:/MAMP/htdocs/pro-dashboard
Alias /simplesaml C:/MAMP/simplesamlphp/www
<Directory C:/MAMP/simplesamlphp/www>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And here is my /etc/hosts file:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# Virtual Hosts
127.0.0.1 simplesamlphp
Apache starts via MAMP totally fine without including this httpd-vhosts.conf file in my httpd.conf file, but as soon as its included, Apache will not start so the issue appears to be with httpd-vhosts.conf. No errors are shown in the apache_error.log file. My Apache version is 2.2 so I believe my Directory directives in my second VirtualHost are correct.
I've tried double quoting the DocumentRoot's, directory paths etc, and also tried backslashes over forward slashes. I spent most of yesterday trying to figure this out while scouring the web but nothing I found has made this work.
Any help is much appreciated!
Try this modified config
The path in Directory header same as DocumentRoot!
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/MAMP/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName simplesamlphp
DocumentRoot C:/MAMP/htdocs/pro-dashboard
Alias /simplesaml C:/MAMP/simplesamlphp/www
<Directory C:/MAMP/htdocs/pro-dashboard>
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
So oddly enough, taking out what I had in httpd-vhosts.conf and simply putting it in my httpd.conf file makes Apache start back up.
After I configured virtual host, my apache document root changed to the virtual host's document root, I just want to know why.
here is my httpd-vhosts.conf:
<VirtualHost *:80>
ServerName myapp.zend
DocumentRoot /opt/lampp/htdocs/php_zend_projects/myapp
<Directory /opt/lampp/htdocs/php_zend_projects/myapp/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</Directory>
</VirtualHost>
After I restart apache server, localhost page changed to index of /opt/lampp/htdocs/php_zend_projects/myapp,
http://gwjyhs.com/t6/702/1556725814x2728329017.png
but it is supposed to be xampp's default page like this:
http://gwjyhs.com/t6/702/1556726269x2728278877.png
If you enable vhosts you have to add an entry that looks like:
<VirtualHost *:80>
DocumentRoot "F:/Dev/xampp/htdocs"
ServerName localhost
</VirtualHost>
Note: change path to whatever is appropriate for you.
Restart webserver and it should work as before.
Reasoning behind this can be found in a comment on top of the httpd-vhosts.conf:
The first VirtualHost section is used for all requests that do not match a ##ServerName or ##ServerAlias in any block.
That means when you type in localhost it fallbacks to your myapp.zend vhost because it is (probably) the first virtualhost section.
I'm having trouble getting Virtual Hosts to work on MAMP.
Here's my hosts file:
127.0.0.1 localhost
127.0.0.1 mysite
Here's my httpd-vhosts.conf file:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# Custom Virtual Hosts
#
<VirtualHost *:80>
DocumentRoot "/Users/(username)/Documents/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/(username)/Documents/foo/bar/"
ServerName mysite
<Directory "/Users/(username)/Documents/foo/bar/">
AllowOverride all
</Directory>
</VirtualHost>
My httpd.conf looks like this:
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
http://mysite doesn't work. I restarted the apache servers multiple times. I've taken a look into multiple threads on this subject on here, but I can't figure out what's wrong.
EDIT: btw, I'm using /Users/(username)/Documents as my document root for MAMP, maybe I should replace those with the usual /Applications/MAMP/htdocs anyway ?
Check that the ports you set for apache is what you set in your httpd-vhosts.conf file. If its port 80. it should be same in your Mamp apache port.
So I was using Wampserver for developing purposes, and I managed to set up the server for developing purposes (it worked with Dreamweaver, PHP worked etc.) but when accessing localhost, I get a 404 error.
I've hardly changed the settings, other than setting it to use that vhosts file, then I made a few new hosts in the hosts file in system 32, which all works fine.
localhost/phpmyadmin does work, however, so I am really stumped as to why it won't load anything. I also tried loading one of the site folders (localhost/Rufus) which also returned a 404. I have all the directories I need pointing to www folder, where all my files are saved.
And before anyone says, no it's not Skype or IIS, as they are both off and Wampserver is running on port 80 (I checked)
My vhosts file:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<Directory C:\Users\Tom\sites\wamp\www>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
</VirtualHost>
Remove the sample virtual hosts, assuming you aren't using them. You also need a virtual host for 'localhost' and it must be the first virtual host. After that you can include your other, custom vhosts.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
</VirtualHost>
If you get a permission denied error try putting the directive I took out into your httpd.conf:
<Directory "C:\Users\Tom\sites\wamp\www">
Order Deny,Allow
Allow from all
</Directory>
It would go right under a similar directive that includes a Deny from all on the root.
Make sure you always restart Apache whenever you make changes to these files.
The error 404 is saying that you have not granted access to those Virtual Hosts, so Apache is kicking you out.
You need to include with your Virtual Host some information to tell Apache which locations are allowed access to each VHOST
You also need to make localhost a Virtual Host and because the first VHOST is the default VHOST it should really be the first you define, and it should always be limited to allow access only from the local machine.
So see if this works any better.
# Virtual Hosts
#
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www"
ServerName localhost
<Directory "C:\Users\Tom\sites\wamp\www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
<Directory "C:\Users\Tom\sites\wamp\www\Rufus>
AllowOverride All
Require local
</Directory>
</VirtualHost>
Require local says allow access from the PC running WAMPServer only.
If later you want to allow other PC's on your internal network to see the Apache server you can add to that like this, for example.
Require local
Require ip 192.168.1
This, assuming you are on the subnet 192.168.1.? will allow any PC connected to your router (wired or wifi) access to the server.
You should avoid these, unless you actually want the world to access your site
Require all granted
OR the Apache 2.2 syntax, which still works on Apache 2.4
Order Deny,Allow
Allow from all
I have read a lot of articles and posts about Virtual Hosts setting but I was not able to figure out which is the problem.
I have a Win7 pc where I installed an xampp to manage my php + mysql projects.
As per default the web root directory is C:\xampp\htdocs
To avoid conflict with skype I setted apache to work on port 8080
If I browse to something like localhost:8080/mysubdir it works fine.
My idea was now to point the webroot of Apache to another dir on my pc: the dir where I would like to point my webroot is C:\Users\myuser\Google Drive\CODE_REPOS
I searched on-line and it seems to be possible by VirtualHost;
Here my configuration
apache httpd.conf
#Listen [::]:80
Listen *:8080
# Virtual hosts
#Include "conf/extra/httpd-vhosts.conf"
here my httpd-vhosts.conf
# Use name-based virtual hosting.
#
NameVirtualHost *:8080
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:8080>
ServerAdmin admin#localhost.com
DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost development.loc:8080>
ServerAdmin admin#localhost.com
DocumentRoot "C:/Users/myuser/Google Drive/CODE_REPOS" # change this line with your htdocs folder
ServerName development.loc
ServerAlias development.loc
<Directory "C:/Users/myuser/Google Drive/CODE_REPOS">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now the code in C:\Windows\System32\drivers\etc\hosts
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 development.loc
If I stop Apache, uncomment the line #Include "conf/extra/httpd-vhosts.conf" and try to start Apache again, it start and stop immediatly.
I don't understand what I missed.
remove the hash from the start of the include line
apache httpd.conf
#Listen [::]:80
Listen *:8080
# Virtual hosts
include "conf/extra/httpd-vhosts.conf"