A little walkthrough to setup a new apache virtual host with an HTTPS certificate on Ubuntu.
sudo apt-get update
sudo apt-get install apache2
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com/public_html
sudo chmod -R 755 /var/www
echo "<h1>Hello world</h1>" > /var/www/example.com/public_html/index.html
You may copy the default file 000-default.conf
to get started
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
Here's an example of the requiredconfig file :
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite example.com.conf
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-apache
sudo ufw allow 'Apache Full'
sudo ufw status
sudo certbot --apache -d example.com -d www.example.com
sudo certbot renew --dry-run
π‘ If your prefer, I have also made a shell script to create new vhost easily, see vhost-setup.sh
. Apache2 and certbot must be installed on your machine before running the script.
bash vhost-setup.sh example.com