Virtual servers on MAMP (Mac OSX + Apache + MySQL + PHP)
Posted Junio 6th, 2008 by moixo.com
If you are a web developer on PHP and MySQL, probably you needed to define virtual servers on Apache. If you also work on Mac OSX, then a good option to have a development environment fully working and up to dateis MAMP. Alright, in this situation, I recommend you to do this:
- First of all install MAMP in the "Applications" folder.
-
Run MAMP configuration utility located at "Applications/MAMP".
-
Go to preferences to setup configuration options. Choose "Ports" and then click on "Use default ports for Apache and MySQL".
-
Then go to "Apache" option to setup webroot directory where your websites will be located. I prefer "Sites" in home folder.
-
At the moment you have Apache configured. Next step consists in setting up your virtual servers, the folders inside "Sites".
With your preferred text editor (I use "vi"), open Apache configuration file.
sudo vi /Applications/MAMP/conf/apache/httpd.conf
-
At the end of the file, after the line
#NameVirtualHost *
add the following code
NameVirtualHost *:80 <VirtualHost *:80> ServerName priorat DocumentRoot /Users/david/Sites/priorat </VirtualHost> <VirtualHost *:80> ServerName granesferas DocumentRoot /Users/david/Sites/granesferas <VirtualHost> -
Last step consists in defining the corresponding hosts
sudo vi /etc/hosts
add the associations between IP an host name
127.0.0.1 priorat 127.0.0.1 granesferas
- In this example we created two virtual servers accessible from the url http://priorat and http://granesferas.
That's all folks. Thanks to MAMP for his excellent work, Apache, MySQL and PHP.