Showing posts with label Debian. Show all posts
Showing posts with label Debian. Show all posts

Sunday, 29 June 2014

Debian Screen Resolution when Hyper-V Guest

So I had a need to create a virtual machine on my laptop running Debian Jessie (Testing).   After the installation the screen resolution was limited to 1152x846.   This is a limit within Hyper-V.

I don't know why it took me a number of hours to find the fix for this but I found how to set the resolution on a blog called Random.GetNewEntry().

What is interesting about the fix is that it doesn't involve configuring X Windows. It is a simple change to the GRUB launch command.

I am keeping a copy of the changes needed here for my own reference, but 100 internets go to the owner of the blog.

  1. Edit the grub configuration file, for example:
    sudo vi /etc/default/grub
     
  2. Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT, and add "video=hyperv_fb:1680x1050" (or your custom resolution) in between the quotes. For example: 
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1680x1050"
  3. Save and exit 
  4. Run 
    sudo update-grub
  5. Restart your computer


Friday, 25 October 2013

Installing Harp on Debian Jessie

I recently came across the new open source web server called Harp.
Here is the description from the Harp website;


What is Harp?

Harp is a zero-configuration web server that is used to serve static assets. It has a built in asset pipeline for serving .jade, .markdown, .ejs, .coffee, .less, .styl as .html, .css, and .js. Harp supports a template agnostic layout/partial system and metadata for dynamically building files.


I thought I would take Harp for a drive around the block and decided to install it on a Debian Jessie virtual machine.
The installation process is rather easy except for one issue due to the Node.js package.

Here is the process to install Harp.

Firstly there are some prerequisites to get Harp installed being Node.js and npm, the package manager for Node.   I decided to install Node and npm using the Debian package repositories with these commands.

apt-get update
apt-get install nodejs npm

Once Node is installed, you can install Harp using the Node package manager.

npm install harp -g

The -g switch in the above command tells the package manager to make the Harp install global rather than a local directory install.

Harp is now installed and everything should be ready to go!   There is a problem though.   If you run the following command.

harp --version

You will get an error which is very misleading.

/usr/bin/env: node: No such file or directory

You can be forgiven for thinking that the harp binary was not found.   This is not the case.   The problem here is Harp is trying to call Node.js by using the command 'node' while on a Debian system the Node command is 'nodejs'.

This is easy to fix with the following symbolic link.   Simply run this command.

ln -s /usr/bin/nodejs /usr/bin/node

Now if you run Harp everything works as expected.

harp --version
0.9.4

All that is left is to follow the instructions on getting started to use the Harp web server.


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.



Thursday, 28 March 2013

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


Thursday, 21 March 2013

Installing ownCloud v5.0 on Debian Wheezy using Nginx running on a Raspberry Pi

My last post was about installing ownCloud onto Debian Wheezy using Git. I didn't mention in that post that Debian was running as a Virtual Machine on Windows Server 2012 Hyper-V. This install is working well for me but I wanted to use a Raspberry Pi for the install of ownCloud so I could attach a USB hard disk for storage and use as little power as possible.

I decided to try installing ownCloud with Nginx as the web server because of articles around the web stating that Nginx uses less resources than Apache2.   This being the case it makes Nginx a great candidate for the web server when using a low powered Raspberry Pi as the hardware.

So here is the process I used to achieve my goal.

Firstly we need to get the Raspberry Pi setup with Debian, or as it is called in the Pi world, Raspbian. I didn't need a graphical environment for this setup, so I used a custom version of Raspbian called Raspbian Server Edition.  Raspbian SE was at v2.3 at the time of writing.

We can use the beginners guide to install the Raspberry Pi operating system to an SD card. Just use the Raspbian SE images instead of the full Raspbian image.

Once you have the Raspberry Pi installed and running including a static IP address, SSH server and other standard configurations, you then need to install the required packages;
apt-get -y install nginx php5 php5-fpm php5-cgi php5-gd php5-json php-pear php-xml-parser php5-intl php5-sqlite curl libcurl3 libcurl3-dev php5-curl smbclient cifs-utils mp3info zip git
Just because we have installed so many packages, I feel it is a good time to do a restart and to test the Nginx server is starting after boot. So type the command Reboot and wait for the system to come up.

You can now open a browser and hit the address of your Pi. You should get a warming message as below;


Nginx does not use the /var/www directory by default so lets make that directory and setup security on it;
mkdir /var/www
chmod 774 /var/www
chown www-data:www-data /var/www

Now lets configure the site file for Nginx. Create a new file in the sites-available directory changing the name as desired;
vim /etc/nginx/sites-available/oc.domain.com
Now paste in your web server configuration. Here is the site file I ended up with;

# This is the complete example of nginx configuration file for ownCloud 5
# This config file configures proper rewrite rules for the new release of ownCloud
# Also, this config file configures nginx to listen on both IPv4 and IPv6 addresses
# If you want it to listen to IPv4 address only, use listen 80; instead of listen [::]:80

# First, we configure redirection to HTTPS (substitue owncloud.example.com with the proper address of your OC instance)

server {
  listen 80;
  server_name owncloud.example.com;
  rewrite ^ https://$server_name$request_uri? permanent;
}

# Now comes the main configuration for ownCloud 5

server {
  listen 443 ssl; # Make it listen on port 443 for SSL, on both IPv4 and IPv6 interfaces
  server_name owncloud.example.com;

  root /var/www; # Make sure to insert proper path for your ownCloud root directory

  index index.php;

  # Now we configure SSL certificates. Make sure you enter correct path for your SSL cert files
  ssl_certificate /etc/ssl/localcerts/oc.pem;
  ssl_certificate_key /etc/ssl/localcerts/oc.key;

  client_max_body_size 2G; # This is the first parameter which configures max size of upload, more to come later
  fastcgi_buffers 64 4K;

  # Configure access & error logs
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  # Configure proper error pages
  error_page 403 = /core/templates/403.php;
  error_page 404 = /core/templates/404.php;

  # Some rewrite rules, more to come later
  rewrite ^/caldav((/|$).*)$ /remote.php/caldav$1 last;
  rewrite ^/carddav((/|$).*)$ /remote.php/carddav$1 last;
  rewrite ^/webdav((/|$).*)$ /remote.php/webdav$1 last;

  # Protecting sensitive files from the evil outside world
  location ~ ^/(data|config|\.ht|db_structure.xml|README) {
    deny all;
  }

  # Configure the root location with proper rewrite rule
  location / {
    rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
    rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
    rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
    rewrite ^/apps/calendar/caldav.php /remote.php/caldav/ last;
    rewrite ^/apps/contacts/carddav.php /remote.php/carddav/ last;
    rewrite ^/apps/([^/]*)/(.*\.(css|php))$ /index.php?app=$1&getfile=$2 last;

    rewrite ^(/core/doc[^\/]+/)$ $1/index.html;

    index index.php; # This one might be redundant, but it doesn't hurt to leave it here

    try_files $uri $uri/ index.php;
  }

  # Configure PHP-FPM stuff
  location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
    try_files $script_name = 404;
    fastcgi_pass unix:/var/run/php5-fpm.sock; # Be sure to check proper socket location for php-fpm, might be different on your system
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param HTTPS on;

    # This one is a little bit tricky, you need to pass all parameters in a single line, separating them with newline (\n)
    fastcgi_param PHP_VALUE "upload_max_filesize = 2G \n post_max_size = 2G"; # This finishes the max upload size settings
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # On some systems OC will work without this setting, but it doesn't hurt to leave it here
    include fastcgi_params;
  }

  location ~* ^.+.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
    expires 30d;
    access_log off;
  }

}

Once you have saved the file you will need to make a symbolic link to it in the sites-enabled directory;
rm /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/oc.domain.com /etc/nginx/sites-enabled/oc.domain.com

It's always nice to see some progress being made, so lets make a phpinfo() file and test the web server and php functionality;
echo "<?php phpinfo() ?>" > /var/www/index.php
service nginx restart

Now open a web browser and hit the IP address of your Raspberry Pi. We should see the standard PHP information being displayed.



As with my last post, we need to add the US UTF-8 locale.   I will keep this post short.   See the ownCloud installation process from my last post.

Here are the references I used for this install;
http://rasberrypibeginnersguide.tumblr.com/post/27283563130/nginx-php5-on-raspberry-pi-debian-wheezy
http://blog.martinfjordvald.com/2010/07/nginx-primer/
http://www.webhostingtalk.com/showthread.php?t=1025286


Wednesday, 27 February 2013

Installing ownCloud on Debian GNU/Linux using Git

I have been watching an open source project for a while now with great interest.   The name of the project is ownCloud and it is a file synchronising server with a web interface that operates much the same as Dropbox, SkyDrive, iCloud and other cloud based storage solutions.
  
Now that ownCloud is feature rich and has a client for Android, iOS, Windows and OS X, I wanted to install it to move my cloud storage away from Dropbox and onto my own server. By doing this I will have control of my data without the need to pay for space and more flexibility as to how I access my data.

I am a fan of the GNU/Linux distribution called Debian so I installed a virtual machine running Debian Wheezy release candidate to host ownCloud. You can install ownCloud on Windows Server if you wish. The stable version of ownCloud on their website is at v4.5 which has issues using external storage on a Windows shared folder, so I needed to install the latest beta version.

To get the latest version of ownCloud I needed to install using the Git repository from GitHub. At the time of writing this article the ownCloud version on GitHub is at v5.0 beta 2.

To start off with I needed to install the prerequisites on Debian with this command;
apt-get -y install apache2 php5 php5-gd php5-json php-pear php-xml-parser php5-intl php5-sqlite curl libcurl3 libcurl3-dev php5-curl smbclient cifs-utils mp3info zip git

At this point, I changed the php.ini file to increase the upload_max_filesize value from the default 2M to 1024M;
vim /etc/php5/apache2/php.ini

I decided to install ownCloud into the root of the apache2 www folder;
cd /var/www

I removed the original apache2 index file;
rm index.html

To get the latest ownCloud version I needed to use Git to clone the core, 3rdparty and apps repositories into the root of the web server.   Note that the apps clone needs to be cloned into a new target apps2 directory to prevent conflicts with the core repositories apps folder. I will need to edit the config.php file later to include the apps2 folder, but it does not exist yet;
git clone https://github.com/owncloud/core ./
git clone https://github.com/owncloud/3rdparty
git clone https://github.com/owncloud/apps apps2

Now I need to give ownership of the ownCloud directories to www-data with;
chown -R www-data:www-data ./*
chown -R www-data:www-data /var/www

To improve the security of ownCloud I needed to enable .htaccess in the virtual host file;
vim /etc/apache2/sites-enabled/000-default

Now change the /var/www directory element so AllowOverride is set to 'All' as in this example;
<directory var="" www="">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</directory>


I found when I first tested this install approach the Admin page reported a locale issue so I needed to install the en_US.UTF-8 locale for the system to work correctly with file names. My default locale is en_AU.UTF8. To install the US UTF8 locale run this command;
dpkg-reconfigure locales

Then select the US UTF-8 locale.
Check the installed locales with;
locale -a

Lastly enable the following modules and restart apache2;
a2enmod rewrite
a2enmod headers
service apache2 restart

I can now open a web browser and access my ownCloud instance (http://ServersIPAddress/) but there is an expected error.   When I first connect to ownCloud like this it will create a config.php file.


Now that I have an ownCloud config file I need to edit it to support the apps2 directory. If you read on the apps repository page here https://github.com/owncloud/apps (near the bottom) it states the need for this change. When you edit the config.php file using the instructions from the link above it states to leave the apps and apps2 directory as writable = false. This failed on my install and I needed to change writable to true on the apps2 directory for user downloaded apps;
vim /var/www/config/config.php

Here is my complete config.php file;
<?php
$CONFIG = array (
  'instanceid' => '512efd12eb6d8',
  'passwordsalt' => '5555c4f3a4fbeb1a527d376095555',
  'datadirectory' => '/var/www/data',
  'dbtype' => 'sqlite3',
  'version' => '4.94.10',
  'installed' => true,
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/apps2',
      'url' => '/apps2',
      'writable' => true,
    ),
  ),
);


I can now connect to my new ownCloud server and run through the setup wizard to create the SQLite database and admin user.

I now have a working cloud storage solution!

To update to the latest Git version I will need to run these commands;
cd /var/www
git pull
cd /var/www/3rdparty
git pull
cd /var/www/apps2
git pull

There is more to do such as enabling SSL and mapping to my external shared folder running on Windows but that is another story.

Here are the references I used to complete this task;
https://github.com/owncloud   (ownCloud github site)
http://doc.owncloud.org/server/5.0/admin_manual/installation.html   (v5.0 installation documents)
http://forum.owncloud.org/viewtopic.php?f=17&t=8012   (fixing the US UTF-8 issue)

To use port SSL use this reference to enable it on Apache2 with Debian;
http://wiki.debian.org/Self-Signed_Certificate