Hoe installeer ik Apache versie 2.4.54 met UFW, HTTPS en HTTP2?
Met onderstaande handleiding krijg je versie 2.4.54
sudo apt update
sudo apt upgrade
HTTP2:
sudo apt install php7.4-fpm
sudo a2enmod proxy_fcgi setenvif
sudo systemctl restart apache2
sudo a2enconf php7.4-fpm
sudo systemctl restart apache2
sudo a2dismod php7.4
sudo systemctl restart apache2
sudo a2dismod mpm_prefork
--let-op-nu-geen-restart--
sudo a2enmod mpm_event
sudo systemctl restart apache2
sudo service php7.4-fpm restart
sudo a2enmod http2
sudo systemctl restart apache2
sudo a2enmod headers
sudo systemctl restart apache2
sudo apt-get install libapache2-mod-security2
sudo systemctl restart apache2
FIREWALL:
sudo ufw app list
sudo ufw allow 'Apache Full'
sudo ufw status
sudo ufw enable
sudo systemctl status apache2
sudo systemctl restart apache2
sudo apachectl -t
HTTPS:
sudo apt update
sudo apt install python3-certbot-apache
sudo certbot --rsa-key-size 4096 --no-redirect --must-staple --staple-ocsp -d computerbas.nl -d www.computerbas.nl
Als je een subdomein hebt op een ander ip doe je dit op de server van het subdomein:
sudo certbot --rsa-key-size 4096 --no-redirect --must-staple --staple-ocsp -d sub.domeinnaam.nl
Zo zien mijn DNS records eruit:
Naam: @
TTL: 1 day
Type: A
Waarde: mijn.ip.adres.hier
Naam: @
TTL: 5 min
Type: CAA
Waarde: 0 issue "letsencrypt.org"
Naam: www
TTL: 1 day
Type: A
Waarde: mijn.ip.adres.hier
Zo zien mijn VirtualHost files eruit:
De HTTP versie:
<VirtualHost computerbas.nl:80>
Redirect permanent "/" "https://computerbas.nl"
</VirtualHost>
<VirtualHost www.computerbas.nl:80>
Redirect permanent "/" "https://www.computerbas.nl"
</VirtualHost>
En de HTTPS versie:
<IfModule mod_ssl.c>
SSLStaplingCache shmcb:/var/run/apache2/stapling_cache(128000)
<VirtualHost computer.nl:443>
ServerName computerbas.nl
DocumentRoot /var/www/html
#Altijd WWW
Redirect permanent / https://www.computerbas.nl
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLUseStapling on
Protocols h2 http/1.1
SSLCertificateFile /etc/letsencrypt/live/computerbas.nl/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/computerbas.nl/privkey.pem
</VirtualHost>
<VirtualHost www.computer.nl:443>
ServerName www.computerbas.nl
ServerAlias computerbas.nl
DocumentRoot /var/www/html
#Omdat ik nog iets wijzig via de .htaccess file voeg ik deze regels toe:
<Directory /var/www/html>
DirectoryIndex index.php
AddType application/x-httpd-php .php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLUseStapling on
Protocols h2 http/1.1
SSLCertificateFile /etc/letsencrypt/live/computerbas.nl/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/computerbas.nl/privkey.pem
</VirtualHost>
</IfModule>
Zo ziet mijn .htaccess file eruit:
.htaccess:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##
RewriteEngine On
# remove //
RewriteCond %{THE_REQUEST} //
RewriteRule ^(.*)$ /$1 [R=301,NC,L]
# remove /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,NC,L]
# remove .php extern
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [R=301,NC,L]
# map it back to .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [R=301,NC,L]
#dit zijn aangepaste meldingen voor errors:
ErrorDocument 404 /404.php

Laatst gewijzigd op 10/11/2022