Question

How to create a subdomain in Apache , Ubuntu 14.04?

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.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

  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…

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 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)