Step 1: Create a new directory for your subdomain
mkdir -p /var/www/subdomain.domain.com/public_html
Step 2: Set the correct permissions for the new directory
chown -R www-data:www-data /var/www/subdomain.domain.com/public_html
Step 3: Create a new virtual host configuration file
nano /etc/apache2/sites-available/subdomain.domain.com.conf
Step 4: Edit the virtual host configuration file
<VirtualHost *:80>
ServerName subdomain.domain.com
ServerAlias www.subdomain.domain.com
ServerAdmin admin@domain.com
DocumentRoot /var/www/subdomain.domain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Step 5: Enable the new virtual host
a2ensite subdomain.domain.com.conf
Step 6: Restart the Apache2 serve
service apache2 restart