How to install Apache (with SSL) + WebDav on Ubuntu

Installing Apache with SSL

$ sudo apt-get install apache2 libapache2-mod-auth-mysql

Then, setup and generate a cerfitecate for the web server:

$ sudo openssl genrsa -des3 -out server.key 1024

You’ll be asked to enter a pass phrase.

$ sudo openssl rsa -in server.key -out server.key.insecure

You’ll be asked for the pass parse you used in the previous step.

This command generates the certificate you will be asked to fill in some details:

$ sudo openssl req -new -key server.key -out server.csr
$ sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

The certificate now need coping in to the SSL directory:

$ sudo cp server.crt /etc/ssl/certs
$ sudo cp server.key /etc/ssl/private

Now wee need to enable to SSL site:

$ sudo a2enmod ssl
$ sudo a2ensite default-ssl

The web server needs to be restarted for the change to take place:

$ sudo /etc/init.d/apache2 restart

Now, you should now be able to access the server by typing https://ip_address in your browser.

You’ll get a certificate warning about it not being from a trust source you need to click on more details to check that it is the right computer you are connecting to.

Installing WebDAV

First you need to enable WebDav modules:

$ sudo a2enmod dav_fs
$ sudo a2enmod dav

You need to create a directory to share. For example, it can be in /home/user:

$ mkdir webdav

We need to give the web server and the user access to the WebDav directory:

$sudo chown www-data:user /home/user/webdav

Next we have to setup a password:

$ sudo a2enmod auth_digest

Create a directory where you will store your password files:

$ sudo mkdir /etc/password

Create the password file like this (WebDavCloud is the AuthName, and user1 is actual username for accessing the WebDav):

$ sudo htdigest -c /etc/password/digest-password WebDavCloud user1

You will be asked to type in a password. Select a strong password, you will use it for accessing to your WebDav directory.

Now we need to edit the default-ssl config files:

$ sudo vim /etc/apache2/sites-enabled/default-ssl

You need to find the part of the file that says:

CustomLog /var/log/apache2/ssl_access.log combined

and under that you need to place the following in to the file

Alias /webdav /home/user/webdav
#
<Directory /home/user/webdav/>
 Options Indexes MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
</Directory>
#
<Location /webdav>
 DAV On
 AuthType Digest
 AuthName "WebDavCloud"
 AuthUserFile /etc/password/digest-password
 Require valid-user
</Location>

Now you need to restart the Apache:

$ sudo /etc/init.d/apache2 restart

You should now be able to access the WebDAV folder by going to https://ip_address/webdav

Note: If you would like to map your WebDav directory as a network drive from Windows, it’s most likely that you will have big problems. If you want to use WebDav from Windows, you will need to buy a commercial certificate and use it instead of self-generated certificate.

 


You should really follow me on Twitter :)


Find out how entrepreneurs make money - Join Startupitis

No spam. High quality guaranteed. Unsubscribe anytime.


How to display load average in terminal titlebar

If you’ve managed a number of Linux servers, then you probably know what it’s like to have several terminal windows running top on your desktop.

There is a better way to do this. You can display load average in real time in your terminal titlebar.

Use this script:

#!/usr/bin/perl -w
use strict;
$|++;
my $host=`/bin/hostname`;
chomp $host;
while(1) {
open(LOAD,"/proc/loadavg") || die "Couldn't open /proc/loadavg: $!\n";
my @load=split(/ /,<LOAD>);
close(LOAD);
print "\033]0;";
print "$host: $load[0] $load[1] $load[2] at ", scalar(localtime);
print "\007";
sleep 2;
}

Save this as a script called tl, and copy it to your ~/bin directory.

When you’d like to have titlebar replaced with the name, load average, and current time of the machine you’re logged into, just run tl&

When your job is finished, just do: killall tl before logging out.
Or, if you want to automate this, you can try:

$echo 'killall tl > /dev/null 2>&1' >> ~/.bash_logout

That’s all.

 

 


You should really follow me on Twitter :)


Find out how entrepreneurs make money - Join Startupitis

No spam. High quality guaranteed. Unsubscribe anytime.


How to “cd” into a directory with name like “-test”

If you’ll ever have a situation that you need to enter into a directory with a name like “-test” or any other starting with “-”, this is a post for you.

Solution: You need to use — argument.

So, one way to do this is:

cd -- -test

Other way to do this is to specify the path explicitly:

cd ./-test

Btw, if you would like to delete a directory called like this, you should do next:

rm -r -- -test

You should really follow me on Twitter :)


Find out how entrepreneurs make money - Join Startupitis

No spam. High quality guaranteed. Unsubscribe anytime.


How to make stress your friend

Here is one must-see TED talk by Kelly McGonigal

If you have free 15 minutes today, then spend them on this talk. It’s definitely worth it.

 


You should really follow me on Twitter :)


Find out how entrepreneurs make money - Join Startupitis

No spam. High quality guaranteed. Unsubscribe anytime.


Get MySQL Database Size from Terminal

If you need to find out the size of MySQL databases you use from terminal, the following query will list all the databases with their respective sizes:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024 "size in MB" FROM information_schema.TABLES GROUP BY table_schema;

The result you’ll get will be something like:

| database           | size in MB     |
+--------------------+----------------+
| test1              | 13542.68241349 | 
| test2              |  1522.23837675 | 
| test3              | 26532.27326164 | 
| information_schema |     0.00390626 | 
+--------------------+----------------+
4 rows in set (0.02 sec)

If you have large databases, you can show the result in gigabytes with this query:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024/1024 "size in GB" FROM information_schema.TABLES GROUP BY table_schema;

You should really follow me on Twitter :)


Find out how entrepreneurs make money - Join Startupitis

No spam. High quality guaranteed. Unsubscribe anytime.