Skip to content

Instantly share code, notes, and snippets.

@syntaxseed
Last active May 10, 2021 19:40
Show Gist options
  • Save syntaxseed/a070002c5303c91ea0370de4e5c299e0 to your computer and use it in GitHub Desktop.
Save syntaxseed/a070002c5303c91ea0370de4e5c299e0 to your computer and use it in GitHub Desktop.
Set Up Local Wildcard Apache Sites
1) Add to your /etc/hosts file, one line per site/project.
```
127.0.0.1 project1.dev.test
127.0.0.1 sandbox.dev.test
127.0.0.1 slim.dev.test
```
2) Set up a wildcard in Apache2's sites:
/etc/apache2/sites-available/wildcard.conf
```
<VirtualHost *:80>
# INFO: This configuration works for any *.dev.test local domains. Requires apache module vhost_alias.
ServerName dev.test
ServerAlias *.dev.test
VirtualDocumentRoot /home/yourname/Path/To/LocalSites/%1/public
DirectoryIndex index.html index.php
# Send 404 errors back to index.php for handling by the framework.
FallbackResource /index.php
<Directory />
Options Indexes FollowSymLinks
Require all granted
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error-wildcard-sites.log
CustomLog ${APACHE_LOG_DIR}/access-wildcard-sites.log combined
</VirtualHost>
```
The %1 in the above file, will be replaced by the symlink name in step 4!
3) Enable the wildcard site in apache:
```
sudo a2ensite wildcard
sudo service apache2 restart
```
4) Create symlinks in the LocalSites path (configured above in the VirtualDocumentRoot) to the actual location on your machine of this project. Project must contain a public/ directory below this target.
Your paths will differ!!
```
cd /home/yourname/Path/To/LocalSites
ln -s /home/user/Development/Git/Personal/sandbox sandbox
ln -s /home/user/Development/Git/Client/project1 project1
```
5) Adding another site?
- Add a line to the hosts file.
- Create a new symlink from LocalSites to the actual project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment