D4rKiTo
D4rKiTo

Reputation: 3

How properly set a website and domain (with subdomains) with apache on ubuntu?

First of all, apologies for my English.

I've been reading and reading guides last week a lot hours with no success. I bought a domain + hosting but due bad performance I've got a cheap vps to use as hosting. Currently my setup is:

My site works fine but I'm don't know how create subdomains with different directories. For example, my website.com files are in /var/www/html and I'd like to create subdomain.website.com with the files in other directory, let's say /var/www/subdomain.

I checked a lot tutorials and they say to create a virtual server on apache (I use webmin) and then an A record for the subdomain pointing to the server ip.

The problem is that when I enter to subdomain.website.com I see the content from main domain (/var/www/html) and not from "/var/www/subdomain"

I don't want ask you for a full guide step by step, I just need know where I need to start for achieve a subdomain with a different directory because usually I always used hosting services with tools like cpanel to create subdomains pointed to directories in 2 clicks.

I'm a full newbie with Apache/dns management.

Thanks a lot for your time!

Upvotes: 0

Views: 4353

Answers (1)

hamnix
hamnix

Reputation: 161

Create a virtual host in Apache by creating a file at /etc/apache2/sites-available/subdomain.website.com.conf

In that file, add the following

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName subdomain.website.com
    DocumentRoot /var/www/subdomain.website.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now place your subdomain.website.com files at

/var/www/subdomain.website.com/public_html

Then enable the new virtual host by sudo a2ensite subdomain.website.com

After placing the files, if you get a 403 forbidden error, check for permissions of the DocumentRoot folder.

Refer: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

Upvotes: 3

Related Questions