As a web developer, I often find myself needing to set up a local server to test my projects. Whether it's working on a new website or testing out a new plugin, a local server is an essential tool for any developer. However, setting up a local server can be a real struggle, especially when you have too many projects to do it manually.
In my case, I recently decided to use XAMPP as my local server of choice temporarily. But I had too many projects to set them up manually, so I decided to find a better way.
That's when I decided to write a script that automates the process of setting up virtual hosts for XAMPP on macOS. This script is called xampp-auto-vhost.sh and it's available for download on my GitHub repository at https://github.com/Preshy/xampp-apache-auto-vhost-mac
The script checks if vhosts is enabled for Apache in XAMPP, and if not it exits the script. Then it prompts the user for the path and domain name of the website, and adds the necessary configuration for the virtual host and entry in the /etc/hosts file. Finally, it restarts the Apache server to make the changes take effect.
By using this script, setting up virtual hosts for XAMPP on macOS is as easy as running a single command. No more struggling with config files or trying to figure out why your virtual host isn't working.
Using the Script
You can use it by following these steps:
1. Download the script and make it executable by running the command chmod +x xampp-auto-vhost.sh
2. Run the script by executing sudo xampp-auto-vhost.sh. This script assumes that XAMPP is installed in the default location of /Applications/XAMPP and also needs to run as an administrator to be able to make changes to the /etc/hosts file.
The script will add the virtual host configuration and the entry in the /etc/hosts file.
Finally it will restart the Apache server to make the changes take effect.
This script will save a lot of time and effort when setting up virtual hosts for XAMPP on macOS. I hope it will be helpful for other developers as well. If you have any questions or feedback, please feel free to reach out on GitHub.