Good day!
In the development process, you always want to automate routine operations (or so it seems to me) and proceed directly to really interesting things. Since I am a web developer, for me such an operation has always been the deployment of the environment. Today I will try to simplify as much as possible the task of creating a new host for a new project on a local machine.
If you are tortured by manually creating hosts for Apache, and there is no desire / opportunity / option to use a ready-made XAMPP or Denwer package, please, under cat.
')
Of course, we need Apache. Download and install. Next, a little magic:
Mass virtual hosts
First of all, select the folder where all our projects will live and make it available for Apache. Let it be
d: / sites (I use Windows, so all the examples will be for it, but it should work in Linux):
<Directory d:/sites> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>
Now automate the process of creating new hosts. For this purpose, you need to enable the mod_vhost_alias module for Apache and add only 2 lines to the configuration file:
NameVirtualHost *:80 VirtualDocumentRoot d:/sites/
The key
% -2 tells Apache to take the penultimate part of the request URL and send the request to the subfolder in
d: / sites . As a bonus, subdomains will work. A few examples:
http://test.local -> d:/sites/test http://qwerty.local -> d:/sites/qwerty http://a.domain.local -> d:/sites/domain
You can read more about possible keys
on the documentation page .
Comment. With this host configuration, mod_rewrite will not work. The problem is very simple to fix: you just need to specify "RewriteBase /". The result should be something like this:
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / # Your rewrite rules go next </IfModule>
Automatic DNS configuration
The best solution is to register a new zone * .local in the router (if available), because the hosts files do not support wildcard (*). If there is no router, then the problem can be bypassed with the help of additional software.
Windows
In order not to prescribe a new host every time, you can set up a local DNS proxy. I use
Acrylic DNS Proxy . The program is miniature and extremely easy to use.
- In the properties of the Internet connection, we change the DNS address to 127.0.0.1
- Edit the Acrylic settings file: Programs \ Acrylic DNS Proxy \ Config \ Edit Configuration File . You need to specify the DNS server of your provider or any other available (for example, Google DNS 8.8.8.8) that Acrylic will use when the domain name is not in the cache.
- Editing Programs \ Acrylic DNS Proxy \ Config \ Edit Custom Hosts File . Acrylic understands the asterisk. Hooray! I personally use *. local
- Clear the cache and restart Acrylic: Programs \ Acrylic DNS Proxy \ Config \ Purge Acrylic Cache Data
Linux
For the same purpose, there is
Dnsmasq (thanks to
Anonym ). We edit /
etc / dnsmasq.conf . For the zone * .local, you need to add:
address=/local/127.0.0.1 listen-address=127.0.0.1
Save the changes and restart Dnsmasq.
Bonus: email setup
Windows does not have built-in sendmail. I use the tiny
Test Mail Server Tool utility, which simply puts the letters into a folder.