Apache

Dieses Tutorial beschreibt wie der Apache Webserver unter Linux (Ubuntu) eigerichtet wird.

Install

sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5

Start / Stop / Restart

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart

VirtualHost

/etc/apache2/sites-enabled/myhost

<VirtualHost 87.230.85.23:80>
ServerName myhost.de:80
ServerAlias www.myhost.de
DocumentRoot /var/www/myhost
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"" combined
ErrorLog "|/usr/sbin/rotatelogs /var/www/myhost/log/error.log 86400"
CustomLog "|/usr/sbin/rotatelogs /var/www/myhost/log/access.log 86400" combined
</VirtualHost>

/etc/apache2/sites-enabled/myhost

Listen 91
<VirtualHost *:91>
ServerName myhost.de
DocumentRoot /var/www/myhost
</VirtualHost>

Doku >>

HTTPS

/etc/apache2/sites-enabled/myhost

<VirtualHost 87.230.85.23:80>
ServerName myhost.de:80
ServerAlias www.myhost.de
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost 87.230.85.23:443>
ServerName myhost.de:443
ServerAlias www.myhost.de
DocumentRoot /var/www/myhost
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"" combined
ErrorLog "|/usr/sbin/rotatelogs /var/www/myhost/log/error.log 86400"
CustomLog "|/usr/sbin/rotatelogs /var/www/myhost/log/access.log 86400" combined
<IfModule mod_ssl.c>
SSLEngine on
SSLCertificateFile /var/www/certs/myhost.crt
SSLCertificateKeyFile /var/www/certs/myhost.key
</IfModule>
<Directory /var/www/myhost>
AllowOverride AuthConfig
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
</IfModule>
Options -Includes -ExecCGI
</Directory>
</VirtualHost>

openssl genrsa -out /var/www/certs/myhost.key 2048
openssl req -new -x509 -key /var/www/certs/myhost.key -days 365 -sha256 -out /var/www/certs/myhost.crt

Doku >>

Rewrite

/etc/apache2/mods-enabled/rewrite.load

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

/var/www/myhost/admin/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)[-](.*)[-](.*).html$ preview.php?dir=$1&id=$2&lang=$3 [NC,QSA,L]
RewriteRule (.*)[-](.*)[-](.*).php$ preview.php?dir=$1&id=$2&lang=$3 [NC,QSA,L]
</IfModule>

Doku >>

Basic Auth

/var/www/myhost/admin/.htaccess

AuthName "Protected"
AuthType Basic
AuthUserFile /var/www/myhost/admin/.htpasswd
require valid-user

SetEnvIf Request_URI ^/noauth.php noauth
AuthType basic
AuthName "Protected"
AuthUserFile /var/www/myhost/admin/.htpasswd
Order Deny,Allow
Satisfy any
Deny from all
Require valid-user
Allow from env=noauth

htpasswd -c /var/www/myhost/admin/.htpasswd user1

Doku >>

Deflate

/etc/apache2/mods-enabled/deflate.load

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so

/etc/apache2/mods-enabled/deflate.conf

<IfModule mod_deflate>
SetOutputFilter DEFLATE
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

Doku >>

Expire

ln -s /etc/apache2/mods-available/expires.load /etc/apache2/mods-enabled/expires.load

<IfModule mod_expires>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</IfModule>

Doku >>