Created
August 17, 2016 15:18
-
-
Save kolunar/535e601ad85bace399d36ce7623cd9a1 to your computer and use it in GitHub Desktop.
How To Set Up Subdomain or multi-domains and Apache Virtual Hosts on Ubuntu 14.04 LTS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Summary | |
========= | |
1) Create an A record for your sub-domain that points to your droplet | |
2) Create a .config file for your sub-domain site in /etc/apache2/sites-available | |
3) Create the directory for your site in /var/www (or wherever you said it was in the config file) | |
4) Enable the site in apache with: sudo a2ensite sub.yourdomain.com (or whatever you named your site in the config) | |
5) reload apache: sudo service apache2 reload | |
NOTE: the DNS record you create might take awhile to propagate | |
============================================================================================ | |
1). | |
In domain's DNS settings (e.g. digitalocean) | |
A--->demo.example.com.--->IPAddress (NOTE: there's a "." at the end of demo.example.com) | |
If using CDN (e.g. cloudflare) | |
A--->demo---------------->IPAddress [DNS & HTTP proxy(CDN)] | |
2). | |
/* make directory for a new subdomain or domain under the same directory as the original website or create one if not exists. */ | |
Examples: | |
sudo mkdir -p /var/www/example.com/ | |
sudo mkdir -p /var/www/demo-site/ (would become demo.example.com) | |
sudo mkdir -p /var/www/example2.com/ | |
/* grant permission to the new directory: */ | |
sudo chown -R $USER:$USER /var/www/test.com/ | |
/* modify permissions to ensure that read access is permitted: */ | |
sudo chmod -R 755 /var/www | |
/* Copy the default Virtual Host and Customize for Second(sub/new) Domain */ | |
clone existing 000-default.conf under /etc/apache2/sites-available/ | |
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-demo.conf | |
/* IMPORTANT:: The original or the first Virtual Host must be modifed as below */ | |
E.g. if 000-joomla.conf is the first Virtual Host, then: | |
ServerName example.com | |
ServerAlias www.example.com | |
NOTE: forgetting to do the step above will cause database or cache conflict. | |
E.g. virtualhost for demo.example.com | |
<VirtualHost *:80> | |
<Directory /var/www/demo> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Order allow,deny | |
allow from all | |
</Directory> | |
ServerName demo.example.com | |
ServerAlias www.demo.example.com | |
ServerAdmin webmaster@localhost | |
DocumentRoot /var/www/demo | |
... | |
</VirtualHost> | |
after that, enable the New Virtual Host Files as below: | |
E.g: | |
sudo a2ensite example.com.conf | |
sudo a2ensite 000-demo.conf | |
then, reload apache | |
sudo service apache2 reload | |
Ref: How to Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS | |
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment