Tuesday, 28 May 2013

Installing AjaXplorer with Nginx on Debian

Over the past few months I have been looking into private cloud storage.   I have been using Dropbox for a long time now but am unhappy with the use of a third party for file storage.   That said, Dropbox is an awesome product and I will still use it for some functions in the future.   After much research I think I may have found a solution for private cloud storage that is best suited to my needs.

I will write another post about the different solutions I have found and tested but for now I am installing AjaXplorer.   This product is open source, installable on your own hardware and gives you access to your already existing file server with minor configuration.

Following are the instructions for installing AjaXplorer with Nginx on Debian Wheezy.   The hardware I am using is a Raspberry Pi with a 4TB Western Digital USB hard drive attached.   Because the Raspberry Pi is a low powered device I am using Nginx as the web server with PHP-FPM for processing php.

Assumptions
  • You already have Debian 7.0 (Wheezy) running.
  • You can download the AjaXplorer compressed file to your Debian server.

To start off with we need to install the prerequisite packages.   I am keen to keep my Raspberry Pi lean and so I did some testing to determine the minimum required packages needed to get the full functionality of AjaXplorer.   Note I am not including the requirements for the AjaXplorer desktop client yet because it is in beta and I am not interested in testing it.   If you wish to use the desktop client you will need some rsync php related packages.   So here is the command to install the prerequisites;

apt-get install nginx php5 php5-fpm php5-gd php5-cli php5-mcrypt

Once the prerequisites are installed, create the www directory and set ownership;

mkdir /var/www
chown www-data:www-data /var/www

We need to configure php to support larger file uploads so edit the php.ini file;

vim /etc/php5/fpm/php.ini

Edit the following values to your liking;

file_uploads = On
post_max_size = 20G
upload_max_filesize = 20G
max_file_uploads = 20000

Now we need to configure Nginx to setup our AjaXplorer web site (use your own domain name below);

vim /etc/nginx/sites-available/x.yourdomain.com

Here is the x.yourdomain.com config file I am using. Make sure you change the max_body_size value and replace x.yourdomain.com with your servers DNS name;

server {                                                                                 
  listen 80;
  server_name x.yourdomain.com;
  root /var/www;
  index index.php;
  client_max_body_size 20G;
  access_log /var/log/nginx/x.yourdomain.com.access.log;
  error_log /var/log/nginx/x.yourdomain.com.error.log;

  location / {
  }

  location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    expires max;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  }

  include drop.conf;
  include php.conf;
}

Take note of the two include statements at the bottom of the Nginx site file.   You will need to make these files also;

vim /etc/nginx/drop.conf

And here is my drop.conf contents;

location ^~ /conf/       { deny all; }
location ^~ /data/       { deny all; }
location = /robots.txt  { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
location ~ /\.          { access_log off; log_not_found off; deny all; }
location ~ ~$           { access_log off; log_not_found off; deny all; }

Note the first two deny all statements above are specific to AjaXplorer.
Now create the php.conf file;

vim /etc/nginx/php.conf

Here is my php.conf contents;

location ~ \.php {                                                                       
  try_files $uri =404;
  fastcgi_param  QUERY_STRING       $query_string;
  fastcgi_param  REQUEST_METHOD     $request_method;
  fastcgi_param  CONTENT_TYPE       $content_type;
  fastcgi_param  CONTENT_LENGTH     $content_length;
  fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  fastcgi_param  SCRIPT_FILENAME    $request_filename;
  fastcgi_param  REQUEST_URI        $request_uri;
  fastcgi_param  DOCUMENT_URI       $document_uri;
  fastcgi_param  DOCUMENT_ROOT      $document_root;
  fastcgi_param  SERVER_PROTOCOL    $server_protocol;
  fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  fastcgi_param  SERVER_SOFTWARE    nginx;
  fastcgi_param  REMOTE_ADDR        $remote_addr;
  fastcgi_param  REMOTE_PORT        $remote_port;
  fastcgi_param  SERVER_ADDR        $server_addr;
  fastcgi_param  SERVER_PORT        $server_port;
  fastcgi_param  SERVER_NAME        $server_name;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
}

The last statement in the above file is the mapping between Nginx and PHP5-FPM.

Now that all the Nginx files are created we can enable the site by deleting the default Nginx site and linking to the new site;

cd /etc/nginx/sites-enabled
rm default
ln -s ../sites-available/x.yourdomain.com

Time to get the AjaXplorer files. Download the latest version and save it to your /var/www directory. Extract the downloaded file to the root of the www directory;

cd /var/www
tar -xzf <gz file name here>
ls -l
mv <extracted directory name>/* /var/www
rm -R /var/www/<extracted directory name>
chown -R www-data:www-data /var/www

Prior to opening a browser and seeing the result we need to restart the required services to pick up the new config files;

service php5-fpm restart
service nginx restart

Now open a browser and hit your IP address or DNS name.   The first time you access AjaXplorer you will see a diagnostics page that will look like this.


You will need to fix any issues discovered by the Diagnostics program before continuing. You will notice the warning about SSL Encryption.   I am accessing my server using Pound as a reverse proxy to encrypt the pages using SSL.

Once you have fixed any errors reported by the Diagnostics page click on the link under the title to continue to the AjaXplorer main interface. You will need to log in with a username of admin and a password of admin for the first access.   Make sure you change the password at some point.

The last required configuration for the installation is to adjust the AjaXplorer upload file size limit. This is achieved under settings;


That's it.   AjaXplorer is now installed and waiting for you to configure repositories and other customizations.  There are plugins available and client applications.   I am using the Android client successfully and will look at the Desktop client once it is out of beta.

The Raspberry Pi is an amazing platform for free open tools like this and I am now using a low powered Pi with a USB disk as my home file server cutting my electricity bill and reducing my carbon foot print.



Monday, 29 April 2013

Remotely Connect to Hyper-V with Hyper-V Manager

On Windows 8 or Windows Server 2012 you can install the Hyper-V Management Console and use it to connect to a server or client running Hyper-V Services.

Microsoft has the basic configurations covered at this address;
http://technet.microsoft.com/en-us/library/jj647788.aspx

There is a rather important detail missing though. To connect to the Hyper-V Service running on a different machine, you need to run the Hyper-V Manager using a local account.

Now if you are like me you are thinking to yourself "I am using my local account!" Well you may not be. If you chose to use a Microsoft account when you installed Windows 8, then you are not using a local account.

So make sure you have a local administrative account on both the Hyper-V Server and the Remote Management machine.   Hold down the Shift key and right click the Hyper-V Manager link and select to "Run as different user" and use your local account.

Have a read through the community comments on the bottom of the Technet page for more details.


Wednesday, 24 April 2013

Export Hyper-V Virtual Machine to a File Share in a Workgroup

I have a number of Windows Server 2012 Hyper-V hosts that are not members of a Domain.
To export the Virtual Machines to a File Server we need to authenticate the System service account to the File Server before the Hyper-V Management Service can access the shares. I found this neat trick on Microsoft's Technet Forum which worked wonderfully using PSExec;


1. Open an elevated command prompt: Click start, type CMD, and press Ctrl+Shift+Enter, then accept the UAC dialog (if applicable).

2. Run:
 psexec.exe \\<localServerName> /s cmd.exe
 This will provide you with a new command prompt, but it will instead run under the SYSTEM context, instead of your user context.

3. Run:
 net use \\<remoteServerName>\<sharename> /user:<domain>\<userName> <password>
 This authenticates the SYSTEM account to the share you want to export to.  
 As an example, the line could look like: "net use \\server2\c$ /user:mydomain\Administrator MyAw3s0m3Pwd"

4. Return to the Hyper-V MMC, and try your export again.  It should work now.

5. When you're done, use:
 net use \\<remoteServerName>\<sharename> /delete
 This revokes the credentials from the SYSTEM account.  Alternatively, you could reboot.

6. Type exit, press enter.  You've dropped back to the original command prompt.  Type exit and press enter again, or simply close the window.



This is not a process you would want to perform for a nightly backup, but as a once off it does the trick.



Vim

I have been using Linux for a number of years now and right from the start have been using Vim.
It is an elite text editor with a number of inside jokes about it.   Love it or hate it, a skilled Vim operator will out perform any peers on other text editors.   I am not excluding Vi comparable text editors here.

That being said, I am not an expert and this blog post is a repository of commands I am learning and have learned.   I plan on using this page to remind myself of the rarely used commands.   This page will be updated often.

So hear are the commands I am learning or know so far;

%s/foo/bar/g     [Find and Replace foo with bar]
V then =         [Reformat Selection]
n      [After Search Find Next]
v      [Visual Mode]
V      [Visual Mode Line Select]
gg=G   [Re-indent Entire Document]
p      [Put or Paste Buffer]
y      [Yank or Copy Selected]
dd     [Delete the Current Line]
3dd    [Delete Three Lines]
u      [Undo]

Just for reference, here is my vimrc config file;

" Debian Statement
runtime! debian.vim

" Set Syntax and FileType
syntax on
filetype on
filetype indent on
filetype plugin on

" Set Omni completion filetype associations
set ofu=syntaxcomplete#Complete
autocmd FileType html :set omnifunc=htmlcomplete#CompleteTags
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete


" Set Search Format
set incsearch
set ignorecase
set smartcase

" Set Tab Style
set expandtab
set shiftwidth=2
set tabstop=2
set softtabstop=2
set smartindent
set autoindent
set wildmode=longest:full
set wildmenu

" Set Visual Style
set cursorline
hi CursorLine term=none cterm=none ctermbg=3

" Key Maps - Insert Mode
imap ii <C-[>

" Set Environment Values
set nocompatible
set showcmd
set showmatch
set ignorecase
set smartcase
set incsearch
set autowrite
set hidden
set viminfo='100,<100,s10,h

" Enable Terminal Colour Support
if &term =~ "xterm"
set t_Co=256
if has("terminfo")
   let &t_Sf=nr2char(27).'[3%p1%dm'
   let &t_Sb=nr2char(27).'[4%p1%dm'
else
   let &t_Sf=nr2char(27).'[3%dm'
   let &t_Sb=nr2char(27).'[4%dm'
endif
endif



Thursday, 28 March 2013

SharePoint 2013 Site Closure

I am working on SharePoint Server 2013 and just learnt about Site Closure or Closing a Site. What a great addition to the site management. This new feature allows an administrator to define a Site Policy to close or delete sites on a schedule.

To configure Site Closure you first have to make a Site Policy in the top level site settings under Site Collection Administration.


In the Site Policies page you can click create to make a Site Policy. When you create a Site Policy you have these options available to you.

The first radio button selection, "Do not close or delete site automatically", is purely so you can have the Site Collection be read only when it is closed.
If you select the second radio button "Delete sites automatically" you get more options.

As you can see, the site can be deleted automatically on a schedule based on either the Site closed date, or the Site created date.
If you choose the last radio button, "Close and delete sites automatically", you get one more schedule option available to you.

Now the site can be closed on schedule and deleted on schedule.

Once one or more Site Policies have been created you apply the policies to the existing sites using the Site Closure and Deletion link on the Site Settings page under Site Administration.

On the Site Closure and Deletion page you can close the site based on the policy you select at the bottom of the page.   To delete the site manually you need to go back to Site Setting and click Delete This Site under Site Actions.


So as you can see, it is a simple feature but enables the SharePoint administrators far greater control over removal of sites in a typical user site creation scenario.

In addition to the above Site Policy settings, you can enable Self-Service Site Creation forcing users to select a Site Policy to apply to their site. Finally we have the ability to clean the unused sites out of SharePoint without a delete only option as in the past.



Installing Ruby on Rails using Debian Wheezy

So I am setting up a website for a community band and wanted to try out using Ruby on Rails. The installation of Ruby with Rails is not as easy as I would have thought. After some trial and error here is the smoothest way to get Rails up and running on Debian Wheezy RC.

Firstly get Debian fully updated and edit the apt.config and sources.list files to add support for unstable packages. We need this to install a javascript engine. See my last post for details of this step.

The next thing to do is install all the required packages to get Rugy working.
apt-get -y install ruby ruby-dev rubygems sqlite3 libsqlite3-dev git
Rails will need a javascript engine so install node.js from the unstable repository with this command. Note that once node.js is available in the Testing or Stable package repositories you will not need to tell apt to install from Unstable.
apt-get -y -t unstable install nodejs
Now we can install Rails using Ruby Gems.
gem install rails
[Edit]
As an option, you could install Rails using apt.
apt-get install ruby-rails-3.2
That's it. If you want to use other Ruby frameworks you can install them also. In this case I am going to give RefineryCMS a shot.



Tuesday, 26 March 2013

Installing Unstable Packages on Debian Testing

If you want to install unstable packages onto a Debain Testing installation you will need make the following changes to Apt.

Firstly edit or create the /etc/apt/apt.conf file and add this line;
vim /etc/apt/apt.conf
APT::Default-Release "testing";

Now we need to add the unstable repositories to the sources.list file.
vim /etc/apt/sources.list

Here is the sources.list file I am using at the time of writing.
# Testing Repository
deb http://ftp.au.debian.org/debian testing main contrib non-free
deb-src http://ftp.au.debian.org/debian testing main contrib non-free

deb http://ftp.debian.org/debian/ testing-updates main contrib non-free
deb-src http://ftp.debian.org/debian/ testing-updates main contrib non-free

deb http://security.debian.org/ testing/updates main contrib non-free
deb-src http://security.debian.org/ testing/updates main contrib non-free

# Unstable Repository
deb http://ftp.au.debian.org/debian unstable main contrib non-free
deb-src http://ftp.au.debian.org/debian unstable main contrib non-free

Lastly update the repositories.
apt-get update
Now if you want to install a package from the unstable distribution of Debian use the apt-get command with a couple of extra parameters   This example is installing nodejs from unstable.
apt-get -t unstable install nodejs