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.

 


If you liked the post, we should get connected - follow me on Twitter

How to run scripts in Linux faster than Cron does

Cron is an amazing job scheduler. But, when it comes to running your scripts in less than every minute, it can’t help.

With Cron, you can run your scripts every minute, but not in shorter period of time.

This problem can be solved with simple bash script. For example, if you need to run a PHP script on every 20 seconds, you can create a bash script like this:

#!/bin/bash
#Name:myscript.sh
#Desc:Run script in every 20 seconds
while (sleep 20 && php /path_to_your_script/your_script_name.php) &
do
 wait $!
done

Then, make script executable, and add it to the system startup. That’s all.

 

 


If you liked the post, we should get connected - follow me on Twitter