Install owncloud for own server (Simple method)

First create a virtual host, and go to that directory.
Install dependencies:

sudo apt-get install libapache2-mod-php5 php5-gd php5-json php5-mysql php5-curl php5-intl php5-mcrypt php5-imagick

Download and extract owncloud package (Find latest version here:

wget https://download.owncloud.org/community/owncloud-9.1.3.tar.bz2
tar xf owncloud-9.1.3.tar.bz2 && rm owncloud-9.1.3.tar.bz2
cd owncloud
mv * ../
mv .* ../

Now create a new database, a new user for that database and grant privileges for that user on that database. This can be done manually on the mysql command line or via phpmyadmin.

Go to the publicly accessible url and input these settings for a wizard install of owncloud.

If you want an ssl-only access to owncloud, first setup certificates on the server, and after verifying that the https:// url works fine, enter the following at the start of .htaccess file in the root of public web directory:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://cloud.yoursite.com/$1 [R,L]

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Redirecting http to https for subdomains

Learn by reading this example:

#cat .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.droidzone.in$ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://blog.droidzone.in/$1 [R,L]
RewriteCond %{HTTP_HOST} ^supernova.droidzone.in$ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://supernova.droidzone.in/$1 [R,L]
RewriteCond %{HTTP_HOST} ^(.*)droidzone.in$ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://droidzone.in/$1 [R,L]
</IfModule>

[NC] Ignores case.
Consecutive RewriteCond statements have an implicit AND.
The RewriteRule applies to the RewriteCond immediately preceding it. The rest is apparent.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

List directories first in apache2 directory listing

Add the following to .htaccess:

# SET INDEX OPTIONS
Options +Indexes
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Better directory index (.htaccess)

I’ll just list my .htaccess here:

# STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
 order allow,deny
 deny from all
 satisfy all
</Files>
# SET INDEX OPTIONS
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble
AuthUserFile /var/.htpasswd
AuthType Basic
AuthName "My Files"
Require valid-user
Options +Indexes

Reference


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

How to setup Owncloud for your own server

Install owncloud on own server.
First add an apache virtualhost.

Edit

/etc/apache2/sites-available/default

Create the following:

<VirtualHost *:80>
ServerName cloud.relsoft.in
ServerAlias cloud.relsoft.in
DocumentRoot /var/www/virtual/relsoft.in/cloud/htdocs
</VirtualHost>

Create a “A” record in the DNS panel for relsoft.in:

A cloud.relsoft.in [myipaddress]

Create the virtual directory:

mkdir -p /var/www/virtual/relsoft.in/cloud/htdocs
chown -R www-data.www-data /var/www/virtual/relsoft.in

Download and uncompress the latest owncloud installation package [Available at

https://owncloud.org/install/#instructions-server ]
wget https://download.owncloud.org/community/owncloud-8.0.3.tar.bz2
tar xf owncloud-8.0.3.tar.bz2
mv owncloud/* ./
rm owncloud-8.0.3.tar.bz2
rm -rf owncloud/

Install php gd module, php5-curl and php5-mysql:

sudo apt-get install php5-gd php5-curl php5-mysql

Set always_populate_raw_post_data to -1 in your php.ini
Now to set the appropriate value in php.ini, first I have to locate the correct php.ini to edit.

find /etc -iname 'php.ini'

Now locate the location of the setting:

grep -in 'always_populate_raw_post_data' /etc/php5/apache2/php.ini
704:;always_populate_raw_post_data = -1

Edit the correct line with emacs:

emacs /etc/php5/apache2/php.ini
Alt-G G 704

takes me to the correct line to edit. Remove the two leading semicolons.

Restart apache2 server:

service apache2 restart

Now reload cloud.relsoft.in in your browser.

Now I got a security warning:
Your data directory and files are probably accessible from the internet because the .htaccess file does not work.
For information how to properly configure your server, please see the documentation.

This means that htaccess is not enabled for the server. So to setup .htaccess for apache:

Edit /etc/apache2/sites-available/default
emacs /etc/apache2/sites-available/default

Add the “AllowOverride All” directive.
So the block now looks like:

ServerName cloud.relsoft.in
ServerAlias cloud.relsoft.in
DocumentRoot /var/www/virtual/relsoft.in/cloud/htdocs

AllowOverride All


If while editing apache directive files, you face issues, run: systemctl status apache2.service Or journalctl -xn for details

Create database with mysql:
mysql -u root -p
mysql> CREATE DATABASE ‘owncloudie’;
mysql> USE owncloudie;
mysql> CREATE USER ‘cloudsrvrusr’@’localhost’ IDENTIFIED BY ‘mypassword’;
mysql> GRANT ALL PRIVILEGES ON owncloudie.* TO ‘cloudsrvrusr’@’localhost’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Restart apache2, and reload the install page.

Now, add an admin username and password, and add the database details that we created with mysql.
When you click on ‘Finish setup’, mysql installation will be over, and you can login as administrator.
Create users.

Download the Desktop client at https://owncloud.org/install/#install-clients, and the Android client from https://play.google.com/store/apps/details?id=com.owncloud.android

To create ssl:

mkdir -p /etc/apache2/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
emacs /etc/apache2/sites-available/default-ssl.conf
<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin [email protected]
        ServerName cloud.relsoft.in
        ServerAlias www.loud.relsoft.in
        DocumentRoot /var/www/virtual/relsoft.in/cloud/htdocs
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
        BrowserMatch "MSIE [2-6]" \
                        nokeepalive ssl-unclean-shutdown \
                        downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
    </VirtualHost>
</IfModule>
a2ensite default-ssl.conf
service apache2 reload

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Blocking listing of certain file types in apache directory listing with .htaccess

If you’d like to block listing of *.avi files in the directory listing on your server, add the following to the same directory, in a file named .htaccess:

IndexIgnore *avi

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Add hotlink protection for images with .htaccess

Add the following to file .htaccess in your virtual site root:

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://droidozone.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://droidozone.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.droidozone.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.droidozone.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://goodbyeleecher.droidozone.com/ [R,NC]

Here, .jpg, .jpeg, and certain other file formats are checked for hot linking of images. If detected, they are redirected to alternate url, which chides the leecher.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Password protect a directory with .htaccess

I will be password protecting /home/droidozo/public_html/wiki

Create a file .htaccess in the same directory:

[/home/droidozo]# cat /home/droidozo/www/wiki/.htaccess
AuthType Basic
AuthName "moodle"
AuthUserFile "/home/droidozo/.htpasswds/public_html/wiki/passwd"
require valid-user

Here, moodle is the name that appears in the pop up where you are prompted for a password.

Now create the folder structure for the directory containing password, which is not accessible on the server by public.

mkdir -p /home/droidozo/.htpasswds/public_html/wiki

Change to this directory, and:

First create the password file, with one user:

htpasswd -c .htpasswd user1

At this point, you will be asked for a password for user user1. A new password file will be created, containing:

user1:hXdhGMV7lSjUM

The hashed password differs depending on your password.

Create the password file:

cat /home/droidozo/.htpasswds/public_html/wiki/passwd
userme:$apr1$TBkGAByI$5W2J7BJPKRvJyCEVuT53e/

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Redirect one site to another with .htaccess

Add the following to your .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^droidzone\.asia$ [OR]
RewriteCond %{HTTP_HOST} ^www\.droidzone\.asia$
RewriteRule ^(.*)$ "http\:\/\/droidzone\.in\/$1" [R=301,L]

This redirects droidzone.asia to droidzone.com, when residing in the public html folder of droidzone.asia


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

.htaccess not working

Sometimes in case of a new web server installation, you may find that Apache does not use your .htaccess in your Virtual server directory.

This is because of your default server configuration which has to be adapted to load .htaccess directives. You need to edit the file:

/etc/apache2/sites-available/default

 

For example, a virgin server directive may resemble:

[[email protected]] /var/www #cat /etc/apache2/sites-available/default
<VirtualHost *:80>
        ServerAdmin [email protected]

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

You need to modify it by changing the following lines:

 
                Options FollowSymLinks
                AllowOverride None
        [/code]
to:
 
                Options FollowSymLinks
                AllowOverride All
        [/code]
and:
 

                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all[/code]
to:
 

                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all[/code]

Alternately, a single line of sed can achieve this:

sed -i 's/AllowOverride\ None/AllowOverride\ All/g' /etc/apache2/sites-enabled/000-default

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.