Zhixian's Tech Blog

2014-12-30

How to install Mono on Ubuntu (Part 2 of 2)

Filed under: development — Tags: , , , , , — Zhixian @ 00:06:12 am

This is continuation of my previous blog post How to install Mono on Ubuntu.
This part focus on testing the installation to make sure that you have the minimal to compile C# source code and to run ASP.NET web applications.

Assumptions

  1. You have installed Apache HTTP Server
  2. You have followed the installation instructions in the previous blog post.
  3. You know how to create folder and files in Ubuntu.
  4. You know how to start a terminal session and run commands in it.
  5. You know how to navigate to other directories using terminal session.

Summary Steps

  1. Compiling and Running helloworld
  2. Create a Apache virtual host

Compiling and Running helloworld

Create a folder to hold your source code. For example, I use “dotnet”.

Projects_134

Inside this folder, create a file call helloworld.cs.

dotnet_135

Edit the contents of this file and replace it with the following:

// Hello1.cs
public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}

After saving the file, start a new terminal session and navigate to the directory where you saved the file.

zhixian@SARA: ~-Projects-dotnet_136

The command to run the compiler for C# in Mono is mcs. Compile helloworld.cs by entering the following at the command-line:

mcs helloworld.cs

After running this command, you should see that you have a file call helloworld.exe in your project directory.

zhixian@SARA: ~-Projects-dotnet_137

To test run your application, enter the following command at the command-line.

./helloworld.exe

zhixian@SARA: ~-Projects-dotnet_138

You should see the words “Hello, World!” after you run the command.

Create a Apache virtual host

Now that we are sure the compiler for C# works, we will test if mod_mono can run ASP.NET applications.
What we are going to do at this section is to create a virtual host on Apache to host our ASP.NET application.

Steps

  1. Define ASP.NET application
  2. Configure Apache virtual host

Define ASP.NET application

We are going to create our test application in this section.

Create a folder to hold the contents of your ASP.NET web application.
In my case, I choose to put my file in a directory call zxtech.

Websites_139

Inside this folder, create a file call test.aspx.

zxtech_141

Edit test.aspx and replace the contents with the following:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>ASP Test Page</title>
  </head>
  <body>
        <form id="form1" runat="server">
          <asp:label id="lbl1" runat="server">ASP Test Page</asp:label>
        </form>
  </body>
</html>

test.aspx (~-Yandex.Disk-Websites-zxtech) - gedit_142

Save the file.
After saving the file, note the full path to the folder (press <CTRL>-L or press the button next to the Location buttons.)

You will need this information when configuring Apache virtual host.

zxtech_140

Configure Apache virtual host

Ok. Here’s where things starts to get a little sticky.
At your terminal session, navigate to Apache HTTP server’s sites directory (its /etc/apache2/sites-available/ by default) by entering the following command at the command-line:

cd /etc/apache2/sites-available/

zhixian@SARA: -etc-apache2-sites-available_143

By default, there should be 2 files in the folder, 000-default.conf and default-ssl.conf.
Make a copy of 000-default.conf for your virtual host (I am picking dev.zxtech.web as my virtual host name) by running the following command:

sudo cp ./000-default.conf ./dev.zxtech.web.conf

zhixian@SARA: -etc-apache2-sites-available_144

After the file is copied, edit the file.
Because the file is in folder owned by the superuser, you need to run the following command to edit the file:

gksudo gedit ./dev.zxtech.web.conf &

zhixian@SARA: -etc-apache2-sites-available_145

After you opened the file, you should see the following:

dev.zxtech.web.conf (-etc-apache2-sites-available) - gedit (as superuser)_146

Things to edit on this file:

  1. ServerName
  2. ServerAdmin (optional)
  3. DocumentRoot (optional)

ServerName refers to the your virtual host name that you will be using. In the below screen shot, this will be dev.zxtech.web.

ServerAdmin refers to an e-mail address that will be used when people needs to contact the server administator.

DocumentRoot refers to the folder where you store your ASP.NET application files. This will be the location of the folder that that you have noted in the previous section. In the below screen shot, this will be /home/zhixian/Yandex.Disk/Websites/zxtech.

After update, the file should look something like the below.

-dev.zxtech.web.conf (-etc-apache2-sites-available) - gedit (as superuser)_147

Things to add on this file:

  1. DirectoryIndex
  2. MonoAutoApplication
  3. AddHandler
  4. MonoServerPath
  5. MonoDebug
  6. MonoSetEnv
  7. MonoApplications
  8. Apache directory configuration
  9. Apache location configuration

DirectoryIndex refers to the default documents that will be use if user navigate to the folder without specifying a specific filename.

MonoAutoApplication refers to using a scheme in mod_mono that allows accounts on a machine to deploy ASP.NET pages without requiring to do any configuration. I prefer to do manual configuration, and so am disabling it here.

AddHandler designates files with specified file extensions to be process by mod_mono.

MonoServerPath allows you to specify the version of Mono runtime to use.
In the below screen shot, we are using the latest mono-server 4 which is equivalent to using ASP.NET 4.0.

MonoSetEnv is use to set an environment variable for use with the Mono run time used to execute the web application.
In the screen shot below, I defined MONO_IOMAP.
MONO_IOMAP is defined to take care of case-sensitivity issues. You can read more about it here.

MonoApplications is use to tell mod_mono that the ASP.NET application exists at the root directory of the web site (/) and this root directory maps (:) to the folder /home/zhixian/Yandex.Disk/Websites/zxtech (hence “/:/home/zhixian/Yandex.Disk/Websites/zxtech”)

Aside from the above Mono configuration, you may need to add an Apache directory configuration section especially if you are are hosting the web application files outside of Apache’s default DocumentRoot location which is /var/www/

 <Directory /home/zhixian/Yandex.Disk/Websites/zxtech>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
 </Directory>

You will also need to add an Apache location configuration section.

 <Location "/">
 Order allow,deny
 Allow from all
 MonoSetServerAlias dev.zxtech.web
 SetHandler mono
 SetOutputFilter DEFLATE
 SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
 </Location>
 <IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
 </IfModule>

After you added the sections, your configuration file should look like the below.

dev.zxtech.web.conf (-etc-apache2-sites-available) - gedit (as superuser)_153

After defining the configuration file, you can enable the website.

sudo a2ensite dev.zxtech.web.conf

zhixian@SARA: -etc-apache2-sites-available_151

The last step to get our virtual name hosting working is to edit our hosts located at /etc/hosts

zhixian@SARA: ~_150

In your text editor, add a line

127.0.1.1 dev.zxtech.web

hosts (-etc) - gedit (as superuser)_154

After this is done, you can navigate to http://dev.zxtech.web/test.aspx to test your sample web application.
You should see:

ASP Test Page - Firefox Developer Edition_155

Reference

A nice tutorial to C# can be found here (http://msdn.microsoft.com/en-us/library/aa288463%28v=vs.71%29.aspx)

Advertisements

2014-12-16

How to install and setup Yandex Disk on Ubuntu

This blog post is about installing and configuring Yandex.Disk, a cloud storage service.

Summary

  1. Assumptions
  2. Installation
  3. Configuration
  4. Launch on startup

Assumptions

This application is priced at $0.
As such, installation requires the use of an Ubuntu One account.
It is assumed that you have such an account.

It is also assumed that you have a Yandex account to use this service.
At this time of writing, the service remains free.

Installation

Yandex.Disk can be installed via Ubuntu Software Center (search term: yandex).
Click on the More Info button to view details.

Ubuntu Software Center_052

In the software description page, click on the Buy button.
At this time of writing, its priced at $0.

Ubuntu Software Center_053

After you pressed Buy, there will be a Terms of Use dialog.
Click on the Accept button to accept the terms of use.

Terms of Use_054

After you clicked on the Accept button, you need to log in to your Ubuntu One account.

Ubuntu Software Center_055

After you entered your credentials and log in to your Ubuntu One account, the installation for the application should proceed accordingly.
After the installation has complete, you should be able to access it from the desktop menu:
Applications > Internet > Yandex Disk

Workspace 1_058

After you click on the menu item, it will start a console session describing the usage of Yandex Disk command, yandex-disk.

zhixian@SARA: ~_059

Configuration

To setup your Yandex Disk, type the following command in the Yandex Disk console session:

yandex-disk setup

The setup process will prompt you for:

  1. Your proxy server information
    (I entered “N” as I do not use a proxy server)
  2. Credentials to your Yandex account
  3. Path to a folder on your local disk to store your Yandex Disk files.
    (I left this field as blank to use the default proposed path)
  4. Whether to start Yandex Disk on startup
    (I entered “Y” to start Yandex Disk on startup)

zhixian@SARA: ~_062

After setup is done, the background (daemon) process will begin to synchonize files from your Yandex Disk in the cloud to the path that you defined above in point 3 (/home/zhixian/Yandex.Disk).

When you examine the folder after a short while, you should see files in your Yandex Disk appearing in the folder.

Yandex.Disk_063

Launch on startup

When doing the setup, you might have indicated that you would like Yandex Disk to launch on startup.
As of this writing, this may not be working correctly.
To remedy this:

Go to the System > Control Center on the desktop menu.

Workspace 1_074

In the Control Center window, click on Startup Applications. to open the Startup Applications Preferences dialog.

Control Center_076

In the dialog, click Yandex.Disk in the lists of additional startup programs.
Then click on Edit button to open the Edit Startup Program dialog.

Startup Applications Preferences_082

In the Edit Startup Program dialog, change the command from:

yandex-disk start

to

/opt/yandex-disk/yandex-disk start

Edit Startup Program_081

After you click Save to close the dialog, Yandex Disk should launch on startup correctly now.

2014-11-26

How to add WordPress to BloGTK

Filed under: computing — Tags: , , , , , — Zhixian @ 22:00:11 pm

This blog post describes how you would configure BloGTK to add your WordPress blog.

After you start BloGTK, click on the Settings button on the top toolbar.
As Edit Settings popup dialog will appear.

BloGTK 2.0_038

In the Edit Settings dialog popup,

  1. Enter an account name
  2. Enter the url of your WordPress blog
  3. Click on the Autodetect Settings button.

BloGTK - Edit Settings_039

After the dialog finished detecting settings, you should see that the Endpoint and Blogging Tool should be updated.

Enter the username and password to your WordPress blog into the Username and Password textboxes respectively.
Then click on the Accept Changes button to close the dialog.

BloGTK - Edit Settings_040

BloGTK - Edit Settings_041

At the BloGTK main screen, click on the Refresh button to fetch your latest blog posts.

BloGTK 2.0_042

2014-11-21

How to configure ServerName directive globally for Apache HTTP Server

After installing Apache HTTP Server, you may notice that that when you restart the service, you may get the following annoying message:

Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message

zhixian@SARA: ~_017

To get rid of this message, you need to define a ServerName for your Apache HTTP Server.
To achieve this, you need to:

  1. Define a “fqdn.conf” file in Apache HTTP Server’s available configuration folder.
  2. Enable the “fqdn.conf” configuration
  3. Restart Apache HTTP Server

Implementation Details

1. Define “fqdn.conf”

Apache HTTP Server’s available configuration folder can be found at:

/etc/apache2/conf-available/

To create the “fqdn.conf” file, enter the following command into a terminal session:

echo “ServerName localhost” | sudo tee /etc/apache2/conf-available/fqdn.conf

zhixian@SARA: ~_018

What this command does is to write the string “ServerName localhost” into a file “fqdn.conf” at “/etc/apache2/conf-available/”.

2. Enable configuration

To enable the “fqdn.conf” that we just added to Apache HTTP Server, enter the following command in a terminal session:

sudo a2enconf fqdn.conf

zhixian@SARA: ~_019

3. Restart Apache HTTP Server

To restart the Apache HTTP service, enter the following command in a terminal session:

sudo service apache2 reload

zhixian@SARA: ~_020

After you restart the service, you should no longer see set “ServerName directive globally” message.

Reference:

http://askubuntu.com/questions/256013/could-not-reliably-determine-the-servers-fully-qualified-domain-name

2013-06-22

How to connect to Microsoft Sql Server from Ubuntu via ODBC using FreeTDS

Filed under: computing — Tags: , , , , , , , — Zhixian @ 22:08:06 pm

This post describes the steps carried out to test my connection to Microsoft Sql Server from Ubuntu using ODBC.
This is part of my “How to connect to Sql Server from Ubuntu” series of blog post.

Assumptions

  1. The version of Ubuntu used in this guide is Ubuntu 12.04.2 LTS (Precise Pangoline) 32-bit.
  2. You are trying to connect to Microsoft Sql Server 2008 or later.
  3. You know how to use a terminal session in Ubuntu.
  4. You have installed unixodbc.
  5. You have installed freetds.

Note: Some of configuration files may be sitting in folders where your default user account may not have permission to edit them.
It is assume that that you will use “sudo” to gain the necessary elevated permission to edit the file if this happens.

Information required

  1. Location of odbcinst.ini file.
    This file is where you will be placing configuration details of any ODBC drivers that you will be using.
    If you have followed the steps in the previous blog post, this file should be at /usr/local/etc/odbcinst.ini
  2. Location of the freetds drivers.
    If you have followed the steps in the previous blog post, this file should be at /usr/local/lib/libtdsodbc.ini

Configuration overview

  1. Add driver configuration information for freetds
  2. Test freetds
  3. Configure freetds.conf for Sql Server connectivity testing
  4. Test connection
  5. Troubleshooting notes

Add driver configuration for freetds

1) Edit your /usr/local/etc/odbcinst.ini.
It should be blank. Add the following lines to the file and save the file.

[FreeTDS]
Description    = FreeTDS unixODBC Driver
Driver        = /usr/local/lib/libtdsodbc.so
Setup         = /usr/local/lib/libtdsodbc.so

Test freetds

After you have configure the driver, you can test the connection to your Sql Server.
We will use the tsql command to test the connection.

1)  Start a terminal session. Type tsql –C on the command line.

This command displays some of freetds configuration.
You should see results like the below.

image

Of note is the freetds.conf directory. This file is used to define Sql Servers aliases as well as freetds driver default settings.

2) Assuming you manage to display the configuration information, this means that your freetds setup correctly.
The next thing to try to do is probe for your Sql Server.
You do thing by typing the command tql –LH <machine_hostname>

<machine_hostname> can be hostname or an IP address.
In the screen below, the machine that host my Sql Server is SARA, so I typed tsql –LH SARA

image

From the above results, I can see that I have 2 instances of Sql Server installed on the host SARA.
It is important to note the TCP port number used by the server instance.
For the remainder of this post, we will try to connect to the SQLEXPRESS instance.
But prior to that, we will need to add a configuration setting in order to use the tsql command to connect to Sql Server.

 

Configuring freetds.conf

1) Remember the freetds.conf  file that you noted in step 1 of under test freetds? The one located at /usr/local/etc/freetds.conf ?
There are content in this file. But you don’t really need them at this stage. What you really need are just the following lines:

[global]
tds version = 8.0

Save the file.
The reason this step is required is because the tsql command utility do not have any parameters that allow you to specify the TDS version that it should use to connect to Sql Server. This is a problem when trying to connect to Sql Servers 2005 or later.
Hence, we set it as a global setting so that the default TDS version that driver will revert to is version 8.0

Test connection

1) Now you can use the tsql command to connect to your Sql Server.

Assuming my database user account is dbadmin, I would connect to the server by typing the following at the command line:
tsql –S SARA\\SQLEXPRESS –U dbadmin

If you get a screen like the below, it means you have successfully connected to your Sql Server.

image

You can run sql statements in this shell.
Type quit in the shell to exit.

image

 

Troubleshooting notes

Problem 1)

If you get a message like “There was a problem connecting to the server” as per the screen below, check your freetds.conf file and make sure tds version is set to 8.0 under global settings section.

image

 

Problem 2)

Another problem you might encounter when test is the following.
You appear to have logged in successfully, but you get a  running numeric prompt that starts from 1, 2, 3, …until such a time it timed out.

image

Essentially, it means tsql was not able to locate the server.

Checkpoints for this problem are:

  1. Is this correct server?
    If you are trying to connect to a database instance, you should specify tsql –S SARA\\SQLEXPRESS –U dbadmin
  2. Is the server running on default port?
    Note the TCP used by Sql Server by using the tsql –LH <machine_hostname> command. Then try the tsql command again by specify the port number with –p parameter. That is to say:
    tsql –S SARA\\SQLEXPRESS –U dbadmin –p 1433

 

Hope this helps anyone who had trouble setting up connection to Sql Server from their Ubuntu boxes.

Blog at WordPress.com.