This can be done using XAMPP Control, which is found at /Applications/XAMPP/XAMPP Control.app. So that your changes take effect, restart Apache. Save the host file using the key combo control+o, and pressing return when prompted to choose the filename. Use your keyboard’s arrow keys to navigate to the bottom of the file and add your own mapping: # XAMPP VirtualHost mappings You’ll see that the hosts file already contains some default hostname mappings (e.g. In this case we want to map your new ServerName to the IP address 127.0.0.1, which is your localhost.įire up a Terminal instance, and at the prompt type the following command: sudo nano /etc/hostsĮnter your OS X password when prompted, and the hosts file will be opened in the nano text editor. The hosts file is used by OS X to map hostnames to IP addresses. Once you’ve saved your nf and nf files, the next step is to edit your OS X hosts file so it knows how to handle your new ServerName. If your path includes spaces, make sure you enclose it in quotes, like in my example. I store most of my sites inside of Dropbox so that I can access them on both my home and work machines. The path to your website can point at any folder in your OS X user directory. local extension makes it obvious that the site is hosted locally rather than on a public web server. This can be anything you wish, but make sure you choose a hostname that won’t conflict with a real domain name. In the above example you should replace “mysite.local” with your own hostname. Options Indexes FollowSymLinks Includes ExecCGI After the default localhost that you just created, add: # My custom hostĭocumentRoot "/Users/yourusername/path/to/your/site" Now you are ready to create your own VirtualHosts. Personally I don’t use the htdocs directory a lot, but occasionally it’s useful to have somewhere to perform quick tests. This step is necessary to ensure that still points at XAMPP’s htdocs directory once we’ve created our custom VirtualHosts. Options Indexes FollowSymLinks Includes execCGI Towards the bottom of the file you will see some example VirtualHosts, which you should comment out or delete.Īt the bottom of the file, add ‘localhost’ as the default named VirtualHost: # localhostĭocumentRoot "/Applications/XAMPP/xamppfiles/htdocs" Open the file /Applications/XAMPP/xamppfiles/etc/extra/nf. Include /Applications/XAMPP/etc/extra/nf Create your VirtualHosts Uncomment the second line by removing the hash ( #), so that Apache loads your custom VirtualHosts configuration file: # Virtual hosts #Include /Applications/XAMPP/etc/extra/nf Look for the following lines: # Virtual hosts The first thing you’ll need to do is open the file /Applications/XAMPP/xamppfiles/etc/nf in your favourite text editor. To test your development site all you would need to do is plug “” into your browser’s address bar. For example, you might want to map mysite.local to /Users/yourusername/mysite. You can set up as many VirtualHosts as you need, so that each website operates under its own hostname. VirtualHosts allow Apache to map a hostname to a directory on the filesystem. Here are the steps I followed to get everything running smoothly.įirst, some quick background on what we’re trying to achieve. Installing XAMPP was a snap, but when I came to create my own Apache VirtualHosts things started getting fiddly. While I know that MAMP is very popular on Mac, I have been using XAMPP for many years so I thought I’d stick with what I know. I do all my development locally, so one of the first applications I installed was XAMPP, a cross platform Apache/MySQL/PHP stack. A few weeks back I rejoined the “Cult of Mac” when I replaced my old Asus notebook with a MacBook Pro, and since then I’ve been busy settling into my new OS X workflow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |