To add domains like project.local, project.dev or even project.test in XAMPP, in your MAC OS system you would need to follow these directions below. Don’t worry, there are simple.
To create virtual hosts in the latest XAMPP for macOS, follow these steps:
1. Open the httpd-vhosts.conf
File
- Go to the XAMPP directory, typically located at
/Applications/XAMPP/
. - Navigate to the file
httpd-vhosts.conf
:- Open Terminal and type the following command to open the file in a text editor (like nano or your favorite editor):
sudo nano /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
2. Edit the httpd-vhosts.conf
File
- Add the following configuration at the bottom of the file:
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/your-project-folder"
ServerName yoursite.local
</VirtualHost>
- Replace:
/your-project-folder/
with the folder name of your project located in thehtdocs
directory.yoursite.local
with your desired local domain name.
3. Edit the httpd.conf
File
- In the same terminal, open the main Apache configuration file:
sudo nano /Applications/XAMPP/xamppfiles/etc/httpd.conf
Look for the following line and ensure it is uncommented (i.e., remove the #
if it exists):
#Include etc/extra/httpd-vhosts.conf
4. Edit Your hosts
File
- Open the
hosts
file to map the local domain tolocalhost
:
sudo nano /etc/hosts
Add this line at the bottom of the file:
127.0.0.1 yoursite.local
- Replace
yoursite.local
with the domain name you used in thehttpd-vhosts.conf
file.
5. Restart Apache
- Go to the XAMPP control panel or run the following command in Terminal to restart Apache:
sudo /Applications/XAMPP/xamppfiles/xampp stop
sudo /Applications/XAMPP/xamppfiles/xampp start
6. Test Your Virtual Host
- Open a browser and visit your virtual host by typing
http://yoursite.local
. If everything is set up correctly, it should direct you to the appropriate project folder.
This should work. If you encounter any issues, simply start fresh and try again. It may take a couple of attempts to get everything working, but as long as you follow the outlined steps, you should be able to complete it successfully.