Monday, May 30, 2011

how to make Apache run ASP.NET and MySQL on Linux Fedora


This will show how to make Apache run ASP.NET and MySQL on Linux Fedora.

dont ask me why ASP.NET on Linux/Apache, I was asked to make it works, and IT WORKED !!!

The guide was tried to run on Fedora 14, but it may works on other version of fedora

- Install packages

If Apache is not yet installed, then you the following command, Use yum to install Apache, mod_mono and the dependencies to xsp.

# yum install httpd mod_mono mono-web

If Apache is already installed, then we just need to install mod_mono and its dependencies

# yum install mod_mono mono-web

- Install xsp from rawhide

If you install xsp from the standard Fedora repository, you get this error in httpd error_log.

500 Internal Server Error

System.InvalidOperationException: mod_mono and xsp have different versions.

Use this command to install xsp from the rawhide repository.

# yum install --enablerepo=rawhide xsp

- Disabling SELinux

Set SELinux in permissive mode (setenforce 0) to avoid the following error.

503 Service Temporarily Unavailable

[error] Failed to connect to mod-mono-server after several attempts to spawn the process.

To put the system into permissive mode, issue this command.

# setenforce 0

Managing the policies for SELinux is beyond the scope of this article, but you can find more information about SELinux in the Fedora SELinux Project Page (http://fedoraproject.org/wiki/SELinux).

- Setting up a MySQL database

Assuming that MySQL is already Installed, then we need to create sample database and table to be fetched by ASP.Net code.

$ mysql -uroot -p
...

mysql> CREATE DATABASE cdcat;
Query OK, 1 row affected (0.10 sec)

mysql> USE cdcat;
Database changed

mysql> CREATE TABLE artist ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) );
Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO artist VALUES(null, 'Wire');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO artist VALUES(null, 'The Fall');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM artist;
+----+----------+
| id | name |
+----+----------+
| 1 | Wire |
| 2 | The Fall |
+----+----------+
2 rows in set (0.00 sec)

mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON cdcat.* TO cdcat@localhost IDENTIFIED BY 'hardpassword';
Query OK, 0 rows affected (0.12 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.13 sec)

What we've done here is setup the first table in a CD catalogue database, namely:

  • Created a new database called cdcat
  • Created a table called artist in that database
  • Put two artists into the table
  • Created a user called cdcat with SELECT, UPDATE, DELETE and INSERT privileges on all tables in the cdcat database
  • Made those privileges active
- Installing Connector/Net

Now you've got a MySQL database server, database, table and user set up, you'll need the MySQL connector for ASP.Net. You need to download Connector/Net from the MySQL website. The one you need is Windows Binaries, no installer (ZIP).

Once the zip file is downloaded, create a directory somewhere and unzip its contents into it. The file you're after is in the resulting bin directory, MySQL.Data.dll. To install it, use the gacutil tool included in the Mono installer, which puts it into the right place in your Mono library directory:

gacutil -i /path/to/unzipped/connector/bin/MySQL.Data.dll

If gacutil isn't on your path you'll need to reference it correctly using its full path.

Creating a simple page to show data from a table
To prove you've got everything installed correctly, we'll create a page to display the contents of the artist table using one of the standard ASP.Net controls. Like I've said before, this isn't going to be a full ASP.Net tutorial, so I'm not going to try to explain Web Forms and all that jazz: I'm just giving a few examples to help you get the pieces working nicely together. See one of the countless ASP.Net books for more detail. (By the way, if anyone can recommend a half-decent tutorial book for ASP.Net, please let me know, as the ones I've looked at are generally good reference works, but lousy tutorials.) I'll try to put more tutorial material in as I learn more about ASP.Net.

First, create a file called artists.aspx inside your project folder.



Next, put this code into the file and save it:



<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CD cat</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script runat="server">
private void Page_Load(Object sender, EventArgs e)
{
string connectionString = "Server=localhost;Database=cdcat;User ID=cdcat;Password=hardpassword;Pooling=false;";
MySqlConnection dbcon = new MySqlConnection(connectionString);
dbcon.Open();

MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM artist", dbcon);
DataSet ds = new DataSet();
adapter.Fill(ds, "result");

dbcon.Close();
dbcon = null;

ArtistsControl.DataSource = ds.Tables["result"];
ArtistsControl.DataBind();
}
</script>

</head>

<body>
<h1>Artists</h1>
<asp:DataGrid runat="server" id="ArtistsControl" />
</body>

</html>
Finally, you need a web.config file, again in the project root directory. This contains application settings, such as which libraries your application needs. It should contain the following to enable the MySQL libraries to be loaded:

<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="MySql.Data"/>
</assemblies>
</compilation>
</system.web>
</configuration>


- Restart httpd

Start or restart httpd.

# service httpd restart

Now run your application again with xsp2 from inside the project directory and browse to http://localhost:8080/artists.aspx. You should see this:

Source:
1. http://www.inprose.com/articles/10-enable-aspnet-support-in-fedora-linux.html
2. http://townx.org/blog/elliot/using-mysql-asp-net-under-mono-linux

Sunday, May 22, 2011

Installing Apache, PHP and MySQL on Fedora

There's XAMPP that integrate Apache, MySQL, PHP and Perl in one bundle and installing them easily on a machine.

however, I've always found XAMPP on Linux to be hard to use. On Windows, it's great because it sets up a quick independent stack. I can have many of them, running easily.

For Linux, I just do:

"yum install httpd mysql php mod-suphp".

This much more easier, then I go through the list of PHP modules I think I'll need and install them too in the same manner.

or if you wanna see more explanation in step by step manner on how to install Apache (httpd) and PHP 5.3.6 on Fedora (11-14), go and check these links :

  1. www.if-not-true-then-false.com
  2. http://www.hackourlife.com
  3. http://library.linode.com/databases/mysql/fedora-14


-- Zeldi

Thursday, May 19, 2011

Enabling Flash on Ubuntu 11.04 (Natty)

I am used to Fedora Linux OS, however I decided to get familiar with Ubuntu 11 (Natty).
First thing first, I downloaded Ubuntu 11 and Installed it successfully.
with its Unity UI (apart from its classical UI), it just looks simple but pretty.. it is awesome.

Having Natty successfully installed, another first thing I tried was installing Google Chrome, it simple because I dont wanna miss Angry Bird game from it.
With the following simple command :

# sudo apt-get install chromium-browse

The Chrome also setup and run very well.

First thing I tried from Chrome of course its addicted "Angry Bird" game.
I download and run the game.. but uppppssss.... the game could not run well..

After short conversation with google, I found the reasons and solution for this issue. It is because the Angry Bird game is a flash based game, default installation of Ubuntu does not include flash support as it may violate the Intellectual Property.

Ubuntu is committed to Free software (free in cost and free in licensing restrictions), but in "the real world," most computer users are used to having proprietary or nonfree codecs and support software installed (to use Java, MP3s, Microsoft fonts, etc.), so Ubuntu has included an easy way to install these nonfree items. The free in the word nonfree refers to licensing restrictions, not to cost.

to solve this issue, I follow the following steps:



If you're using Unity, you can find Ubuntu Software Center on the left side of your screen.If you're using classic Gnome, go to Applications and select Ubuntu Software Center


Do a filter search for the word restricted and then click Install next to Ubuntu restricted extras.

When prompted for your password, enter it.



That's it!

You can find more details here (without all the screenshots).

There are also variations on Ubuntu that include proprietary/nonfree software in the default installation. One popular variation is called Linux Mint.

And now I can enjoy playing angry bird.....





 
powered by Blogger