Short guide to set up an apache virtual host on ubuntu 14.04

Knowing, that there are very good and detailed guides for virtual host creation, i decided to have a shortest possible how to on this topic here.
Assuming, that you have installed and running your apache in Ubuntu 14.04 Trusty Tahr, then these are the steps to create a new virtual host:

  • assure, that the directory, where your virtual host should to “live” in, exists (e.g. “/var/www/awesome.local”)
  • assure, that the permissions of your document root are set to 755
  • create an apache virtual host configuration file (copy the default config file)
    • sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/awesome.local
    • fill it with your configuration (with the editor of your choice)
  • <VirtualHost *:80>
        ServerAdmin admin@awesome.local
        ServerName awesome.local
        ServerAlias www.awesome.local
        DocumentRoot /var/www/awesome.local
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
  • enable the virtual host configuration:
    sudo a2ensite awesome.local
  • restart apache:
    sudo service apache2 restart
  • set up your local /etc/hosts:
    • open the file “etc/hosts”
    • add the line
      127.0.0.1 awesome.local www.awesome.local
  • open http://awesome.local and/or http://www.awesome.local in your browser and check, if everything went well (if you see an empty page, check, that there is something in your document root ;))

Little GREPpings

Sometimes it is great to have the little help of grep. I’m often asked for some hints, so here are my favorite tiny commands:

grep -lir 'PATTERN' *

where the l stands for “give me only the file names”, i for “case insensitive”, r for recursive and the asterisk for all files (use *.xml or other wildcards to only search in certain files).

grep -lir 'PATTERN' * | grep -v "svn"

to search all files, except the svn files (hopefully there is no other filename with svn in it 😉 ). The | is the pipe operator.

I hope that they are useful and help you to grep around!

SME Server – Dansguardian installation script

I wrote a script to install a Dansguardian filter on a SME Server 7.5:
here it is!

Download it by typing

wget http://www.sebastianbauer.name/files/servers/sme/sme_dansguardian_setup.sh

to your server shell as root.

Then make it executable by

chmod +x sme_dansguardian_setup.sh

and run it by

./sme_dansguardian_setup.sh

… thats it ;)!

If you have any hints, critiques or improvements, let me know it and write a comment or an email!

Security script: ubuntu server automatic check of services

Looking at this post on about perl i got the idea to write my own script to check if all services are running.

Here it is:
check_services.py

There are only a few things you have to do:

  • change the path to the script in the script (necessary cause we use cron)
  • put it in your crontab:
    • “crontab -e” as root
    • set your local PATH variable (look it up in the shell with “echo $PATH”)
    • * * * * * /PATH_TO_YOUR_SCRIPT/check_services.py
  • think about how you observe the logfile (maybe you want an email or a notification at login)

If you like the script, see any points i missed or have problems: let me know it and write a comment!

MySQL database backup script

Using the scripts

In another post i wrote two scripts which allow you comfortable to save and restore your disk under ubuntu (other linux probably will work too 😉 ). Now i give you similar scripts for your MySQL databases. I use the plain scripts from the WordPress Backups page and use python 3.1 again for shortness and readability of code.

Again the warning:
Don’t use them mindless, you could damage all your recent work or worse! I don’t take responsibility for the effects of this scripts, you use them on your own response!

You have to give the “db2file.py” a string with a description like this:

./db2file.py 'before installing the newest updates'

and it will create a packed file called:

001__17_5_2011__before_installing_the_newest_updates.bak.sql.bz2

with an automatic incremented number and the date.

To decompress the file use:

./file2db.py 001__17_5_2011__before_installing_the_newest_updates.bak.sql.bz2

You can define another database name and user by the -u and -d options, here are the help outputs:

Usage: db2file.py description_string

Options:
  -h, --help            show this help message and exit
  -u USER, --user=USER  database user name
  -d DATABASE, --database=DATABASE
                        database name
Usage: file2db.py filename

Options:
  -h, --help            show this help message and exit
  -u USER, --user=USER  database user name
  -d DATABASE, --database=DATABASE
                        database name

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Download

You can download them here:
db2file.py
file2db.py

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Ubuntu backup scripts

[toc]

Using the scripts

There are many backup scripts out there for linux. I wrote two on base of a tar with bzip2 and nice (giving you the ability to use your box while [de]compressing by setting the priority of the backups to “lowest”) in python 3.1.

Don’t use them mindless, you could damage all your recent work or worse! I don’t take responsibility for the effects of this scripts, you use them on your own response!

You have to give the “disk2file.py” a string with a description like this:

./disk2file.py 'before installing the newest updates'

and it will create a packed file called:

001__16_5_2011__before_installing_the_newest_updates.tar.bz2

with an automatic incremented number and the date.

To decompress the file use:

./file2disk.py 001__16_5_2011__before_installing_the_newest_updates.tar.bz2

You can define another directory to compress and decompress and a comma separated list of directories to exclude, here are the help outputs:

Usage: disk2file.py description_string

Options:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory=DIRECTORY
                        directory which will be saved (default='/')
  -e EXCLUDE, --exclude=EXCLUDE
                        directories to exclude (separated by comma,
                        default='['/proc', '/lost+found', '/media', '/mnt',
                        '
/sys', '/var/backup*']')
Usage: file2disk.py filename

Options:
  -h, --help            show this help message and exit
  -d DIRECTORY, --directory=DIRECTORY
                        directory where the backup will be copied
                        (default='/')

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.

Download

You can download them here:
disk2file.py
file2disk.py

If you have ideas or hints on the scripts or even find them usefull, let me know it and write a comment.