Jump to content
The Uniform Server Community
Sign in to follow this  
Pedja

How to setup multiple domains for projects on local Uniform Server

Recommended Posts

I just installed Uniform Server and I am delighted. First impression is that it is easy to set, efficient and clean. Great Work!

I am in web stuff for decades and none of the tools I used for local development environment seems so nice. Kudos to developers.

In my workflow I use separate local domains for each project. There is number of reasons I never embraced local www site with each project in subdirectory as it is widely proposed by all WAMP platforms. I usually just use public domain for the project and add .loc at the end.

My other requirement is that each project is easily configurable and all configuration is easily shareable among several computers or several developers if they are involved on the same project (by using git,  svn or similar service).

So, here I will explain how i did it with Uniform Server, as I guess others can benefit from this approach.

Presumptions:

- directory where projects are stored is c:\www_projects

- each project is within this directory as separate directory (usually) named by project domain

- all configuration including Apache config is within this directory for easy sharing, placed in c:\www_projects\_vhosts

- example project domain is example.org

 

 

First thing is to set Uniform Server as proposed in setup instructions and make sure it works fine.

 

Then create directory c:\www_projects\example.org and place project web site files there.

 

Then we need project local domain in .hosts file. You can edit .hosts file directly or use Uniform Server option Extra / Edit Win hosts file. Make sure you set both base domain and www domain for the project. As we use example.org as project domain .hosts file should get two additional lines like:

127.0.0.1 example.org.loc
127.0.0.1 www.example.org.loc

 

Then we have to edit httpd.conf. You may use Apache / Edit Configuration files menu in Uniform Server. Go to the bottom file and add these lines:

Define projects_www_path c:\www_projects
Include ${projects_www_path}/httpd_projects_www_hosts.conf

This will allow Apache to load additional virtual hosts settings from separate configuration files that you control outside of Uniform Server. This edit is the only one that must be done within Uniform Server configuration. Everything else is within your projects. This means if you set new computer, all you have to do is copy projects directory and add these two lines in httpd.conf. This will work even if you use different WAMP platform.

 

Now create file D:\www_projects\httpd_projects_www_hosts.conf using text editor and make sure it's contents is like this
 

#
# Virtual Hosts for Custom Projects
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#

<Directory ${projects_www_path}>
		#Options FollowSymLinks Indexes
		AllowOverride All
		Order deny,allow
		Allow from all
		Require all granted
</Directory>

<VirtualHost *>
  DocumentRoot "${projects_www_path}/default"
  ErrorLog "logs/default-error.log"
  CustomLog "logs/default-access.log" common
</VirtualHost>


Include ${projects_www_path}/_vhosts/*.conf

This will instruct Apache to look for virtual host config files in  c:\www_projects\_vhosts\. There you would put virtual host config file for each project.

For our example virtual host file should be named c:\www_projects\_vhosts\test.org.conf and its content might be something like this:

<VirtualHost *>
	DocumentRoot "${projects_www_path}/example.org"
	ServerName example.org.loc
	ServerAlias www.example.org.loc
    CustomLog "logs/example.org.log" common
  ErrorLog "logs/example.org-error.log"
</VirtualHost>

This is the most basic settings and good enough for development. Apache will know where to find project files and will store access and error logs separately for this project.

 

Now you have to restart Apache for this configuration to be loaded and check if site is visible at domain example.org.loc or www.example.org.loc

 

Further, if you want to add additional projects you just have to create project directory in c:\www_projects, store project files there and create virtual host configuration file in c:\www_projects\_vhosts. And restart Apache, of course.

Share this post


Link to post
Share on other sites

I used a different (and imo better location) for my files - /uniserver/vhosts/

I work my configuration files a bit differently to yours but there are elements of your setup i quite like..

As for restarting apache you can just use a quick command - apache.exe -k restart - but from the command line you must be in the same folder as apache.exe. You can also run it from a .bat script but note that it can't be done from php using the exec function (tried). This tells apache to kill off the current child threads when they're done and then restart them with the new configuration - but apache itself does not restart and this means that any current http connections that are in use (eg a file download) continue to run. Note that if you're running apache as a windows service (my personal choice) you need to make sure that it's installed with it's version number - so mine is apache 2.2 and US installed it as ApacheS1. When apache receives a restart signal it looks for itself with it's version number so i had to uninstall and reinstall it as apache2.2 for it to work correctly..

I've got my vhosts.php from the US admin panel modified to create a folder structure for each new virtual host - it creates a named folder then subfolders; conf, ftp, logs, private, www. www is for public files obviously, ftp for annonymous ftp, conf for apache files / ssl certificates, private for stashing things like database connection files and logs is self explanatory. Also my vhosts.php automatically creates the virtualhost config in http.conf - but i quite like the look of your setup so might consider switching. I also modded it to delete vhosts too (including in http.conf).

IF you want proper virtual hosting so that you can use real / local domains then you need to setup a local dns nameserver on your PC and reconfigure windows to use that. Uniformserver does not come with this so i created one myself (crude but functional) but then i realised that you'd need to reconfigure every device on the network.. so yup.. i did the dhcp server too lol which lets you specify a dns server to use... also crude but functional.

It's taken me quite a bit of work to hack and modify my US but i'm rather pleased with it now.. the only thing left for me is to hack the SSL certificate generator so that each virtual host can have SSL enabled automatically..

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...