itsdarrylnorris / lazydubuntu

(Deprecated) Setting Up my Drupal Enviroment in Ubuntu
http://www.lazydubuntu.com
Apache License 2.0
20 stars 10 forks source link

Virtual Host #1

Closed itsdarrylnorris closed 9 years ago

itsdarrylnorris commented 9 years ago

Problem:

We will have to provide a quick and easy way to setup a new virtual host.

Solution:

Configure the serve to be virtual host. And with a command will generate a virtual host with the desire domain. The domain will end up in .dev. For instance example.dev.

Here are few tutorial that will help us accomplish this goal: http://tinyurl.com/pzwphtx http://tinyurl.com/nkdvtmg

immoreel commented 9 years ago

Hey there,

Almost no tutorial I read about apache vHosts mentions the possibility of dynamic virtual hosts, meaning you don't have to create an entry in httpd.conf for each vhost.

You'd use mod_vhost_alias for it.

Enable mod vhost alias and add a line: Include /path/to/extra/httpdconfs/httpd-dynamic-vhosts.conf

Which in turn contains something like this:

UseCanonicalName Off
VirtualDocumentRoot /path/to/webdirectory/Sites/%-2+/httpdocs
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /path/to/logs/access_log vcommon
ErrorLog  /path/to/logs/error_log

<Directory />
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Then you can have a shell script to make the directories and an entry into your hosts file like so:

#!/bin/bash # ask for domainname read -p "Supply a domainname (fubar): " DOMAIN # Create directories mkdir -p -v ${DOMAIN}/httpdocs/ # Create index file echo "index file created on $(date)" > ${DOMAIN}/httpdocs/index.php # Add to hostfile sudo gsed -i "/^\#local domains$/ s:$:\n127\.0\.0\.1 ${DOMAIN}.dev:" /etc/hosts /usr/bin/open -a "/Applications/Google Chrome.app" "http://${DOMAIN}.dev/" echo 'Domain folders n stuff created and transwarped'

itsdarrylnorris commented 9 years ago

@immoreel Thank you so much for contributing to this project.

Which Apache version are you using ? Or are you using another OS that is not Ubuntu ? Because the names of files are a little bit different from httpd.conf to apache2.conf.

Anyway I love your approach of using mod_vhost_alias would be possible if you can write a patch for this project ?

itsdarrylnorris commented 9 years ago

@immoreel By accident I delete your last comment. But thank you anyway for your resources.

immoreel commented 9 years ago

NP here it is again:

Hey there, i’m on OS X, so I imagine the filenames do indeed differ. Since I’m on OS X, not ubuntu, writing a patch isn’t a possibility, I’m afraid you have to figure that out for yourself.

BTW: Apache version: Apache/2.4.9 (Unix) — See ya!