Question

How to create a subdomain in Apache , Ubuntu 14.04?

  • Posted August 21, 2014

I have installed Apache, Mysql, Webmin & also configured DNS settings for the primary domain but however I want to create a staging site first .i.e. staging.domain.com and then want to make the site live.

I already checked so many articles on Digital Ocean’s forum. Every one has different approach & this all makes it very confusing.

I read these posts but it all seems to have messed up. Can some one please provide an easy way to deal with this?

Thanks in Advance.

Subscribe
Share

This comment has been deleted


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Maybe use A records instead of CName…

When you create your a records, you just need to put in the sub-domain (calis) rather than the full domain (calis.kludgecruft.com)

the only other thing I have noticed is that you are using DocumentRoot /var/www/html for your top-level domain, while your other sites are sub-directories. I wonder if that could be causing some conflict.

You probably know this already, but just to check:

files in /etc/apache2/sites-enabled/ are symlinks to the files in sites-available. As such, if you were renaming your config files, you should delete all those symlinks, then rename the actual files in /sites-available/ and then re-enable all of your sites…(as opposed to just renaming symlinks in/etc/apache2/sites-enabled/)

try using <VirtualHost *:80> rather than: <VirtualHost 104.236.80.93:80>

Maybe this if you want to use .htaccess:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/staging
	ServerAlias   www.staging.domain.com  
	ServerName staging.domain.com   (or whatever name you gave it)

	<Directory /var/www/staging>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride all
		Order allow,deny
		allow from all
                Require all granted
	</Directory>

	ErrorLog ${APACHELOGDIR}/error.log
	CustomLog ${APACHELOGDIR}/error.log/access.log combined

</VirtualHost>

Maybe this if you want to use .htaccess:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/staging
	ServerAlias   www.staging.domain.com  
	ServerName staging.domain.com   (or whatever name you gave it)

	<Directory /var/www/staging>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride all
		Order allow,deny
		allow from all
                Require all granted
	</Directory>

	ErrorLog ${APACHELOGDIR}/error.log
	CustomLog ${APACHELOGDIR}/error.log/access.log combined

</VirtualHost>

Maybe this if you want to use .htaccess:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/staging
	ServerAlias   www.staging.domain.com  
	ServerName staging.domain.com   (or whatever name you gave it)

	<Directory /var/www/staging>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride all
		Order allow,deny
		allow from all
                Require all granted
	</Directory>

	ErrorLog ${APACHELOGDIR}/error.log
	CustomLog ${APACHELOGDIR}/error.log/access.log combined

</VirtualHost>

Maybe this if you want to use .htaccess:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/staging
	ServerAlias   www.staging.domain.com  
	ServerName staging.domain.com   (or whatever name you gave it)

	<Directory /var/www/staging>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride all
		Order allow,deny
		allow from all
                Require all granted
	</Directory>

	ErrorLog ${APACHELOGDIR}/error.log
	CustomLog ${APACHELOGDIR}/error.log/access.log combined

</VirtualHost>

Maybe this if you want to use .htaccess:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/staging
	ServerAlias   www.staging.domain.com  
	ServerName staging.domain.com   (or whatever name you gave it)

	<Directory /var/www/staging>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride all
		Order allow,deny
		allow from all
                Require all granted
	</Directory>

	ErrorLog ${APACHELOGDIR}/error.log
	CustomLog ${APACHELOGDIR}/error.log/access.log combined

</VirtualHost>
  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, so be patient…sleep on it before panicking and re-editing all of your files…

  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, so be patient…sleep on it before panicking and re-editing all of your files…