How can I setup a virtual hosting on my Mac. It should be easy by adding a 127.0.0.1 line to the hosts file and editing the apache configuration. But for some reason, it doesn't work with me...
And no, MAMP is not an option since you can't setup vhosts in MAMP (except if you buy the MAMP Pro...)
Any advice?
It works just fine, i have several vhosts set up on my OS X box under apache. Make sure that you are using name-based virtual hosting AND that if you are using apache that is distributed with OS X and the vhosts config is in a separate file (e.g. in /etc/apache2/other/httpd-vhosts.conf) that it is actually getting included. Also you can always test apachectl -t -D DUMP_VHOSTS to see if the virtual hosts are actually getting defined.
Related
I am setting up a new machine. I have it configured to use a Sites folder and localhost to access it. Using Apache, everything installed via Homebrew.
Sites folder
site1
site2
In the browser
localhost/site1/index.html
localhost/site2/index.html
That part works fine.
The problem is that site1 and site2 think localhost is the root folder (which it is) but I want them to think localhost/site1 and localhost/site2 are the root folders for those sites.
Is this something I can do with /etc/hosts or some other trickery?
It turns out this is a combination of /etc/hosts and Apache VirtualHosts. Here are the steps I took:
Establish the directories where you want to serve them from (this will become your DocumentRoot). In my case /Users/myusername/Sites/site1
Edit your /etc/hosts file to include your new "domain name" (this will become your ServerName). In my case site1.com
127.0.0.1 site1.com
::site1.com
Create an Apache Virtual Host ... there are different ways to go about this, but I used Homebrew to install Apache, so for me, there is a file here: /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf. I copied the examples provided using DocumentRoot and ServerName as noted above.
Update this file /opt/homebrew/etc/httpd/httpd.conf to uncomment this line
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
Restart Apache
On mac OS (El Capitan) I have a virtual machine vagrant with laravel-homestead box. In one of my dev projects I need to use dynamically created subdomains for each user registered on site (e.g. user.sitename.dev, user2.sitename.dev, etc.). So, I used dnsmasq to do this and everything works fine but only with internet connection. If I disable connection, dnsmasq doesn’t resolve domains. Here are my configuration files:
Local:
/etc/resolver/dev:
nameserver 192.168.10.10
/usr/local/etc/dnsmasq.conf:
address=/.dev/192.168.10.10
Virtual machine:
/etc/dnsmasq.conf:
local=/dev/
domain=dev
address=/.dev/192.168.10.10
/etc/nginx/sites-available/sitename:
server_name sitename.dev *.sitename.dev;
What can be the reason of this problem?
I'm using dnsmasq on the Mac (OS X 10.7) to facilitate local development (along with MAMP), with just this pretty simple config:
[dnsmasq.conf]
address=/dev/127.0.0.1
.. pretty darn simple. All my *.dev domains resolve to 127.0.0.1 (localhost). Together with:
[DNS Servers]
127.0.0.1
8.8.8.8
8.8.8.4
..as my Mac's DNS settings, this works a treat.
But then I also have a pretty stock Windows 7 SP 1 VM running in VirtualBox (latest). It uses 10.0.2.* as its IP subnet within Windows. At the moment I have to use a service like http://xip.io + another hostname alias to use my *.dev sites in Windows, e.g:
[ if Mac's local IP is 192.168.1.50 ]
something.dev.192.168.1.50.xip.io
..and I need to have this extra ServerAlias manually set up in my Apache config, and keep it updated each time my local IP address changes.
Is there any way I can set up either dnsmasq, VirtualBox, or my Windows IP settings (or a combination of these) so that I can use my .dev hostnames (e.g. http://something.dev/) directly from Windows?
Try this:
https://github.com/stackia/DNSAgent
It has functions similar to Dnsmasq server= and address=
and a rule converter: https://stackia.github.io/masq2agent/
If you mean that you want to run something like dnsmasq on your windows vm then I share your pain. I have been trying to get something setup on a windows host to do wildcard localhost sites without doing something like xip.io but I am having problems getting it to work. Dnsmasq on the osx machine I have was a breeze, but trying to get Acrylic DNS to work on windows the same way hasn't worked. I do have it running as a local caching DNS, and it should be doing the wildcard part, but having problems getting over the final steps.
Check it out. Looks neat, free, and a dnsmasq alternative on windows. And if you get it working post your results! I'll do the same if I can get it going.
After upgrading my MacBook Pro to Mac OS X Lion I am not able anymore to get my 'Zend Server' running like before. At first the 'Zend Server' gave me servile errors by starting it from the command line. I fix this by doing a complete new installation of Zend Server.
After this new installation Zend Server runs fine and no problems at all. So now I want to put back my zend projects. I made a backup of my vhost file and put it back, it seems to be Lion didn't touch my host file so I didn't touch either (just checked). I did the follow things;
Put one of my vhosts back in conf/extra/httpd-vhosts.conf (just one to check).
Uncomment the vhost include in conf/httpd.conf
Checked my host file
Restart zend server from command line
After this I still cant reach the project by browsing to http://foo.localhost:10088/
Vhosts
<VirtualHost *:10088>
ServerAdmin my#email.com
SetEnv APPLICATION_ENV "development"
DocumentRoot "/Users/nicky/Zend/workspaces/DefaultWorkspace7/foo/public"
ServerName foo.localhost
ErrorLog "/Users/nicky/Zend/workspaces/foo-log"
CustomLog "/Users/nicky/Zend/workspaces/foo-log" common
</VirtualHost>
Hosts
127.0.0.1 localhost
127.0.0.1 dummy-host.example.com
127.0.0.1 dummy-host2.example.com
127.0.0.1 foo.localhost
I am not sure if this can have effect on the problem, but by restarting zend from the
command line, i get the follow:
MacBook-Pro-van-Nicky-Klaasse:~ nickyklaasse$ sudo /usr/local/zend/bin/zendctl.sh
restarthttpd: Could not reliably determine the server's fully qualified domain name,
using MacBook-Pro-van-Nicky-Klaasse.local for ServerName
Regards,
Nicky
I've had similar problems as well with that. I've been searching around for an answer, found some solutions but none of them seemed to work.
The only thing that finally made it working (not even sure how it actually helped), is going into system preferences -> sharing and enabling web sharing. That is normally starting your apache2 server but I wasn't using the default one, I am running another apache2 process with a different httpd configuration. Anyway, after starting it and stopping it (from the system preferences window), it seemed like it was working.
One thing that could be useful is checking your error_log as well as the access_log in /var/log/apache2/. Check the access_log to see what is the address trying to be resolved. At first, whenever I was making a request on my website through the Virtual Host, in my access log I only had 127.0.0.1 which is incorrect. After it worked, I can see that the requests are www.example.com and not the localhost, showing that the virtual host is indeed working.
Not sure if that will help you, give it a try, paste the access_log and error_log latest lines to see where there could be a problem.
My local django dev environment (apache 2.2, Python 2.6, Django 1.2a, mod_wsgi, sqlite, win7 64bit) is really slow. It usually takes 15sec-30sec to load a page.
Any ideas what might be slowing it down? Same application on the production server runs just fine.
Task manager shows:
Task Manager http://img268.imageshack.us/img268/4396/20100201210438.gif
What host name are you using to access your site? Are you using 'localhost'? If so, try using '127.0.0.1' instead and see if it runs quicker.
Seen a few times where people would experience delays because of fact that IPV6 is enabled by default on Windows 7. This was causing issues when accessing via localhost. The solution was to edit:
C:\Windows\system32\drivers\etc\hosts
and comment out the line:
::1 localhost
Ie., make it so it reads:
# ::1 localhost
If there is a line:
# 127.0.0.1 localhost
uncomment it so it reads:
127.0.0.1 localhost
Anyway, think that was what the changes needed to be.