XAMPP Virtual Host wildcard subdomains on Mac - apache

I want to set up my virtual hosts in a way so that I don't have my projects in the htdocs folder and I would like to use subdomains to get to them. So for example instead of going to "http://localhost/myproject" which would be located inside "/xampp/htdocs/myproject", I'd rather like to go to "http://myproject.sites.local" which would be located inside "/Users/myname/Projects/myproject".
I know I have to go to httpd.conf inside the "etc" folder in xampp and uncomment the line that includes virtual hosts, done that. Then I went to "/etc/hosts" file to add "127.0.0.1 sites.local" and after that I have this chunk of code inside my httpd-vhosts.conf file:
<Directory "/Users/marioplantosar/Projects">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/marioplantosar/Projects"
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/marioplantosar/Projects/%1"
ServerName sites.local
ServerAlias *.sites.local
UseCanonicalName Off
</Virtualhost>
The first part works I guess because if I visit "http://sites.local" it opens the Projects folder root (it just lists the subfolders because there is no index file inside of the "Projects" folder. But the other part is not working and it just throws the "ERR_NAME_NOT_RESOLVED" error. So I have the wildcard "*" in the ServerAlias so that it catches every subdomain of sites.local, and I use the "%1" to open the corresponding folder inside "Projects" folder, however it's just not working. The weirdest part is that it worked for months up until yesterday and I have no idea what happened that it just suddenly stopped working.

I figured out the problem. Everything I wrote in the question was configured correctly, but since I was doing all of that little over a year ago I totally forgot about the dnsmasq part which somehow got messed up. "hosts" file doesn't support wildcards so you have to use a tool like dnsmasq that does the dns masking automatically for every folder inside my "Projects" folder.
For anyone that gets into a similar situation like me, you configured everything in httpd-vhosts.conf, httpd.conf and hosts files correctly but it's not working you should follow this tutorial to set up the dnsmasq: https://passingcuriosity.com/2013/dnsmasq-dev-osx/

Related

XAMPP Virtual Host cant find?

I'm trying to set up a local development environment for a PHP project. The project is placed in the htdocs folder, and i wanna be able to access it on a virtual host environment so all the links and so on works, and treats it as the root directory.
So, here is what i have done:
C:\Windows\System32\drivers\etc
hosts
127.0.0.1 bakeboss.test
C:\xampp\apache\conf\extra
httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\bakeboss"
ServerName bakeboss.test
<Directory "C:\xampp\htdocs\bakeboss">
</Directory>
</VirtualHost>
Apache starts up fine, but if i try to go to (in my browser):
www.bakeboss.test
NOTHING happens - cannot find it, cannot connect. If i go to localhost/bakeboss it works, but obviously not the way i want it.
What am i missing here?

How to serve sites from http://ip/folder?

Please help.
I'm trying to setup 3 test sites, so each could be reached from my server's ip like:
my-server-ip/site1
my-server-ip/site2
my-server-ip/site3
When I use ServerName as ip it works fine:
<VirtualHost 127.0.0.1:8080>
ServerName x.x.x.x
DocumentRoot "/home/myfolder/public_html"
<Directory "/home/myfolder/public_html">
AllowOverride All
</Directory>
</VirtualHost>
but using ServerName x.x.x.x/site1 is not working ofcourse.
I tryed to use Alias /site1 /path and it works for first virtual host but when i add 2 more virtual hosts to vhosts.conf only first works.
Another trick that i tryed is to add:
Alias /site1 /home/folder1/public_html
Alias /site2 /home/folder2/public_html
Alias /site3 /home/folder3/public_html
into /usr/local/apache/conf.d/domain-redirects.conf
and add options into /usr/local/apache/conf/httpd.conf
And this does work but not correctly.
I know I could use some domain name and setup a buch of subdomains for other sites..but using ip is better.
Is there a way to set things up this way?
You need to deposit your sites into the directory that the server accesses. The default that apache gives is /var/www. So if your file is at /var/www/test.html you can access it with 127.0.0.1:8080/test.html .
Thanks! Your idea led to solution. Just in case someone needs the same setup, here is what i've done (running on Centos 6 + Apache+Varnish).
Create and upload folders/files just like you do for normal domains.
By default http://ip -> my apache looks into a folder:
/usr/local/apache/htdocs
I could create a folder here and upload a site here but rather I've created a symlink to my testsite:
ln -s /home/user/public_html/test_site_folder testsite1
now my testsite is available at http://ip/testsite1
almost...to make it work for user I added in httpd.conf this statement (AllowOverride) in order to be able to use mod_rewrite and others in .htaccess located in root folder of testsite1
*** added
<Directory "/usr/local/apache/htdocs">
suPHP_UserGroup user user
AllowOverride All ***
Order allow,deny ***
Allow from all ***

Access Apache virtual hosts stored in /users directory

I just upgraded my Mac to Yosemite and managed to get my development environment almost back to normal. In my old set up (which I didn't create), I stored all of my virtual hosts in /etc/apache2/users as separate .conf files.
I'm now no longer able to access those sites and I need to set up my virtual hosts in the /etc/apache2/extra in the httpd-vhosts.conf file. While it does work, I'd rather not have to do this as it's easier for me to organize all of these extra sites when they're in separate files.
Is there anything I can do to get it back to my original set up? Using my old httpd.conf file doesn't work and I've left the new file that originally came with the Yosemite installation because at the very least it left my development environment functional.
The contents of the .conf files I set up in /etc/apache2/users look like this
<directory "/Users/dev/Sites/*/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
#Require all granted
</directory>
NameVirtualHost *:80
<virtualhost *:80>
DocumentRoot "/Users/dev/Sites/mysitename"
ServerName mysitename.dev
</virtualhost>
I was able to get my virtual hosts working by putting them all inside of the httpd-vhosts.conf file. I only had to add the virtualhost bock and left the directory block and the namevirtualhost *:80 line out as that was already inside of the httpd-vhosts.conf file.
Apache's Configuration file /etc/apache2/httpd.conf can include separate configuration files for processing through the Include and IncludeOptional directive (the difference being, if Include doesn't get a matching file it will fail with error but IncludeOptional will just ignore it)
What you can do now is, add this line at the very bottom of your httpd.conf
IncludeOptional users/*.conf
and place your separate configuration .conf files in /etc/apache2/users directory for including them in the main httpd.conf file

Magento not accessible since tried to move to multi website setup. Apache issue?

I wish I had never seen this article:
http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup
I have Apache 2.2 installed on my XP machine and until a while ago I had a Magento site that I could test the development of a custom module on. I decided that I wanted to have multiple websites and multiple stores so that I could test that my modules configuration variables set at the different scopes (global, website, and store) were working as expected.
So I followed the instructions in the above Magento article. I created a website and gave it a name of “paulsplace.com”. I created a couple of Stores under that website. I then went to System/Configuration/General/Web and, with the scope set to paulsplace.com, I set the unsecured and secured URLs to http://paulsplace.com/ and https://paulsplace.com/ and hit Save Config - what a mistake!!
I got a 404 error. And now I can’t get to my magento front end or back end.
I tried a couple of things:
I added these lines to my hosts lookup file:
127.0.0.1 paulsplace.com
127.0.0.1 www.paulsplace.com
I then uncommented this line in my httpd,conf file:
Include conf/extra/httpd-hosts.conf
and added the following to the conf/extra/httpd-hosts.conf file:
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "C:/Applications/Apache Software Foundation/Apache2.2/htdocs"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
</VirtualHost>
and restarted Apache.
If I browse to “http://www.paulsplace.com” I now get a page that just says “It works!”. Same for “http://paulsplace.com” and “http://www.paulsplace.com/magento/index.php”.
I tried a few more things - I added this line to httpd.conf:
AccessFileName htaccess
(I did this because Windows Explorer didn’t let me create a file starting with a dot; I could do it from the command prompt, but I believe what I have done should be ok).
I changed AllowOverride to All from None:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "C:/Applications/Apache Software Foundation/Apache2.2/htdocs">
AllowOverride All
</Directory>
and in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\htaccess (a file that I created), I entered:
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host ^paulsplace\.com MAGE_RUN_TYPE=website
(pws was the value I used for the “Code” when creating my store).
Please tell me how I can put this right. I feel like I’m taking one step forward and three backward at the moment.
Any help really would be greatly appreciated.
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "Change this to point at your magento install"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
SetEnv MAGE_RUN_TYPE website
SetEnv MAGE_RUN_CODE pws1
</VirtualHost>
If changing anything in System Configuration borks your system, you can always clear out the bad values in the database directly, and clear your Magento cache. Do a
select * from core_config_data where value LIKE '%paulsplace.com%'
This will give you the two rows that were added when you clicked save. Remove the rows. Next, clear out all the files in
var/cache/*
to clear your cache. Then restore your Apache config to what it was before you started monkeying around. This should restore your site back to its previous state, and you can continue to experiment with things.

Apache local configuration to resolve files correctly

I have just configured Apache and PHP to work on my local Mac OS X computer. Now PHP works fine, except when I try to load the files for my live sites. The live sites have separate directories and are sorted by client name etc.
I've created symlinks in the default root for the local web server documents. My issue is that Apache doesn't seem to want to load any of the relative paths that are found in the HTML pages. For example, I have src="/css/main.css" but Apache doesn't load the file, similarly for images, it just resolves as a file not found 404 error. I then thought it might be the symlinks so I copied the full directory into the Apache document root, and still had the same result.
I would really love to setup my local development environment to run Apache, PHP, MySQL to develop locally then publish when ready. I also tried the MAMP installation, and had the same issues.
First you might want to try using src="./css/main.css".
When dealing with multiple live sites I like to setup a single configuration file for each site with apache and then load them all together in the httpd.conf file.
for my setup it looks like this:
in
/etc/apache2/httpd.conf
I have:
# Begin virtual host directives.
Include conf/bortreb.conf
Include conf/rlmcintyre.conf
Include conf/laserkard.conf
Include conf/judyates.conf
and then in
/etc/apache2/conf/judyates.conf
I have:
<VirtualHost *:80>
#localhost site
ServerAdmin email#example.com
DocumentRoot "/home/r/Desktop/web/judyates"
ServerName localhost
ServerAlias judyates.localhost
ErrorLog "/home/r/Desktop/web/judyates/log/error_log.log"
ScriptAlias /cgi-bin/ "/home/r/Desktop/web/judyates/cgi-bin/"
<Directory "/home/r/Desktop/web/judyates">
Options Indexes FollowSymLinks
Options +ExecCGI
AddHandler cgi-script cgi pl py
AllowOverride Options
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
#live site
ServerAdmin email#example.com
DocumentRoot "/home/r/Desktop/web/judyates"
ServerName judyates.com
ServerAlias *.judyates.com
ErrorLog "/home/r/Desktop/web/judyates/log/error_log.log"
ScriptAlias /cgi-bin/ "/home/r/Desktop/web/judyates/cgi-bin/"
<Directory "/home/r/Desktop/web/judyates">
Options Indexes FollowSymLinks
Options +ExecCGI
AddHandler cgi-script cgi pl py
AllowOverride Options
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This way works really well, because you can set the subdomain yoursite.localhost
to loop back to your home ip address.
With this setup, when I work on judyates.com on my computer and want to test anythig, I just go to judyates.localhost in my web browser.
I have about 5 other sites all set up this way in their own *.conf file, so they can each live in their own directories on my computer that exactly match the directories they'll be in on the server.
The key is to use virtual hosts to go to different sites based on the subdomain.
You can learn how to configure subdomains that point to yourself here:
http://digitalpbk.blogspot.com/2007/01/making-subdomains-on-localhost.html
My setup goes even one step further because I setup the server too. Whenever I want to update I load both the webfiles AND the apache config files, and that way the server exactly mirrors my local setup. The only difference is that the real judyates.com points to the server and not my home computer, so when people try to visit the site they get everything from the server.
Have you tried src="css/main.css"? That is, without the leading slash? If you have a leading slash there your files would have to be in a directory named css that was in the root directory of the webserver, and if I understand you correctly that's not the case.
EDIT: OK, from reading your comments it seems like you are not quite clear on how relative urls work. "/css/main.css" is not relative to the page's location in the directory tree. It means a file named "main.css" in a directory named "css" in the root directory of the webserver. When you put your files on the deployment server your css directory is at the webserver's root directory. But it sounds like you are currently putting the css directory in a subdirectory named for the client... so your css file is now living at "/clientname/css/main.css".
If I understand you correctly, you can do what you want by using relative urls. If your html file is in the same directory as the css directory you would need "css/main.css". If it's in a subdirectory of the directory that contains the css directory you would need "../css/main.css"- the ".." means the parent directory of the current directory. If you use relative urls they will continue to work as long as the relationship between the files doesn't change.
Here's a page on the subject that explains it adequately, I think: http://www.webreference.com/html/tutorial2/3.html. Was pretty much the first thing I found in Google though, so there are likely better explanations out there.
There are a number of Apache directives that you could use to do this, but if using relative urls would work for you (and if I understand you correctly it would) then that's likely to be a lot simpler and less likely to cause you further trouble.