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.
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.
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.
To be perfectly honest, I'm not even sure if this is doable...
I've configured my vhosts file in /etc/apache2/sites-enabled which you can see here:
<VirtualHost 159.203.171.140:8080>
ServerAdmin webmaster#localhost
ServerName 159.203.171.140:8080
DocumentRoot "/home/wiki/public_html"
DirectoryIndex index.php index.html
<Directory "/home/wiki/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
CustomLog ${APACHE_LOG_DIR}/wiki_access.log combined
</VirtualHost>
for a digitalocean droplet given at the IP listed in the above hosts file. This droplet has absolutely nothing on it except for the wiki user in /home/ plus the required php, mysql/mariadb, apache stuff.
What I want to be able to do is to go to 159.203.171.140:8080 and see my site without having to purchase a useless domain name.
I'd really appreciate some help with this one.
If you have only one website on the droplet, then you don't need to set up a virtual host. You can use the 000-default.conf, no need for a2ensite.
You do not need the ServerName, which won't work with the IP as a name, you also don't need the IP address in the VirtualHost directive.
So, instead of this:
<VirtualHost 159.203.171.140:8080>
ServerAdmin webmaster#localhost
ServerName 159.203.171.140:8080
DocumentRoot "/home/wiki/public_html"
...
You can use this in your 000-default.conf file
<VirtualHost *:8080>
DocumentRoot "/home/wiki/public_html"
...
The rest of the directive stays as you have it.
Also, one note, if you are using port 8080, then you need go to /etc/apache2/ports.conf and set the Listen to 8080 (restart Apache after doing this).
The issue is that when using MAMP for local development, the .htaccess file needs to differ in that the RewriteBase needs to specify the subdirectory for the specific site (as shown here on SO).
Is there a way to configure MAMP MAMP/conf/apachehttpd.conf so that each virtual site gets it's own "root"?
UPDATE
After getting a clue about Virtual Hosts:
Have updated /etc/hosts file to include:
127.0.0.1 ClientSite.localhost
Uncommented the line:
`#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf`
in /Applications/MAMP/conf/apache/httpd.conf.
There is a directory called ClientSite in /Users/myname/Sites/.
This is the /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf content:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
ServerName localhost
ServerAlias *.localhost
VirtualDocumentRoot /Users/myname/Sites/%0
RewriteLogLevel 3
RewriteLog "/Applications/MAMP/logs/rewrite.log"
<Directory /Users/myname/Sites>
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Restarted the MAMP servers (and even ran dscacheutil -flushcache).
When browser is pointed to ClientSite.localhost it returns a 404: The requested URL / was not found on this server.
so that each virtual site gets it's own "root"?
You need to use VirtualDocumentRoot.
This is how I am using this on my MAMP in my /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
ServerName localhost
ServerAlias *.localhost
VirtualDocumentRoot /Users/admin/htdocs/%0
RewriteLogLevel 3
RewriteLog "/Applications/MAMP/logs/rewrite.log"
<Directory /Users/admin/htdocs>
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Take note of VirtualDocumentRoot /Users/admin/htdocs/%0 directive. That makes each virtual site's root as:
VirtualDocumentRoot /Users/admin/htdocs/localhost
VirtualDocumentRoot /Users/admin/htdocs/dev.localhost
VirtualDocumentRoot /Users/admin/htdocs/client2.localhost
etc.
Then simply create a directory within /Users/admin/htdocs/ for each site named as above, like:
dev.localhost
client2.localhost
Remove (or rename) any .htaccess files during the process - and once websites confirmed to be accessible via url like: http://client2.localhost, .htaccess files should behave as expected.
Also be sure that in the /etc/hosts file, there's an entry like:
127.0.0.1 client2.localhost
for each URL in question.
I have problem with creating virtual host. I am using Windows 7 x64 Professional. In file C:\Windows\System32\drivers\etc\hosts I have only this lines:
127.0.0.1 myhost
127.0.0.1 www.myhost
And in file C:\xampp\apache\conf\extra\httpd-vhosts.conf I have this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Users/Me/Dropbox/Project/public"
ServerName myhost
ServerAlias www.myhost
<Directory "C:/Users/Me/Dropbox/Project/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And of course I have restared my Apache server after adding this lines in those files.
Unfortunatly typing myhost or www.myhost in my browser redirect me to the myhost/xampp.
I have already search and I have found on google and also on stackoverflow description how to configure virtual hosts using xampp but how can I recognize I have done everything alright. I know that my problem isn't new but I didn't found working solution for me.
I have also recognized that typing localhost in my browser redirect me alsto localhost/xampp. I don't know whether these problems are linked in my case.
I had this same issue. Your first request is redirecting to the htdocs root directory. If you look at index.php in the htdocs directory, you can see very brief code that takes the incoming request and redirects it to the xampp directory.
I fixed it by fiddling with the httpd-vhosts.conf file. In your case, try making the following edits:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:\xampp\htdocs\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "C:\Users\Me\Dropbox\Project\public"
ServerName www.myhost
ServerAlias www.myhost
<Directory "C:\Users\Me\Dropbox\Project\public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I had a similar issue and found that I had to go to my Apache24 main httpd.conf file and uncomment around line 501 "Include conf/extra/httpd-vhost.conf"
I had never used that before and it was still #'ed out. Hope this helped anyone not finding other answers here. My Apache24 can now see my vhost file.
You need to enable name-based virtual hosting.
Near the top of the file in C:\xampp\apache\conf\extra\httpd-vhosts
uncomment #NameVirtualHost *:80
i.e. from:
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
To:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
(Note the last line now is uncommented).
Worked like a charm for me. :)
try this
[ file : C:\xampp\apache\conf\extra\httpd-vhosts.conf ]
<VirtualHost basic.test:80>
DocumentRoot "C:/xampp/htdocs/basic/public/"
ServerName basic.test
</VirtualHost>
[ file : C:\Windows\System32\drivers\etc\hosts ]
(open as admin)
127.0.0.1 basic.test
127.0.0.1 localhost
For me replacing this one <VirtualHost *:80> to this <VirtualHost 127.0.0.1:80> working fine.