# Apache setup & Virtual servers

### Initial setup

Install packages `sudo apt install apache2 mariadb-server libapache2-mod-php php-mysql -y`

Open ports at `cd /etc/apache2/ports.conf` and add the line `Listen NEW_PORT_NUMBER`

### Creating virtual servers

Create a file named NAME.conf and add something like this

```ini
<VirtualHost *:80>
        ServerName pdb.conorbriggs.com.au
        DocumentRoot /mnt/drives/10tb/10tb/web_servers/pdb/

<Directory /mnt/drives/10tb/10tb/web_servers/pdb/>
        Options -Indexes -FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
ErrorLog /var/log/apache2/pdb-error.log
CustomLog /var/log/apache2/pdb-access.log combined

RewriteEngine on
</VirtualHost>
```

Enable the site &amp; restart apache with `sudo a2ensite site.conf && systemctl restart apache2`

<div id="bkmrk-">  
</div>### SSL Certificate management

Install certbot and run setup

```bash
sudo apt install certbot python3-certbot-apache
a2enmod ssl
sudo certbot --apache
```

<div id="bkmrk-list-all-certificate">List all certificates with `certbot certificates`</div><div id="bkmrk--1"></div><div id="bkmrk-delete-a-certificait">Delete a certificaite `certbot delete --cert-name CERT_NAME_HERE`</div><div id="bkmrk--2"></div><div id="bkmrk--3"></div><div id="bkmrk--4"></div>### Managing the apache2 service

Start, stop &amp; restart `sudo service apache2 start/restart/stop`

<div id="bkmrk-enable-a-config%C2%A0sudo">Enable a config `sudo a2ensite SITE_CONF_FILE.conf`</div><div id="bkmrk--5"></div><div id="bkmrk--6"></div><div id="bkmrk-disable-a-config%C2%A0sud">Disable a config `sudo a2dissite SITE_CONF_FILE.conf`</div>