Issues with Virtual Hosts
I am new to WordPress and I am having a few issues with setting up two separate websites, locally, as virtual hosts.
I have tried to follow numerous tutorials online, without success. I had successfully setup a local wordpress site for testing, but ran into issues when I wanted to have another local site for testing.
Is the only way to have two websites locally, is through virtual hosts?
I think I have changed a few things in the wp files, and now the original site isnt working.
PLEASE please, can someone help me… I am so lost right now.
You can use Virtual hosts or the same hosts and install a different WordPress install in each directory.
As regards breaking your current website, can you give us more information on what is not working? Are you getting an error code or something when trying to access your website?
Honestly, I have no idea what to use.. I just need to be able to have a few different locally hosted sites for testing (different clients etc)..
Is the best thing to do the virtual hosts?
I have changed the httpd.conf file to have the following at the bottom:
# # Use name-based virtual hosting. # NameVirtualHost * <VirtualHost *> DocumentRoot Applications/MAMP/htdocs/strawberryelephant ServerName strawberryelephant.loc </VirtualHost> <VirtualHost *> DocumentRoot Applications/MAMP/htdocs/wordpress ServerName wordpress.loc </VirtualHost>
I then changed the /etc/hosts file (through the terminal) to:
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost # Adobe Blocker 127.0.0.1 strawberryelephant.loc 127.0.0.1 wordpress.loc
My MAMP settings are:
Apache port: 80
MySQL port: 3306
When I was having no problems (before trying to do the virtual hosts) I was using 8888 for apache and 8889 for MySQL port and had no issues..
Please can you let me know where I am going wrong? I don’t know enough about MAMP etc to understand this..
This is how I have set it up.
Set your ports to the “default apache and mysql ports” (80 and 3306) in the preferences of MAMP and quit MAMP.
Move your site folders from Applications/MAMP/htdocs/ to a directory /Users/[Your User Name]/Sites. Replace [Your User Name] with your own username.
Put this above all your virtual hosts in /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf. (replace
NameVirtualHost *with this)
// NameVirtualHost *:80  NameVirtualHost * <VirtualHost *:80> DocumentRoot "/Applications/MAMP/htdocs" ServerName localhost </VirtualHost>
And for every site (virtual host) in a folder called Sites:
<VirtualHost *:80> DocumentRoot "/Users/[Your User Name]/Sites/strawberryelephant" ServerName strawberryelephant.loc <Directory "/Users/[Your User Name]/Sites/strawberryelephant"> AllowOverride All </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot "/Users/[Your User Name]/Sites/wordpress" ServerName wordpress.loc <Directory "/Users/[Your User Name]/Sites/wordpress"> AllowOverride All </Directory> </VirtualHost>
Replace [Your User Name] with your own username.
mod_rewrite needs to be loaded in the httpd.conf file (/Applications/MAMP/conf/apache/httpd.conf) if you want pretty permalinks to work:
LoadModule rewrite_module modules/mod_rewrite.so
Remove (uncomment) the # character if it has that in front of it.
Save the httpd-vhosts.conf file. Flush your dns cache in the terminal or reboot your computer to have the changes take effect.
Open Mamp and go to your websites strawberryelephant.loc or wordpress.loc.
Thanks for the information. I have followed everything without luck.
A few things:
Should the Document Root in the Apache tab (in MAMP) be /Applications/MAMP/htdocs ?
When MAMP start page opens, the port is saying 8889, even though they are set to the default apache and mysql ports…?
When i type in wordpress.loc it brings up Google search…?!
I know I must have missed something.. Any ideas please?
Should the Document Root in the Apache tab (in MAMP) be /Applications/MAMP/htdocs
I still have it at: /Applications/MAMP/htdocs
Clearing your browser cache.
restarting your computer.
Also look if there are any error logs under MAMP/logs
Thank you for helping me..
There are error logs… I’m not sure what to do with them?! There is a large amount of text/errors in apache_error.log and php_error.log
Somehow your Virtiual hosts doesn’t get recognized.
Check your host file if it is correct (you need to use your password to save it)
I have changed the httpd.conf file to have the following at the bottom.
You should put it in /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
and this should be in your httpd.conf file (without a # character in front of it):
Close Mamp when editing httpd-vhosts.conf, httpd.conf or your host file.
Flush your DNS cache after every edit of these files.
What version of MAMP are you using?
My httpd-vhosts.conf contains the following:
# Virtual Hosts
# 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
# for further details before you try to setup virtual hosts.
# You may use the command line option ‘-S’ to verify your virtual host
# Use name-based virtual hosting.
MAMP version: 2.0.5
What do you mean by “host” file?
I made the changes you suggested and still not working. Also, after flushing the DNS cache, and restarting MAMP, the port is still listed as 8889… After trying to type wordpress.loc into my browser, its still bringing up Google search..
What do you mean by “host” file?
Ah, sorry: /etc/hosts file. Did you have to give your password when saving this file.
Just opened my httpd-vhosts.conf file and I see I have this above my virtual hosts:
NameVirtualHost * <VirtualHost *:80> DocumentRoot "/Applications/MAMP/htdocs" ServerName localhost </VirtualHost>
I said earlier to replace
NameVirtualHost *:80but that was a mistake.
Final question, what are the ports for Apache and mySql in Mamp preferences (check it again).
Okay, I updated the httpd-vhosts.conf to the above information.
I am using MAMP version: 2.0.5
After checking the preferences, the ports are still:
Apache port is: 80
MySQL port is: 3306
After flushing and trying again, it is still showing port as 8889 on the MAMP start page..
The /etc/hosts file contains:
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
What version of osx do you use?
I did as the link said, and it all seemed good (MAMP start page opened and was saying the correct port – 3306)… Then I tried typing in wordpress.loc or strawberryelephant.loc and it brought up 404 Not Found Error Page saying: The requested URL /MAMP/ was not found on this server. Apache/2.2.22 (Unix) DAV/2 Server at localhost Port 80 – Now, after rebooting my Mac, and opening the start page, it brings up this error and not the MAMP start page..
Any other ideas? I am freaking out!
I am using OS X 10.7.5
Please, if you know of anything else that will help, or how I can undo it all.. I really need to finish both of these websites..
Try setting the Apache setting “Document Root” to your Sites folder in MAMP preferences.
In system preferences look if Web Sharing is activated under “Saring”. De-activate it if it was.
Try the mamp forums also: http://forum.mamp.info/viewforum.php?f=21
Do you have a administrator account on your mac?
- The topic ‘Issues with Virtual Hosts’ is closed to new replies.