Skip to content

Instantly share code, notes, and snippets.

@wwwqr-000
Last active July 1, 2025 16:15
Show Gist options
  • Select an option

  • Save wwwqr-000/ec5985c6033c1d18d1ac72eca491e490 to your computer and use it in GitHub Desktop.

Select an option

Save wwwqr-000/ec5985c6033c1d18d1ac72eca491e490 to your computer and use it in GitHub Desktop.
apache2 virtual host
sudo -s
apt-get update
apt-get install apache2
cd /etc/apache2/sites-available
nano a_new_website.conf
#begin of file
<VirtualHost *:8080>
ServerAdmin admin@example.com
#Domainname without protocol
ServerName example.com
DocumentRoot /additional_website/public
<Directory /additional_website/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /additional_website/logs/error.log
CustomLog /additional_website/logs/access.log combined
</VirtualHost>
#end of file
a2ensite a_new_website.conf
nano /etc/apache2/ports.conf
#Add the port in this file, in this case, add this line:
Listen: 8080
systemctl restart apache2
If you want to enable HTTPS for your website, you can folow these steps:
sudo -s
apt-get update
apt-get install snapd
snap install core
snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
#The command below uses the domainname, just enter it's name here without http or https or slashes.
certbot certonly --standalone -d example.com
#Remember the location of the created files.
#Now you can create a new .conf in /etc/apache2/sites-available or edit an existing one
nano /etc/apache2/sites-available/my-website.conf
#Now paste the following config setup in the file, and change it to your use-case.
#Begin file
<VirtualHost *:443>
#The domain name you used for certbot
ServerName example.com
#Https
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
#
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
#
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>
#End file
mkdir /var/www/example.com /var/www/example.com/public
echo Welcome! > /var/www/example.com/public/index.html
nano /etc/apache2/ports.conf
#Add the following line in the file
Listen 443
#
a2ensite my-website
systemctl restart apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment