Hosting Your Website on Linux ubuntu server and connect your domain with the ubuntu 21.04 server is very easy to follow the commands and connect your domain with the ubuntu server and host your website on ubuntu 21.04.
sudo mkdir /var/www/your_domain
Next, assign ownership of the directory with the $USER
environment variable, which will reference your current system user:
sudo chown -R $USER:$USER /var/www/your_domain
Then, open a new configuration file in Apache’s sites-available
directory using your preferred command-line editor. Here, we’ll use nano
:
sudo nano /etc/apache2/sites-available/your_domain.conf
Copy
This will create a new blank file. Paste in the following bare-bones configuration:/etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>
ServerName your_domain
ServerAlias www.your_domain
ServerAdmin [email protected]
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file when you’re done.
You can now use a2ensite
to enable the new virtual host:
sudo a2ensite your_domain
Copy
You might want to disable the default website that comes installed with Apache. This is required if you’re not using a custom domain name, because in this case Apache’s default configuration would overwrite your virtual host. To disable Apache’s default website, type:
sudo a2dissite 000-default
Copy
To make sure your configuration file doesn’t contain syntax errors, run:
sudo apache2ctl configtest
Copy
Finally, reload Apache so these changes take effect:
sudo systemctl reload apache2