Apache Configure Domain

In my previous story of Ubuntu installing Laravel, it ended with Apache listening to all IP addresses. Now I am going to configure it to listen to one subdomain only, this way one server can be shared by multiple subdomains.

I have a domain at Cloudflare, I am going to point it to the Laravel blog I setup earlier.

Image for post
Image for post

I had previously backup a copy of the 000-default.conf, rollback to the original with the commands below. I prefer to name my config file with the name of the subdomain for easy searching in future.

cd /etc/apache2/sites-available
sudo mv 000-default.conf laravel.oofnivek.com.conf
sudo mv 000-default.conf.bak 000-default.conf
sudo vim laravel.oofnivek.com.conf

Edit “ServerName” to the subdomain.

Image for post
Image for post

Lastly enable the site and restart Apache.

sudo a2ensite laravel.oofnivek.com
sudo systemctl restart apache2

Browse with subdomain, you’ll see something similar to the screenshot below.

Image for post
Image for post

Browse with IP address you’ll see the Apache Ubuntu default page.

Image for post
Image for post

< Back to all the stories I had written

Written by

A software engineer, a rock climbing, diving & rollerblading enthusiast, a husband, a father.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store