Ubuntu server 12.04/apache2
From Attie's Wiki
apt-get install apache2 libapache2-mod-php5 # enable modrewrite ln -s ../mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
Contents |
Configuring an Apache server
Configuration is in /etc/apache2
Initial Setup
echo <<EOF >>/etc/apache2/mods-available/cgi.load AddHandler cgi-script .cgi EOF echo <<EOF >/etc/apache2/mods-available/proxy.conf <IfModule mod_proxy.c> ProxyVia On ProxyRequests On <Proxy *> Order deny,allow Deny from all Allow from 127.0.0.1 Allow from .attie.co.uk </Proxy> </IfModule> EOF echo <<EOF >>/etc/apache2/conf.d/security # prevent access to sensitive files RedirectMatch 404 /\\.svn(/|$) RedirectMatch 404 /\\.git(/|$) RedirectMatch 404 /\\.ht EOF ln -sf ../mods-available/proxy.load /etc/apache2/mods-enabled/proxy.load ln -sf ../mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf ln -sf ../mods-available/proxy_http.load /etc/apache2/mods-enabled/proxy_http.load ln -sf ../mods-available/proxy_ftp.load /etc/apache2/mods-enabled/proxy_ftp.load ln -sf ../mods-available/proxy_ftp.conf /etc/apache2/mods-enabled/proxy_ftp.conf ln -sf ../mods-available/proxy_connect.load /etc/apache2/mods-enabled/proxy_connect.load
Site Configuration
Store site content in /home/www
mkdir /home/www chown www-data:www-data -R /home/www
Path goes with TLD first, and a few other rules. Access and Error logs are stored in the TLD's directory, with the subdomain prefixed. E.g:
Domain / Subdomain | Root Dir | |
---|---|---|
www.attie.co.uk |
→ | /home/www/attie.co.uk/htdocs
|
wiki.attie.co.uk |
→ | /home/www/attie.co.uk/wiki
|
joke.test.attie.co.uk |
→ | /home/www/attie.co.uk/test.joke
|
As the default configuration will deny access to .ht*
, we can use .htinfo
to store the configuration and logs.
Content | ${ROOTDIR}/
|
Config | ${ROOTDIR}/.htinfo/config
|
Access Log | ${ROOTDIR}/.htinfo/access.log
|
Error Log | ${ROOTDIR}/.htinfo/error.log
|
Start/Restart
service apache2 restart
Setup sites
Add a site file in /etc/apache2/sites-available
.
Enable the site by symlinking it into /etc/apache2/sites-enabled
.
If there is a reason to load one site before another, then use a prefix other than 50.
ln -s /home/www/attie.co.uk/htdocs/.htinfo/config /etc/apache2/sites-enabled/50-www.attie.co.uk
Sample config
<VirtualHost *:80> ServerAdmin webmaster@attie.co.uk ServerName attie.co.uk ServerAlias www.attie.co.uk DocumentRoot "/home/www/attie.co.uk/htdocs" CustomLog "/home/www/attie.co.uk/htdocs/.htinfo/access.log" combined ErrorLog "/home/www/attie.co.uk/htdocs/.htinfo/error.log" </VirtualHost>