1

I have an instance on Amazon AWS (Ubuntu server).

I want to create a sub-domain for my website: tools.example.com for people in the office I work in, and build tools (using PHP) so employees can work with. (code automation web-apps for ex).

I have never created a sub-domain on a Linux server myself (I usually worked with hosting companies with cPanel ect'), and I'm new to Amazon AWS, which I find very awesome, and working with a Linux server and doing everything by myself - Extremely awesome!

So I was starting to explore how to create a sub-domain on my website, and I got to a point that I know that I have 2 options, which I don't exactly know what are the differences between them, what will be the implications on my work ect'.

The first option is creating the sub-domain using Amazon Route53: http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingNewSubdomain.html

and the second option I encountered was doing this using the Ubuntu server itself, ex: https://askubuntu.com/questions/463618/setting-up-subdomain-on-ubuntu-server http://kim.sg/index.php/ubuntu/17-how-to-setup-subdomain-on-ubuntu-server-14-04

Some things seem vague for me a little bit and I will be happy to have more enlightenment points from people who know a little bit more about the theoretic "stuff" and will know to guide me to the best choice for me.

Please feel free to ask me questions.

for @Stefano Martins (28.10.2015):

Ok, I did this:

<VirtualHost *:80>
    ServerName tools.example.com
    ServerAdmin walid@example.com

    ErrorLog /var/www/tools.example.com/logs/error.log
    CustomLog /var/www/tools.example.com/logs/access.log combined
    DocumentRoot /var/www/tools.example.com/public_html
</VirtualHost>

mkdir -p /var/www/tools.example.com/{public_html,logs}

sudo a2ensite tools.example.com.conf
sudo service apache2 reload
sudo find /var/www/tools.example.com/public_html -type d -exec chmod 755 {} \;
sudo find /var/www/tools.example.com/public_html -type f -exec chmod 644 {} \;
sudo adduser ubuntu www-data
sudo find /var/www/tools.example.com/public_html -type d -exec chmod 775 {} \;
sudo find /var/www/tools.example.com/public_html -type f -exec chmod 664 {} \;

My folder is the var one, not the srv. I changed everything from srv to var and now I don't get the 403 error anymore. but now I cant upload to /var/www/tools.example.com/public_html via FTP.

UPDATE: I used sudo chown www-data:www-data -R /var/www/ that solved my problem.

Thanks A LOT!

2 Answers2

2

That's the thing with Amazon Web Services. You have a lot of options to construct your infrastructure, beginning with the simple EBS (Elastic Beanstalk) which provides an easy-to-deploy (a.k.a. quick-and-dirty way) environment.

Another option is to use EC2 and build it yourself, and since this is the way you've chosen so far, basically what you need is:

In your Route 53, create a CNAME or an A record pointing to your instance's IP address (you should use Elastic IPs to make sure your instance always get the same IP address). I would suggest a CNAME entry because you already has an A record in your zone. It makes your DNS resolution a little bit slower, but it's easier to manager through time. We can call that tools.example.com.

In your Apache configuration's directory (usually /etc/apache2/sites-available), create a file called tools.example.com.conf with the following content:

<VirtualHost *:80>
    ServerName tools.example.com
    ServerAdmin me@example.com

    ErrorLog /srv/www/tools.example.com/logs/error.log
    CustomLog /srv/www/tools.example.com/logs/access.log combined
    DocumentRoot /srv/www/tools.example.com/public_html
</VirtualHost>

Create the directory which will store your site/application with:

mkdir -p /srv/www/tools.example.com/{public_html,logs}

Enable the new virtualhost and reload Apache's service:

sudo a2ensite tools.example.com.conf
sudo service apache2 reload

A tip: in most cases, using AWS infrastructure and out-of-the-box solutions is cheaper.

Note: Basically, this is what you need, but this is not 100% ideal for a production environment.

Cya!

  • First of all thanks a lot for your well explaned answer!

    I went through all that you said, and in the end when restarting with service apache2 reload I got a lot of errors without apache2 loading back again, I had to delete all the content in the file I created and restart back again.
    I'm editing my main post with the outputs. Please check them out.

    – Rick Sanchez Oct 20 '15 at 12:21
  • I had a mini-heart attack, I thought I have to install everything (apache for ex) and I really need the website to be available right now :S – Rick Sanchez Oct 20 '15 at 12:24
  • Sorry, I've made a mistake in the Apache's config file. Simply change "AccessLog" to "CustomLog" in the /etc/apache2/sites-available/tools.example.com.conf file and restart the service. I'm editing my answer right now to match it! =) – Stefano Martins Oct 21 '15 at 12:48
  • Ok, I did everything and my website didn't crash (YEY!)

    Where do I upload files ? under /var/www/ I have a folder called "html" where all my main domain files are (for www.example.com)

    Where should the other files go :X

    – Rick Sanchez Oct 28 '15 at 12:51
  • btw, http://tools.example.com/ gives me a 403 error

    `Forbidden

    You don't have permission to access / on this server.`

    – Rick Sanchez Oct 28 '15 at 12:54
  • I navigated to: /srv/www/tools.example.com and I cant upload files via WinSCP. How do I grant general access? – Rick Sanchez Oct 28 '15 at 13:02
  • Copy these files to your /home/ubuntu directory. Then, login using SSH and run: sudo mv /home/ubuntu/my-site-dir/* /srv/www/tools.example.com/public_html ; sudo chown www-data:www-data -R /srv/www/ ; sudo find /srv/www/tools.example.com/public_html -type d -exec chmod 755 {} \; ; sudo find /srv/www/tools.example.com/public_html -type f -exec chmod 644 {} \; and you're probably good to go. – Stefano Martins Oct 28 '15 at 13:13
  • What do you mean by: Copy these files to your /home/ubuntu directory ? – Rick Sanchez Oct 28 '15 at 13:28
  • Put the files that belong to your website in your home directory, because it's where you do have permissions to write. Then, log in your instance using SSH and then copy them to the directory defined in your Apache's DocumentRoot using sudo. – Stefano Martins Oct 28 '15 at 13:31
  • I get this > thing which I don't know what to write. I'm adding to my main post the outputs. – Rick Sanchez Oct 28 '15 at 13:42
  • Oh.. this is what it's doing. Cant I just grant it an FTP permission like the main websites settings? So i can use WinSCP to upload files to it ? – Rick Sanchez Oct 28 '15 at 13:43
  • You could just add the ubuntu user to the www-data group and grant 775 / 664 permissions, like this: sudo adduser ubuntu www-data ; sudo find /srv/www/tools.example.com/public_html -type d -exec chmod 775 {} \; ; sudo find /srv/www/tools.example.com/public_html -type f -exec chmod 664 {} \; – Stefano Martins Oct 28 '15 at 13:51
  • I think there is something wrong, I have all these directories /srv/www/tools.example.com/public_html/tools.example.com – Rick Sanchez Oct 28 '15 at 13:55
  • and I have this error when running the url: tools.example.com on the browser:

    `Forbidden

    You don't have permission to access / on this server.

    Apache/2.4.7 (Ubuntu) Server at tools.example.com Port 80 `

    – Rick Sanchez Oct 28 '15 at 13:58
  • OK !

    I changed my commands from srv to the var dir. not I dont get the 403 error. but I do get the FTP error again and cant upload files there.

    – Rick Sanchez Oct 28 '15 at 15:34
  • Ok, I understood the processes. Thanks to you I know much more about how ubuntu server works. Thank A LOT! – Rick Sanchez Oct 28 '15 at 15:42
  • Hi Stefano Martins, Can you please review this post and tell me if you think the problem is related? http://serverfault.com/questions/735481/sender-address-rejected-domain-not-found-after-route-53-amazon-aws-changes – Rick Sanchez Nov 11 '15 at 08:34
1

You need two things for your subdomain to work properly.

  1. A DNS Record in a DNS Server. This Records should be created on the name servers that you have set up on your naked domain (yourdomain.tld). If you are already using Amazon Route53 for your naked domain that's fine you can also use it for your subdomain (Amazon Route53 is just a dns hosting service)

  2. A virtual host in a web server.