Posted on 30th Jan 2025
To set up a local subdomain on Ubuntu server / desktop with Apache2, follow these steps:
Edit the /etc/hosts
file:
Add the subdomain to the /etc/hosts
file by running the following command:
sudo nano /etc/hosts
Add the following lines at the end of the file:
127.0.0.1 autonetix.yourdomain.local
Replace autonetix
with your desired subdomain name and yourdomain.local
with your local domain name.
Create a new Apache virtual host:
sudo mkdir /var/www/autonetix.yourdomain.local
/etc/apache2/sites-available
directory:sudo nano /etc/apache2/sites-available/autonetix.yourdomain.local.conf
<VirtualHost *:80>
ServerAdmin [your_email@example.com](mailto:your_email@example.com)
ServerName autonetix.yourdomain.local
DocumentRoot /var/www/autonetix.yourdomain.local
VirtualHost>
Replace your_email@example.com
with your email address and /var/www/autonetix.yourdomain.local
with the directory containing your subdomain's files.
Enable the new virtual host: Enable the new configuration by running:
sudo a2ensite autonetix.yourdomain.local
sudo service apache2 restart
http://autonetix.yourdomain.local
. If everything is set up correctly, you should see your subdomain's files.Remember to replace yourdomain.local
with your actual local domain name and autonetix
with your desired subdomain name throughout the process.