Local dev environment with wildcard .test domains, served by dnsmaq on fedora 33/34 [closed]
I am trying to set up an Intel NUC with Fedora 34 as my new stable local web development environment.
My environment on mac OS x gets destroyed by system updates, even homebrew currently throws a lot of errors since last system update.
wanted is this:
- NAS with folder "sites" with a lot of web-projects in it, each in its own subfolder (checked, working)
- fedora system with apache, mariadb, php, ... (lamp) (checked, working)
- sites/subfolder should be served by address subfolder.sites.test
- would be nice if this worked from other computers within LAN, too
On my Mac is just needed to put two lines in dnsmasq.conf and resolve.conf to make this magic happen. virtualhost entry with wildcard serves all.
This is the Mac config:
virtualhost-definition in httpd.conf or similiar:
<VirtualHost *:80>
ServerName sites.test
ServerAlias *.test
VirtualDocumentRoot "/Volumes/webroot/sites/%1/web"
UseCanonicalName Off
</VirtualHost>
in /etc/resolver/test:
nameserver 127.0.0.1
in /usr/local/etc/dnsmasq.conf (through homebrew):
address=/.test/127.0.0.1
On Fedora (and other actual distros) there are things like NetworkManager and systemd-resolved which make things much more complicated.
I read a lot of samples all over the Internet and tried them, without luck.
How to configure this with NetworkManager, systemd-resolved, dnsmaq etc. on Fedora?
This article had the closest match, but still it does not work (or I am missing something?) article: enter link description here
How can I make this work?
After reading Articles on the Web for 2 weeks and trying each and every described way I think, I finally found a solution for this scenario:
- You have a bunch of websites (perhaps located on NAS)
- that shall be called in Webbrowser like this: foldername.sites.test.
As .test is one of the remaining Domains dedicated for "local development". .dev ist not valid anymore.
Temporarily disable SeLinux so it won't block things that technically work. See this Article Enabling/disabling SELinux temporarily/permanently
This Article explains the Setup for dnsmasq and systemd-resolved in detail: Configure dnsmasq and keep systemd-resolved
For anyone new to this, it creates great confusion because there exists:
- dnsmasq (full version)
- dnsmasq as part of NetworkManager
- systemd-resolved (resolver as part of systemd)
- resolve (full version)
You'll get lost in endless configuration possibilities and 99% will not work. The Solution is to install dnsmasq (the full version), ignore NetworkManager-dnsmasq and use systemd-resolved. This combination worked for me, currently on fedora 34.
After setting things up like described in Article 2, you can go on and add vhost-definitions to apache (or any httpd).
For example:
# ##########################################################################
<Directory /var/www/html/nas-mount>
Options Indexes Includes FollowSymLinks ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<VirtualHost *:80>
ServerName sites.test
ServerAlias *.sites.test
VirtualDocumentRoot /var/www/html/nas-mount/%1/web
</VirtualHost>
# ##########################################################################
On some systems it is better to put the Directory definition outside VirtualHost.
This way I can call any web-project within /var/www/html/nas-mount by its name in the browser, followed by "sites.test", automatically.
- project1.sites.test
- bananas.sites.test
- applejuice.sites.test
All *.sites.test respond to 127.0.0.1 by dnsmasq.
This Setup is a great time-saver (if it finally works) for mass-work on a bunch of websites.
The idea for this setup comes from this website mallinson.ca where it is described for a Mac OS System (back 2018).
Making this happen on an actual Distro is not easy, but satisfying if it works :-)