⬆️ ⬇️

Automatic configuration of apache vhosts or denwer for Mac

Probably many had to manually configure the vhost-s, place all sorts of test stays on different ports, always remember where everything lies. Pretty tedious. I think this is one of the reasons why novice web developers are so fond of Denver, who are relieved by the need to set up apache. Driving once again a new vhost, I decided to somehow change the situation.



Remembering that an article about tools like inotify, incrontab and using these to automatically start services was already running through Habré, I began to look for similar solutions for Mac Os X. During trial and error, I found out that you can create your own service that will be launched by events file system. What you need.

After a day of picking bash, I wrote a php script in half an hour.



The algorithm of the script turned out to be simple and looks like this:

  1. get a list of folders with sites
  2. we screen out invalid names
  3. if the resulting list does not match the current settings, generate new settings
  4. ask for administrator password
  5. we register settings in / ect / hosts and / etc / apache2 / vhosts


If the system has growlnotify installed, then messages about what is happening will be displayed in pop-up windows.



If you are interested in this tool, you can download it here . The installation procedure is not very trivial (for Mac Os X):



In the folder with the sites should be a folder with sites. If you do not specify anything, then the default value is "~ / Sites". For the settings to take effect, you need to change something in the “folder with sites”, or run in the terminal “agent.php [<folder with sites>]”.

')

After installation, you can go to the Sites folder, create a test folder there, index.html in it, and test its performance in the browser.



Notes.

  1. If you change the value of the ALLOW_PRECONFIGRE_HTTPD parameter to true before in the config.php file, then at startup the script itself can add the necessary line to /etc/apache2/httpd.conf and create a folder. But the script does not check anything, and if something suddenly breaks, blame yourself.
  2. A reboot is necessary for the normal operation of the authorization procedure. Without a reboot, a password prompt window is not displayed.




Ps. I understand that Denwer is a lot more than it’s in the article, but this is the part of denwer that I needed.

Source: https://habr.com/ru/post/70145/



All Articles