Configure MAMP to treat each directory in Htdocs as Root in Apache mod_redirect - apache

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.

Related

MAMP Apache Won't Start with Virtual Host for SimpleSAMLphp

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.

Apache VirtualHost configure

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.

apache 2.4 serverAlias with * wildcard overwrittes specificed vhost

I have two vhosts the default one and another one:
<VirtualHost *:80>
ServerName www.eve-stuff.com
ServerAlias *.eve-stuff.com
DocumentRoot /var/www/html/test
<Directory /var/www/html/test>
Options +FollowSymLinks
AllowOverride None
#Require all denied
</Directory>
</VirtualHost>
This one should just redirect all subdomains that a not specifically setup to the test directory.
This is another vhost i have:
<VirtualHost *:80>
ServerName dev.eve-stuff.com
DocumentRoot /var/www/html/dev
<Directory /var/www/html/dev>
Options +FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
This one should show the dev folder for the dev subdomain.
From what I understood from the apache doc the ServerAlias *.eve-stuff.com in the first host will always catch UNLESS another vhost has specifically been created for the address.
However dev.eve-stuff.com still redirects to the test folder not to the dev folder, as it should.
All dns entries, also for the subdomains, point to the right IP.
I am running Apache/2.4.18 (Ubuntu).
Turns out the order in which it is setup matters.
Apache apparently looks for the matching host it can find.
Since the first config was in 000-default.conf and the second one was in the 020-dev.conf the dev-subdomain matched the first vhost and used that.
I changed default to 999-default.conf which means now dev will first be matched with the proper vhost but other undefined subdomains will still be matched with the default vhost.

What is the procedure to add domain aliases to an existing linux apache installation?

I have a personal VPS hosted in * and an ubuntu installation. The ubuntu runs apache,php,mysql and is currently being used for 5 websites mapped by virtualhosts. I am writing the whole procedure in case someone needs it.
When I want to add a new domain, I create an 127.0.0.1 test.com *.test.com row in /etc/hosts, add a new file in /etc/apache2/sites-available and run a2ensite test.com - then restart apache. Each website has its own folder in /var/www and the virtualhost entry looks like this :
<Virtualhost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin info#test.com
ServerName www.test.com
ServerAlias test.com *.test.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot "/var/www/test.com"
<Directory /var/www/test.com>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</Virtualhost>
I am planning to add some aliases like aaa.test.com, bbb.test.com, ccc.test.com etc. which will point/forward to different folders. The aaa.test.com one will point to /var/www/aaa/index.php and the bbb.test.com to /var/www/bbb/index.php. To summarize, different aliases - same domain - different folders all in apache. How do I achieve that ?
There can only exist one DocumentRoot per VirtualHost container. Since you have specified different DocumentRoot for each aaa.test.com, bbb.test.com etc, you need to setup a separate VirtualHost for each:
<VirtualHost *:80>
ServerName aaa.test.com
DocumentRoot /var/www/aaa
DirectoryIndex index.php index.html
...
</VirtualHost>
and so on.
As aaa.test.com and bbb.test.com should point to different directories, You are required to create separate Virtualhost entries manually. Before that you have to remove the _*.test.com_ from the ServerAlias of test.com Virtualhost entry. Then create a file at /etc/apache2/sites-available , say aaa.test.com and add the following and then save
<Virtualhost *:80>
ServerName aaa.test.com
DirectoryIndex index.html index.php
DocumentRoot "/var/www/aaa/"
</Virtualhost>
make sure to restart/reload the apache service.
Do the same for bbb.test.com.. That is all you required to do... All d best :)

configuring virtual host and localhost redirecting to the xampp folder

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.