2/19/09

.htaccess

Trong quá trình tìm hiểu để sửa lỗi Internal Server Error, Fan đã tìm thấy một tài liệu nói về file .htaccess , file này có thể áp dụng để chặn các IP spam mà như Fan đã làm cho TVT, ngoài ra còn nhiều tác dụng khác. Sau đây xin giới thiệu với các bạn những bài viết về file .htaccess

Tiêu đề: Giới thiệu về file .htaccess

File .htaccess hầu hết được dùng để đặt mật khẩu cho web site của bạn. ví dụ. nếu tôi muốn dùng mật khẩu để bảo vệ site http://domain.com/secrect/ Tôi có thể tạo một file gọi là .htaccess trong folder secret nằm trên server đó. Ngoài ra file .htaccess còn dùng để từ chối việc liệt kê file trong folder. Điều này rất tiện khi bạn không có file index ví dụ. images/ cgi-bin/ db/ .

Có rất nhiều tùy chọn cho bạn đặt vào file .htaccess. Ở đây tôi chỉ đề cập đến 'AuthConfig' và 'Limit'.

QUAN TRỌNG: File .htaccess hoạt động trong toàn bộ cây thư mục. Ví dụ. nếu bạn có một file .htaccess trong /www/.htaccess thì nó sẽ có tác dụng đến /www/public/, /www/pictures, v.v.. Nếu bạn chỉ muốn không cho liệt kê thư mục trong /www/pictures thì đặt file .htaccess vào /www/pictures chứ KHÔNG phải vào /www !
Có một tùy chọn khác với thẻ nhưng tôi sẽ không đề cập trong bài này . Bạn có thể dùng google nếu muốn tìm hiểu kỹ hơn.

Đặt mật khẩu bảo vệ:
==============
Việc đầu tiên là phải tạo một file gọi là .htpasswd để chứa username và mật khẩu (đừng lo lắng gì, chúng đã được mã hóa). Có nhiều cách tạo mật khẩu mã hóa. Cách dễ nhất là vào http://www.euronet.nl/~arnow/htpasswd/ tạo một cái. Sau đó bạn copy/paste dòng kết quả vào file .htpasswd. Tiếp theo ta tạo file .htaccess. Ví dụ như sau:
CODE
AuthUserFile /home/leon/secret/.htpasswd
AuthGroupFile /dev/null
AuthName "My .htaccess secured web page!"
AuthType Basic
require valid-user



Dòng đầu tiên là nơi bạn chứa file .htpasswd. Những dòng còn lại chắc bạn cũng đã hiểu!


Từ chối ip:
Nếu bạn muốn cấm (block) vài ip hay isp thì đặt một trong những dòng sau vào file .htaccess:
CODE
order allow,deny
deny from 123.45.67.89
deny from 45.67.89.
allow from all


Nó sẽ cấm 123.45.67.89 và mọi ip bắt đầu với 45.67.89.

Bên cạnh đó bạn cũng có thể làm như sau:
CODE
order deny,allow
deny from all
allow from 123.45.67.8


Nó sẽ cấm tất cả IP ngoại trừ 123.45.67.8

Ngoài ra bạn có thể tham khảo thêm ở:
http://httpd.apache.org/docs/howto/htaccess.html
http://wsabstract.com/howto/htaccess.shtml
http://www.he.net/faq/tutorials/htaccess/demo.html
http://www.freewebmasterhelp.com/tutorials/htaccess/
http://baremetal.com/gadgets/htaccess/

Helloworld with JSP + ECLIPSE + TOMCAT

Chạy Eclipse 3.2 trong thư mục đã cài (C:\eclipse\eclipse.exe), chọn một thư mục để làm việc. Nếu đây là lần sử dụng đầu tiên, Eclipse sẽ hiển thị trang Welcome, bạn đóng nó lại.

Để tạo một Web project, bạn chọn File\New\Project, chọn Dynamic Web Project

Bạn đặt tên cho project là HelloWorld, sau đó nhấn Finish luôn , mặc định với các tùy chọn phía sau.



Eclipse sẽ tạo cấu trúc thư mục, các library cho bạn, sau khi hoàn tất, Eclipse hiện ra một Dialog hỏi bạn có muốn chuyển qua view ở chế độ J2EE không ? Ứng dụng Web của chúng ta khá đơn giản nên chỉ cần view ở chế độ Java, vì thế bạn chọn No. Cấu trúc thư mục Eclipse tạo cho bạn sẽ như sau :




Cấu trúc thư mục này gồm có :

  1. thư mục src : chứa toàn bộ source code Java
  2. WebContent : chứa file JSP
  3. WebContent\lib : chứa các thư viện mà bạn sử dụng trong ứng dụng này, thư mục này cũng được Eclipse hiểu là Web App Libaries
  4. web.xml : file cấu hình chính cho một ứng dụng Web
  5. JRE System library : môi trường Java mà ứng dụng của bạn sẽ chạy trên đó
Vậy là bạn đã có một ứng dụng Web, như đã nói ở trên, muốn chạy được ứng dụng này, bạn cần có một Web Server, ở trên chúng ta đã download Tomcat 5.5 và unzip ở C:\ . Bây giờ bạn sẽ tạo một Web Server trong Eclipse cho ứng dụng HelloWorld của bạn!

Right click vào project HelloWorld, chọn New\Others chọn Server



Ở đây bạn sử dụng Tomcat 5.5 của Apache, vì vậy chọn Tomcat v5.5 Server click Next, trong trang này yêu cầu bạn chỉ rõ đường dẫn của thư mục cài đặt Tomcat 5.5, bạn click Browse, chọn thư mục đã unzip Tomcat 5.5 (C:\apache-tomcat-5.5.23)



Bước kế tiếp , bạn chọn project HelloWorld để cấu hình cho Server này






Sau đó Finish để hoàn tất quá trình tạo Server cho project.

Do một Web project trong Java khi chạy cần một số thư viện của Tomcat, vì vậy, bạn cần thêm một bước phụ nữa để sử dụng thư viện này. Right click lên project HelloWorld, chọn Build Path\ Add Libaries, chọn Server Runtime




Chọn Apache Tomcat v5.5 , Finish để kết thúc




Sau khi hoàn thành, bạn thấy trong project HelloWorld có thêm một mục mới là Apache Tomcat v5.5 với nhiều file jar trong đó, đây là những thư viện của Tomcat mà chúng ta có thể dùng trong project , quan trọng nhất là serlet-api.jar – thư viện cần thiết để viết Web , không có sẵn trong bộ cài đặt Java !




Như vậy toàn bộ các bước thiết lập môi trường đã hoàn tất, bây giờ bạn bắt đầu viết trang JSP đầu tiên !




Right click vào thư mục Web Content , chọn New \ Others, chọn Web\JSP






Gõ vào tên của file là index.jsp . Chú ý là Web Server sẽ tìm trang index đầu tiên trong ứng dụng của bạn, vì thế trang đầu tiên phải có tên là index hoặc default ! Rồi , bạn chỉ cần Finish là xong !




Trang index.jsp của bn s như sau :






Các dòng có sẵn là do JSP template của Eclipse sinh ra, tại dòng , bạn thêm vào chuỗi :




<%out.println("Hello World"); %>





Save lại file này !




Bạn sẽ chạy file jsp này để xem kết quả, Right click lên HelloWorld project chọn Run As \ Run On Server, hiện ra dialog





Bạn chọn Apache Tomcat v5.5 để chạy Project này, chọn Finish ! Bạn sẽ thấy trong Browser của Eclipse hiện ra chuỗi “Hello World” của bạn !







Chú ý , đây là bạn chạy trong Internal Web Browser của Eclipse, bạn muốn kết quả của mình hiện ra trên IE, bạn chọn trên thanh Tool Bar, chọn Window\Web Browser\ Internet Explorer, chạy lại project , kết quả sẽ hiển thị trên IE của bạn ! Thật là đơn giản khi viết Web bằng JSP đúng không ?! Chúc bạn thành công !

2/18/09

Using Smarty

Bước đầu dùng smarty – template engine dành
cho lập trình PHP
Khái niệm template engine vốn khá quen thuộc với tất cả những ai lập trình đặc biệt là lập trình web, khi mà chương trình đòi hỏi chạy ở 2 nơi (server – client). Đồng thời, template engine còn tạo sự độc lập trong lập trình và thiết kế giúp tránh lỗi không mong muốn cũng như phân chia công việc khi làm group rất hiệu quả. Tất nhiên không chỉ có vậy mà template engine còn nhiều điểm cần thiết nửa, nhất là Smarty vốn là template engine khá phổ biến trong thế giới PHP và được nhiều người ưa chuộng. Tuy vẫn còn có những khuyết điểm nhưng tư tưởng và kết quả smarty đạt được đáng được học hỏi và vận dụng đúng mức.

Thông tin về mã nguồn và document thì có thể down ở đây:
http://smarty.net
Thông tin về các ý kiến phản đối cũng như những khuyết điểm của smarty có thể xem ở đây
http://nosmarty.net
Thông tin về source code cho ví dụ này có thể down ở đây:
http://bkitweb.com/store/Smarty-1.zip

Tất cả những gì chúng ta cần là 1 webserver chạy được PHP và 1 thư viện smarty down từ trang của smarty ở trên. Sẵn tiện hãy down luôn document của nó.

Sau khi tải smarty về và giải nén chúng ta sẽ có 1 thư mục Smarty. Hãy giải nén nó váo thư mục $ROOT của webserver.

Bây giờ hãy chú ý đến thư mục libs. Chúng ta sẽ chỉ dùng đến thư mục này vì đây là thư mục chứa toàn bộ thư viện smarty vì vậy nếu muốn thì có thể tham khảo những đặc điểm kèm theo nếu không thì hãy xóa hết tất cả những thứ khác và để lại chỉ thư mục libs thôi.

Tiếp theo là công tác chuẩn bị. Để smarty hoạt động chúng ta sẽ cần đến 1 thư mục chứa template, 1 thư mục chứa cache, một thư mục chứa thông tin cấu hình và một thư mục chứa thông tin compile của smarty. Vì vậy hãy tạo thư mục dạng như sau:


Tiếp theo hãy tạo file index.php trong thư mục gốc như hình và dùng đoạn mã sau:

require 'libs/Smarty.class.php'; //1
$smarty = new Smarty();//2
$smarty->compile_check = true;//3
$smarty->debugging = true;//4
$smarty->cache_dir = "cache";//5
$smarty->template_dir = "template";//6
$smarty->compile_dir = "compile";//7
$smarty->cache_lifetime = 60;//8
$smarty->config_dir = "config";//9
$smarty->caching = false;//10
$smarty->right_delimiter = "}";//11
$smarty->left_delimiter = "{";//12
//start to assign data
$smarty->assign("groupName", "Bkitweb");//13
$smarty->assign("title", "Hello smarty!!!");//14
$smarty->assign("members",array("John","Mary","James","Henry"));//15
//end of assign data
$smarty->display('index.tpl');//16
?>
Trên đây là đoạn mã khởi tạo smarty với những thông số cấu hình thông dụng nhất. Trước khi giải thich chi tiết từng phần chúng ta cần chạy được cái đã. Hãy chú ý dòng 16 cuối cùng đang dùng đến file template là index.tpl, ngay bây giờ hãy tạo 1 file tên index.tpl trong thư mục template sau đó đưa nội dung vào như sau:
<html>
<head>
<title>
{$title}
</title>
</head>
<body>
<h1>{$groupName}</h1>
{foreach from=$members item=member}
Member name: {$member}<br/>
{/foreach}
</body>
</html>


Và cuối cùng, hãy chắc rằng thư mục compile, cache được phép ghi. Hãy vào trình duyệt và chạy http://yourdomain/Smarty/ , nếu không có vấn đề gì thì sẽ xuất hiện trang web như sau:
This image has been resized. Click this bar to view the full image. The original image is sized 721x402.


Trong hình trên thì ngoài trang web chính còn có 1 cửa sổ mở ra để hiện thông tin debug. Để không hiển thị cửa sổ này hãy edit dòng 4 trong file index.php thành
$smarty->debugging = false;//4
Và nếu như mọi thứ cho đến thời điểm này đều diễn ra như mong muốn thì bạn đã thực sự làm chủ được smarty trong ứng dụng của bạn trong việc cấu hình nó. Còn bây giờ chúng ta sẽ đi vào chi tiết về cách mà smarty hoạt động cũng như cấu hình nó bằng cách phân tích từng dòng trong file index.php
1.require 'libs/Smarty.class.php'; // đưa thư viện của smarty vào, trong file này chứa thông tin định nghĩa class smarty mà chúng ta dùng
2.$smarty = new Smarty();// khởi tạo 1 instance của lớp Smarty
3.$smarty->compile_check = true;// bật chế độ kiểm tra lổi khi compile
4.$smarty->debugging = true;// bật chế độ debug
5.$smarty->cache_dir = "cache";// chọn thư mục chứa cache
6.$smarty->template_dir = "template";// chọn thư mục chứa template, smarty sẽ tìm những file tpl trong đây để compile
7.$smarty->compile_dir = "compile";// thư mục chứa dữ liệu tam khi compile của smarty
8.$smarty->cache_lifetime = 60;//đặt thời gian sống của cache, tính bằng giây
9.$smarty->config_dir = "config";//chọn thư mục chứa flie cấu hình
10.$smarty->caching = true;//Bật chế độ cache lại thông tin sau khi compile
11.$smarty->right_delimiter = "}";//quy định dấu đóng dòng lệnh của smarty
12.$smarty->left_delimiter = "{";//quy định dấu mở dòng lệnh của smarty
13.Đăng ký biến với smarty
//start to assign data
$smarty->assign("groupName", "Bkitweb");//13
$smarty->assign("title", "Hello smarty!!!");//14
$smarty->assign("members",array("John","Mary","James","Henry"));//15
//end of assign data
Chú ý phương thức assign dùng để đăng ký một biến từ PHP sang cho template dùng. Ví dụ với dòng 13 thì trong file template sẽ gọi biến đó bằng {$groupName}
14.Show smarty với template chỉ định
$smarty->display('index.tpl');//16
Smarty sẽ tự động tìm trong thư mục chứa template đã chỉ định để thể hiện file cần thiết với phương thức display.

Vậy là mọi chuyện về cấu hình và gọi template xem như hoàn thành. Trước khi đi vào vài dòng lệnh cơ bản ở file index.tpl chúng ta sẽ khảo sát vài chức năng của thông số cấu hình smarty xem nó hoạt động ra sao. Bây giờ hãy xóa hết mọi thứ tạo ra trong thư mục compile và cache sau đó sửa dòng 10 lại thành
$smarty->caching = false;//10
Chạy lại trang web và chúng ta se chú ý rằng trong thư mục cache không có gì được tạo ra. Hãy xóa 2 thư mục đó lần nửa và cho dòng 10 lại thành true và chạy lại thì sẽ thấy thư mục cache có 1 file. Đây chính là cache mà smarty tạo ra, việc tạo cache này có thể sẽ làm chậm xử lý trong lần đầu nhưng sau đó thì quá trình sẽ nhanh hơn rất nhiều vì chỉ cần compile lại những khi dữ liệu thay đổi. Tương tự hãy tùy biến những thông số khác để có thể hiểu hơn về smarty.

Tiếp theo chúng ta sẽ nói sơ qua về file index.tpl. File này thật sự tách biệt với mã PHP hoàn toàn thích hợp với designer – họ chỉ cần dữ liệu để thể hiện chứ không cần xử lý dữ liệu.
Theo như file index.tpl ở trên thì chúng ta sẽ viết giống như 1 file HTML thông thường nhưng những gì chúng ta cần thể hiện khi đã xử lý bằng PHP thì hoàn toàn có thể gọi ra ở đây bằng cách đơn giàn nhất là {$varName}
Như đã thấy file index.php thì chúng ta đăng ký 3 biến là : title, groupName, members nên chúng ta sẽ dùng chúng trong file index.tpl bằng cách gọi biến ra. Ngoài ra chú ý dòng sau:
{foreach from=$members item=member}
Member name: {$member}<br/>
{/foreach}
Do biến $members là 1 array nên chúng ta sẽ gọi ra bằng 1 cách khác. Chúng ta sẽ bàn kỹ về những câu lệnh này vào 1 bài khác về “các lệnh hổ trợ trong smarty”.Còn bài này chỉ giới thiệu đến đây.
Sự tách biệt rõ rang của designer và programmer hoàn toàn có thể làm được với cách này nhưng tất nhiên không chỉ hổ trợ như vậy mà còn rất nhiều chức năng khác nửa của smarty mà bkitweb sẽ giới thiệu nhanh chóng vào các bài sau. Tất cả sẽ làm cho việc thiết kế giao diện trở nên nhẹ nhàng thoải mái và giúp vấn đề về ngôn ngữ cũng như cách thể hiện của hệ thống cải thiện đáng kể

2/17/09

Dot Net Interview Questions

Author: ngocbd
• Tuesday, December 30th, 2008

1.What is a stack? What is a heap?

Ans : Stack is a place in the memory where value types are stored. Heap is a place in the memory where the reference types are stored.

2.What is Boxing/Unboxing?

Ans : Boxing is used to convert value types to object.
E.g. int x = 1;
object obj = x ;
Unboxing is used to convert the object back to the value type.
E.g. int y = (int)obj;

3.What is globalization?

Ans : Globalization is the process of customizing applications that support multiple cultures and regions.

4.What is localization?

Ans : Localization is the process of customizing applications that support a given culture and regions.

5.What is Ilasm.exe used for?

Ans : Ilasm.exe is a tool that generates PE files from MSIL code. You can run the resulting executable to determine whether the MSIL code performs as expected.

6.What is Ildasm.exe used for?

Ans : Ildasm.exe is a tool that takes a PE file containing the MSIL code as a parameter and creates a text file that contains managed code.

7.What is the ResGen.exe tool used for?

Ans : ResGen.exe is a tool that is used to convert resource files in the form of .txt or .resx files to common language runtime binary .resources files that can be compiled into satellite assemblies.

8.What happens when you change the web.config file at run time?

Ans : ASP.NET invalidates the existing cache and assembles a new cache. Then ASP.NET automatically restarts the application to apply the changes.

9.Explain the AutoPostBack feature in ASP.NET?

Ans : AutoPostBack allows a control to automatically postback when an event is fired. For eg: If we have a Button control and want the event to be posted to the server for processing, we can set AutoPostBack = True on the button.

10.What are Master Pages?

Ans : Master pages is a template that is used to create web pages with a consistent layout throughout your application. Master Pages contains content placeholders to hold page specific content. When a page is requested, the contents of a Master page are merged with the content page, thereby giving a consistent layout.

11.What are the types of Caching?

Ans : 1.Application Cache 2.Page Output Cache 3.Variable Cache


12.Method Parameters in C#?

Ans : 1. REF,2. OUT,3.PARAMS


13.What’s the .NET datatype that allows the retrieval of data by a unique key?

Ans : HashTable.

14.How do you debug an ASP.NET Web application?

Ans : Attach the aspnet_wp.exe process to the DbgClr debugger.

15.What is the syntax to inherit from a class in C#?

Ans : Place a colon and then the name of the base class.

Example: class MyNewClass : MyBaseClass

16.What’s a bubbled event?

Ans : When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

17.What does WSDL stand for?

Ans : Web Services Description Language.

18.Can you override private virtual methods?

Ans : No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

19.What is an out parameter?

Ans : An out parameter allows an instance of a parameter object to be made inside a method. Reference parameters must be initialised but out gives a reference to an uninstanciated object.

20.What is recursion?

Ans : Recursion is when a method calls itself.

21.Name 10 C# keywords.

Ans : abstract, event, new, struct, explicit, null, base, extern, object, this

22.What is a DLL?

Ans : A set of callable functions, which can be dynamically loaded.

23.What is unsafe code?

Ans : Unsafe code bypasses type safety and memory management.

24.How would you read and write using the console?

Ans : Console.Write, Console.WriteLine, Console.Readline

25.What’s the difference between // comments, /* */ comments and /// comments?

Ans : Single-line comments, multi-line comments, and XML documentation comments.

Author: ngocbd
• Tuesday, December 30th, 2008

1.What are server controls?

Ans : ASP.NET server controls are components that run on the server and encapsulate user-interface and other related functionality. They are used in ASP.NET pages and in ASP.NET code-behind classes.

2.What are Sealed Classes in C#?

Ans : The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class) .

3.What is the difference between Array and Arraylist?

Ans : As elements are added to an ArrayList, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.

4.What is Jagged Arrays?

Ans : A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an “array-of-arrays.”

5.Which method is used to redirect the user to another page without performing a round trip to the client?

Ans : Server.Transfer method.

6.Is it possible to debug java-script in .NET IDE? If yes, how?

Ans : Yes, simply write “debugger” statement at the point where the breakpoint needs to be set within the javascript code and also enable javascript debugging in the browser property settings.

7.How many ways can we maintain the state of a page?

Ans : Client Side - Query string, hidden variables, viewstate, cookies

Server side - application , cache, context, session, database.

8.Will the finally block be executed if an exception has not occurred?

Ans : Yes it will execute.

9.What is the base class of all web forms?

Ans : System.Web.UI.Page .

10.Can we force the garbage collector to run?

Ans : Yes, using the System.GC.Collect(), the garbage collector is forced to run in case required to do so.

11.What does the virtual keyword in C# mean?

Ans : The virtual keyword signifies that the method and property may be overridden.

12.Whats the difference between web.config and app.config?

Ans : Web.config is used for web based asp.net applications whereas app.config is used for windows based applications.

13.What is the difference between a session object and an application object?

Ans : A session object can persist information between HTTP requests for a particular user, whereas an application object can be used globally for all the users.

14.Is it possible to perform forms authentication with cookies disabled on a browser?

Ans : No, it is not possible.

15.Which control has a faster performance, Repeater or Datalist?

Ans : Repeater.

16.What technique is used to figure out that the page request is a postback?

Ans : The IsPostBack property of the page object may be used to check whether the page request is a postback or not. IsPostBack property is of the type Boolean.

17.How can we force a thread to sleep for an infinite period?

Ans : Call the Thread.Interupt() method.

18.What’s the difference between Response.Write() andResponse.Output.Write()?

Ans : Response.Output.Write() allows you to write formatted output.


19.Describe the difference between inline and code behind.

Ans : Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

20.What is the lifespan for items stored in ViewState?

Ans : Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

21.What is PostBack & Callback?

Ans : One technique that current ASP.NET 1.0/1.1 developers use to overcome this postback problem is to use the Microsoft XMLHTTP ActiveX object to send requests to server-side methods from client-side JavaScript. In ASP.NET 2.0, this process has been simplified and encapsulated within the function known as the Callback Manager. The ASP.NET 2.0 Callback Manager uses XMLHTTP behind the scenes to encapsulate the complexities in sending data to and from the servers and clients. And so, in order for the Callback Manager to work, you need a web browser that supports XMLHTTP. Microsoft Internet Explorer is, obviously, one of them.

22.What is singlecall and singleton ?

Ans : Differneces between Single Call & Singleton. Single Call objects service one and only one request coming in. SingleCall objects are useful in scenarios where the objects are required to do afinite amount of work. Single Call objects areusually not required to store state information, and they cannot hold state information between method calls. However, SingleCall objects can be configured in aload-balanced fashion.

Singleton objects are those objects that service multiple clients and hence share data by storing state information between client invocations. They are useful in cases in which data needs tobe shared explicitly between clients and also in which the overhead of creating and maintaining objects is substantial.

23.What is Machine.config File ?

Ans : As web.config file is used to configure one asp .net web application, same way Machine.config file is usedto configure application according to a particular machine. That is, configuration done in machine.configfile is affected on any application that runs on a particular machine. Usually, this file is not alteredand only web.config is used which configuring applications.

24.What debugging tools come with the .NET SDK?

Ans : 1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.

2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.

25.What does assert() method do?

Ans : In debug compilation, assert takes in a Boolean condition as a parameter, and shows the errordialog if the condition is false. The program proceeds without any interruption if the conditionis true.

Author: ngocbd
• Tuesday, December 30th, 2008

1.What method do you use to explicitly kill a users session?

Ans : Syntax: Session.Abandon()

Note : The Abandon method destroys all the objects stored in a Session object and releases their resources.If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.

2.What methods are fired during the page load?

Ans : Init() ,Load(),PreRender(),Unload().

3.What data type does the RangeValidator control support?

Ans : Integer,String and Date.

4.Which method do you invoke on the DataAdapter control to load your generated dataset with data?

Ans : Fill() method.


5.Which control would you use if you needed to make sure the values in two different controls matched?

Ans : CompareValidator Control


6.What base class do all Web Forms inherit from?

Ans : The Page class.

7.Explain the differences between Server-side and Client-side code?

Ans : Server-side code executes on the server. Client-side code executes in the context of the clients’ browser.
8.do you store the information about the user’s locale?

Ans : System.Web.UI.Page.Culture

9.Can you edit data in the Repeater control?

Ans : No, it just reads the information from its data source.

10.Which template must you provide, in order to display data in a Repeater control?

Ans : ItemTemplate.

11.How can you provide an alternating color scheme in a Repeater control?

Ans : AlternatingItemTemplate.

12.Name two properties common in every validation control?

Ans : ControlToValidate property and Text property.

13.Is String is Value Type or Reference Type in C#?

Ans : String is an object (Reference Type).

14.What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?

Ans : Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client’s browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user’s browser to another page or site. This performas a trip back to the client where the client’s browser is redirected to the new page. The user’s browser history list is updated to reflect the new address.

15.What is the Global.asax used for?

Ans : The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

16.How many classes can a single .NET DLL contain?

Ans : It can contain many classes.


17.What is portable executable (PE)?

Ans : The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.


18.What is strong name?

Ans : A name that consists of an assembly’s identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly.


19.What is Code Access Security (CAS)?

Ans : CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running. For example, it is CAS that will prevent a .NET web applet from formatting your hard disk.

20.What are the different types of assemblies?

Ans : Private, Public/Shared, Satellite

21.Which namespace is the base class for .net Class library?

Ans : system.object

22.How do you create threading in .NET? What is the namespace for that?

Ans : System.Threading.Thread .


23.What is the difference between ref & out parameters?

Ans : An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.


24.What are indexers?

Ans : Indexers are similar to properties, except that the get and set accessors of indexers take parameters, while property accessors do not.

25.What are the access-specifiers available in c#?

Ans : Private, Protected, Public, Internal, Protected Internal.

Chôm từ : fordevs.com

2/9/09

TRÊN ĐỈNH DRAN


Nếu muốn chọn một tour du lịch nội địa tuyệt vời nhất trong mùa xuân này, hãy chọn Đơn Dương - Dran - Đà Lạt. Mời bạn cùng chúng tôi du xuân trên hai ngọn đèo tuyệt đẹp này…

Dran là thị trấn huyện lỵ Đơn Dương trước kia. Từ Đơn Dưong có hai hướng lên được thành phố hoa Đà Lạt: hướng đi qua ngã ba Phi Nôm, qua đèo Prenn; hướng qua đèo Dran, qua Cầu Đất - một địa danh rất nổi tiếng, còn cao hơn cả Đà Lạt, nơi nhà thám hiểm - bác sỹ A. Yersin - người khám phá ra Đà Lạt đã từng trồng thử nghiệm cây canh - ky - na để chế biến thuốc trị bệnh sốt rét.

Phóng túng và lãng mạn

Năm 1978, lần đầu tiên tôi đến Đà Lạt từ hướng Nha Trang. Chiếc Peugeot cũ kỹ dùng để chở khách chạy mệt mỏi từ thung lũng Ninh Sơn thuộc tỉnh Ninh Thuận ì ạch leo đèo Ngọan Mục. Đến thị trấn Đơn Dương xe vượt đèo Dran lên Đà Lạt. Khi ấy hai ngọn đèo Ngoạn Mục và Dran đã cuốn hút tôi. 10 năm sau Đà Lạt trở thành quê hương thứ 2 của tôi và tôi nhận ra đó là những miền cảm hứng bất tận mà thiên nhiên hào phóng tặng cho Cao nguyên Langbian. Và mùa xuân này, Ngoạn Mục và Dran, một lần nữa làm tâm hồn tôi ngất ngây khi được đặt chân lên những thảm cỏ xanh mát lạnh ven đèo, ngắm nhìn những ngọn núi hùng vĩ chìm dần trong chiềc xanh thẫm…


Đèo Ngoạn Mục với cảnh quan đa dạng và bí ẩn.Ảnh: VDT


Từ thị trấn Tân Sơn của huyện Ninh Sơn, bạn đã hình dung ra sự “ngoạn mục” của đèo Ngoạn Mục, khi nhìn thấy hai đường ống dẫn nước sáng loáng của Nhà máy thủy điện Đa Nhim như từ trên trời đổ xuống. Đường lên đèo, thỉnh thoảng xe bạn chui dưới hai đường ống dẫn nước thủy điện, lao vào những khu rừng gìa như có từ ngàn năm. Những khúc cua “chết người” và những độ dốc dựng đứng cho bạn biết thế nào là đèo “Ngoạn Mục”.
Nhưng thú vị nhất là sự thay đổi thời tiết, càng lên cao không khí càng dịu mát. Những ngọn gió càng phóng túng và lãng mạn, lồng ngực bạn thoải mái hít thở không khí trong lành, dịu mát của rừng, của núi, của mây. Gần hết đèo Ngọan Mục, một vài cây thông xuất hiện, như báo hiệu cho bạn biết cách đó không xa là Đà Lạt thông reo.
Hết đèo Ngoạn Mục là đến thị trấn Đơn Dương, một thị trấn bé nhỏ và hiền dịu đến nhu mì. Những quán cà phê yên tĩnh, cô độc; những vườn cà chua “trái hồng như trái ngực”; những vườn hồng trơ cành vào mùa đông, trĩu quả vào hạ; những vườn rau thơm ngát, xanh rì; những thiếu nữ má hồng như những quả cà chua mới ửng chín, khép nép trong những chiếc áo lạnh hờ hững...
Có nhiều thời gian sống ở thị trấn nhỏ bé này, tôi vẫn chưa hiểu hết về Đơn Dương. Nhưng có thể hình dung nó như là một cô gái dậy thì vào buổi sáng; một nàng tiên nữ thuần khiết và kiêu hãnh khi chiều xuống. Sự thuần khiết và kiêu hãnh đó chinh phục bạn đến cuồng si. Nhạc sĩ Trịnh Công Sơn có thời kỳ dạy học ở B’lao cũng rất mê Đơn Dưong, Ka Đô- một thị trấn cũng gần với Đơn Dương. Một số bài tình ca của ông đã ra đời ở đây, bên cạnh cây ghi-ta bập bùng làm núi rừng thêm hoang vu.
Thời tiết ở Đơn Dương cũng hết sức lạ lùng, buổi chiều tối và sáng sớm mùa đông thì giá rét, rét chịu không nổi, giống như cái rét Hà Nội mùa đông, nhưng đến trưa lại nồng ấm đến vô cùng, đó là thời tiết đặc trưng của miền thung lũng ở độ cao gần 1.000 mét.
Một đêm ở Đơn Dương bên ly rượu, ngắm sao trời trong vắt; buổi sáng tinh mơ bên ly cà phê đen, bạn đủ trầm tĩnh để hiểu về cái thị trấn đặc biệt này, vì sao nó chinh phục được bạn.

Dran hút hồn

Đèo Dran nối liền Đơn Dưong với Trạm Hành, Trại Mát, Cầu Đất, Xuân Thọ, Xuân Trường, để đến Đà Lạt. Thực chất đèo Dran chỉ dài hơn 10 km, từ thị trấn Đơn Dương đến Cầu Đất - điểm được coi là cao hơn cả Đà Lạt. Từ Cầu Đất, đèo Dran bắt đầu đổ đèo xuôi về Đà Lạt. Đây là vùng đất cũng hết sức đặc biệt, mà A. Yersin gọi là “Langbian nhỏ” trong lần thứ 3 chinh phục Langbian năm 1893.
Thời Pháp thuộc, vượt qua đèo Dran là con đường chính để đến Đà Lạt từ hướng Ninh Thuận, sau này người ta khai thông con đường qua Thạnh Mỹ - ngã ba Phi nôm để lên đèo Prenn đến Đà Lạt, làm cho con đường đèo Dran trở nên hoang phế. Nhưng chính sự hoang phế này tạo nên một sức hút khác, sức hút của sự hoang sơ của núi đồi “Langbian nhỏ”.
Đèo Dran ngắn nhưng cực kỳ hiểm trở với những khúc cua không tưởng. Những rừng thông bạt ngàn, gìa cỗi như có tự bao giờ chìm lẩn khuất trong mây. Du khách có thể “sờ” được mây, được sương, bởi mây và sương luôn bất chợt hiện ra lúc ở giữa lưng chừng đèo, lúc ở đỉnh đèo, như muốn ôm bạn vào lòng. Cứ mỗi km vượt đèo Dran, bạn như đang đi thẳng vào xứ sở ôn đới, bởi nhiệt độ thay đổi rất nhanh chóng, chẳng bao lâu bạn chìm trong khí hậu lạnh mát của Đà Lạt.
Đặc biệt ở Cầu Đất, nếu tiết trời đang xuân, bạn có thể hưởng cái lạnh khỏang 4-5 độ C vào ban đêm hoặc sáng sớm. Đó là cái lạnh trong ngần, hoang dã, tinh khiết trong thoang thỏang hương chè bạt ngàn, xanh rì từ những nông trường chè bất tận. Một ly rượu canh -ky - na làm buổi tối Cầu Đất ấm lại; một ly cà phê đen buổi sáng, làm tan sương đặc quánh bên quán nhỏ ven đồi, bạn mới hiểu rằng vì sao Cầu Đất từng thu hút người Pháp đến vậy.
Chính con đường này A. Yersin đã đi trong lần thứ 3 thám hiểm Langbian. Ở đó ông gặp bộ tộc người Lat bên dòng suối xanh biếc. Ông gặp một cảnh quan huyền diệu của “Langbian nhỏ” và chợt nhớ đến câu ngạn ngữ Latin: “Dat Aliis Laetitian Aliis Temperriem” (cho người này niềm vui, cho người khác sự mát dịu). Như một sự tình cờ, 5 chữ đầu tiên của câu ngạn ngữ có 5 từ kia ghép lại thành DALAT!
Đến Cầu Đất, bạn nên biết về cây chè ở đây. Nó mới làm nên thương hiệu trà Lâm Đồng. Những cây chè cổ thụ, có tuổi trăm năm vẫn còn. Những nông trang chè xanh mướt, hình ảnh những người công nhân lặng lẽ hái che trong sương xanh tịch đến vô ưu.

Chiều sâu Dran

Dọc tuyến du lịch này, bạn có thể tắm mình trong thiên nhiên nếu biết cách tổ chức và thưởng thức nó, bằng những cuộc picnic nho nhỏ vài ba ngày với bạn bè hoặc người thân trong gia đình. Dọc đèo Ngoạn Mục vô cùng bình yên, bạn có thể hạ trại. Dọc đèo Dran cũng vậy, hoàn toàn yên tĩnh và tinh anh, cái tinh anh của đất trời buổi sáng, buổi chiều và khi màn đêm buông xuống, để bạn không phải bị chi phối bởi bất kỳ điều gì ngoài lắng nghe tiếng nói của thiên nhiên.
Mùa xuân, bạn có thể ngắm hoa đào Cầu Đất, Trạm Hành. Những cây đào cổ có tuổi gần năm, hoa chi chít, màu hồng quí phái, thân đào như có hoa văn của thời gian. Hoa cà phê trắng tinh anh, ngọt ngào khoe sắc bên trong những khu vườn nhà yên tĩnh. Những đóa dã quỳ khoe sắc vàng rực rỡ bên đường làm bạn nao lòng.
Và còn nữa: những ngôi nhà gỗ trong sương. Hầu hết cư dân ở vùng đất này đều sống trong những ngôi nhà làm bằng gỗ thông nghe như nhựa thông tỏa mùi ấm áp. Tôi thích ngắm những làn khói xanh trong màu lam chiều Cầu Đất, Trạm Hành…Những làm khói ấy làm cho người lữ khách cô đơn như càng cô độc hơn, nó làm bạn thấy cuộc hành trình ấy thi vị biết chừng nào. Ở đó còn có những người con gái cao nguyên hiền lành nhưng phảng phất vẻ bí ẩn của những đóa dã quỳ cuồng dại, đa tình…
Chiều sâu của Dran là bất tận như đỉnh Langbian huyền diệu, như những ngọn gió phóng túng thổi ào ạt, bất tận trên cao nguyên huyền bí, ẩn chứa những điều hư huyền nhưng rất thực. Chiều sâu ấy thúc giục người lữ khách lên đường…

2/7/09

4 CD hòa tấu Phong-Hoa-Tuyết-Nguyệt Cực Đỉnh



Một câu chuyện kể rằng :Vào một đêm trăng sáng, trong cái lạnh giá của mùa đông trên núi, có gió, có hoa thơm cỏ lạ và tuyết rơi.một lữ khách phiêu bạc giang hồ, hình như ông ta bị bệnh rất nặng và đi ẩn náu trên núi.

Mùa đông lạnh lùng và tàn nhẫn , dường như nó chẳng cho fép bất cứ cái gì tồn tại song song với nó...Trong tiết trời lạnh lẽo ông lão rât cô đơn , ông bỗng nhớ đến người yêu ngày xưa,... vì định mệnh đã ko cho phép ông lão cũng bà ấy đc ở bên nhau... nhưng trong lòng ông lão ấy chưa bao giờ nguôi thương nhớ người ấy. Rồi ông lão tự lầm nhẩm 1 mình rằng " phải chăng cuộc đời quá ngắn ngủi để thưởng thức Phong _Hoa_Tuyết_Nguyệt"

Cùng lúc đó, 1 vị lữ hành đi ngang qua thoáng nghe câu chuyện của ông lão tội nghiệp, anh ta đã dùng cây sáo của mình hòa tấu lên 1 bản trong tứ tuyệt của Phong, Hoa, Tuyết, Nguyệt...và nói với ông lão rằng "Hãy Trân Trọng Những Gì Đang Có"....

一、风 - CD1 Phong


1.风的传说 - Lời của gió
2.你是风儿我是沙- Em là gió, anh là cát
3.风含情水含笑- Gió hữu tình, nước hữu tình
4.伤心雨 - Mưa buồn
5.蒙娜丽莎的眼泪-- Mona Lisa's tears
6.一场游戏一场梦-- Một giấc mơ, một trò chơi.
7.别亦难-- Lời biệt ly
8.片片枫叶情-- Tình xanh
9.一千个伤心的理由-- Một vạn lý do để thương tâm.
10.任逍遥-- Bay lên
11.恋恋风尘-- Gió bụi lưu luyến
12.亲密爱人-- Người yêu dấu
13.流浪歌-- Khúc lưu luyến
14.天空-- Thiên không
15.梦驼铃—Mộng thiên lý

Phong ko chỉ là gió mà nó cũng là tiếng lòng là tiếng thở than tiếng hòa âm theo từng nhịp khúc của đất trời.Nghe bộ tấu Phong này ta như cảm thấy gió cũng có lúc vui đùa gào thét lúc giận hờn,cũng có tâm hồn như chính con người.Phải chăng âm nhạc lại có sức hút kỳ diệu đến vậy,các bạn thử nghe xem

Lời Của Gió
Thăng Trầm
hàng phi lao hòa âm trong gió thoảng
gió xoay cành lá phím thử hợp âm
nghe vi vu hoang loãng sóng ngân thầm
reo vi vút nhạc tấu cùng trổ khúc

buồn réo rắt tiếng sầu như lá rớt
buồn hắt hiu như tiếng gió than thầm
buồn tái tê như đêm mưa gió gảy
lạnh cung đàn phiền muộn lá rụng rơi

gió hôm nay điểm giao mùa trở lạnh
thổi vào hồn nghiêng ngả tiếng tiêu ngân
gió len qua ru sầu vang điệp khúc
dư âm còn vọng tiếng gió chơi vơi

vol1.Phong
http://www.mediafire.com/?yvmh0mx8zyk
http://www.mediafire.com/?jshmsyno4vz
or
http://www.rapidspread.com/file.jsp?id=o7ckzrm0w8
http://www.rapidspread.com/file.jsp?id=tum9gncigp

二、花 - CD2 Hoa

1.我等到花儿也谢了-- Em sẽ đợi đến khi hoa tàn.
2.雨蝶-- Cầu vồng
3.花祭-- Hoa tàn
4.山茶花-- Trà hoa nữ
5.羞答答的玫瑰静悄悄的开-- Nụ hồng mới nở
6.花好月圆-- Trăng tròn hoa đẹp.
7.我是一片云-- Em là áng mây.
8.蓝蓝的天蓝蓝的梦-- Trời xanh mộng đẹp.
9.故乡的云-- Nhớ thôn xưa
10.念念不忘的情人-- Không bao giờ quên em
11.朋友-- Bạn hữu
12.情人-- Người tình
13.驿动的心-- Con tim rung động.
14.变心的翅膀-- Đôi cánh tình yêu.
15.梦里水乡-- Mộng quê hương.
Thời xưa người ta thường coi Hoa như là một hình ảnh của người phụ nữ-yếu ớt và rung rinh trước gió.Vì thế hoa cũng như người con gái có lúc khoe sắc rực rỡ lại có lúc héo tàn ,có lúc lại như tiếng lòng thổn thức người phụ nữ khi rơi lệ."Người buồn cảnh có vui đâu bao giờ",người ta ko chỉ ngắm hoa mà còn nghe Hoa lắng nghe tiếng nói từ trong cõi lòng của Hoa có như thế mới thưởng thức được hết cái đẹp của nó.Bộ tấu Hoa này âm thanh uyển chuyển,rộn ràng thật khiến người ta phải đắm say Hãy nghe và thưởng thức nó.

Trích bài Đào hoa hành
Tào Tuyết Cần
Này người đẹp hoa tươi là thế,
Sao hoa tươi mà lệ vẫn rơi?
Đem hoa ví với lệ người,
Lệ tuôn lã chã hoa cười lả tơi.
Xem hoa mai lệ vơi vơi cạn,
Lệ cạn rồi xuân chán hoa buồn,

Hoa buồn người cũng héo hon,
Hoa bay, người lả, chiều hôm còn gì?
Tiếng quyên bỗng gọi xuân đi,
Rèm này lặng lẽ trăng kia lờ mờ!

vol2.Hoa
http://www.mediafire.com/?0mlloysoatv
http://www.mediafire.com/?ybydgmt4zkd
or
http://www.rapidspread.com/file.jsp?id=socswdqerx
http://www.rapidspread.com/file.jsp?id=vdloxxqceq

三、雪 - CD3 Tuyết


1.雪中情 -- Tình trong tuyết
2.你那里下雪了吗-- Nơi ấy tuyết có rơi không em?
3.爱如潮水 -- Tình tựa sông nước.
4.冬雨-- Mưa đông
5.快乐老家-- Hạnh phúc quê nhà
6.雪地上的回忆-- Hồi ức mưa tuyết
7.尽在不言中-- Không nên lời
8.我愿意-- Em chấp nhận
9.明明白白我的心-- Thấu hiểu tình anh.
10.心灵之约 -- Liều thuốc cho trái tim.
11.冬天里的-- Đông chí
12.狼-- Sói
13.爱的承诺-- Tình yêu đã qua
14.似曾相识-- Thân thương.
15.想说爱你不容易 -- Muốn nói yêu em nhưng thật khó.
Thưở xưa Tuyết đã là đề tài vô tận cho các thi nhân đối ẩm vì tuyết đẹp,tuyết lạnh và tuyết khiến con người ta gần nhau hơn.Không có gì thú vị hơn ngồi uống rượu ngắm trời tuyết từng bông tuyết rơi trắng xóa lả tả cả 1 góc trời khiến nỗi lòng con người càng thêm đậm đà hơn.

Nhớ khi xưa Tống Thái Tổ đến thăm đại thần quân cơ Triệu Tấn-khai quốc công thần của triều Tống.Đó cũng là trong một ngày tuyết trắng xóa ,kín cả mặt đường cảnh vật ko gian như mờ ảo đi.Triệu Tấn hôm đấy thấy trời cũng đã tối lắm rồi ông đã vào phòng chuẩn bị đi ngủ thì được người nhà vào báo có Thái tổ đến.Ông vội vàng ko kịp thay quần áo ra đón vua thì thấy khắp người vua là một mầu trắng xóa chỉ còn trên khuôn mặt một nụ cười rạng ngời.Thật đúng là tình cảm "vua tôi gắn bó thân mật ko gì sánh tỏ" và chính khung trời tuyết hôm đó đã là cảm hứng cho câu truyện lịch sử này lưu truyền trong dân gian đến muôn đời sau.

vol3.Tuyet
http://www.mediafire.com/?dfwdvm5imat
http://www.mediafire.com/?560nsgwmrse
or
http://www.rapidspread.com/file.jsp?id=lvtwso0upw
http://www.rapidspread.com/file.jsp?id=5mcl8yddww

四、月 - CD4 Nguyệt

1.你看你看月亮的脸 -- Em tựa trăng rằm
2.如果云知道-- Nếu mây hiểu được
3.月亮若的祸 -- Trăng rơi
4.月亮走我也走-- Em đã ra đi cùng vầng trăng đêm.
5.明月千里寄相思-- Nguyệt tình
6.白天不懂夜的黑-- Không hiểu tình em.
7.孤枕难眠-- Đêm dài mất ngủ
8.相约到永久-- Tình yêu vĩnh cửu
9.爱情的故事-- Câu chuyện tình yêu
10.梦醒时分 -- Tỉnh mộng
11.让我一次爱个够 -- Để anh một lần có em.
12.忘记你我做不到-- Anh không thể quên em.
13.今夜你会不会来--Hãy đến bên anh đêm nay.
14.月亮船 -- Thuyền trăng.
15.糊涂的爱 -- Tình yêu bươm bướm.

Nghe Nguyệt người ta thường liên tưởng đến trăng và trăng cũng là cảm xúc cho bao thi nhân phóng bút.Cuộc đời cũng những lúc vui buồn sinh ly tử biệt cũng như vầng trăng kia có lúc tròn,khuyết.Vì thế những khi buồn người ta thường nhìn lên trời để ngắm vầng trăng kia đang tỏa sáng tìm trong đó một sự sẻ chia tâm sự.

Trăng trên trời có khi tròn khi khuyết
Người ở đời ai khỏi kiếp gian nan

Buồn đấy vui đấy rồi cũng như bọt bèo mà thôi.Hãy cùng album Nguyệt này sẻ chia giãi bày những tâm sự của bạn.Biết đâu bạn sẽ tìm thấy trong đó một điều thú vị thì sao

vol4.Nguyet
http://www.mediafire.com/?4fmfd4uibbg
http://www.mediafire.com/?46qiul00ni3
or
http://www.rapidspread.com/file.jsp?id=cf25hqlvij
http://www.rapidspread.com/file.jsp?id=vi0ag7ziwy

2/4/09

Installing Lighttpd With PHP5 And MySQL Support On OpenSUSE 11


Version 1.0
Author: Falko Timme
Last edited 09/01/2008

Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on an OpenSUSE 11 server with PHP5 support (through FastCGI) and MySQL support.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

2 Installing MySQL 5.0

First we install MySQL 5.0 like this:

yast2 -i mysql mysql-client

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

chkconfig --add mysql
/etc/init.d/mysql start

Now check that networking is enabled. Run

netstat -tap | grep mysql

In the output you should see something like this:

server1:~ # netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 8566/mysqld
server1:~ #

If you don't see a line like this, edit /etc/my.cnf, comment out the option skip-networking:

vi /etc/my.cnf

[...]
#skip-networking
[...]

and restart your MySQL server:

/etc/init.d/mysql restart

Run

mysqladmin -u root password yourrootsqlpassword

to set a password for the user root@localhost.

As you've seen in the netstat output, MySQL is not only listening on localhost, but on all interfaces, which means it can be accessed from the outside. Therefore we need to set a password for the user root@server1.example.com as well. But there's one little problem: most likely the Host column in the mysql.user table doesn't contain server1.example.com, but server1. We will change that now, and afterwards we will set a MySQL password for the user root@server1.example.com.

Let's connect to MySQL:

mysql -u root -p

Type in the password for the MySQL root user. Then, on the MySQL shell, do this:

mysql> USE mysql;

mysql> SELECT * FROM user;

The output could look like this:

+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | root | *5172022923C5A97E5A842DA249B93473314416D5 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| server1 | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| 127.0.0.1 | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
3 rows in set (0.00 sec)

As you see, in the second row, it reads server1 instead of server1.example.com in the Host column. Let's replace that with server1.example.com:

mysql> UPDATE user SET Host = 'server1.example.com' WHERE Host = 'server1';

mysql> FLUSH PRIVILEGES;

We can leave the MySQL shell now:

mysql> quit;

Now back on the normal shell, we can set the MySQL password for the user root@server1.example.com:

mysqladmin -h server1.example.com -u root password yourrootsqlpassword

3 Installing Lighttpd

Lighttpd is available as an OpenSUSE package, therefore we can install it like this:

yast2 -i lighttpd

Then we create the system startup links for Lighttpd (so that Lighttpd starts automatically whenever the system boots) and start it:

chkconfig --add lighttpd
/etc/init.d/lighttpd start

Now direct your browser to http://192.168.0.100, and you should see that Lighttpd delivers a page (well, it's a 404 page because there's no index file in Lighttpd's document root, but at least this means that Lighttpd is working ok):

Lighttpd's default document root is /srv/www/htdocs on OpenSUSE, and the configuration file is /etc/lighttpd/lighttpd.conf.

4 Installing PHP5

We can make PHP5 work in Lighttpd through FastCGI. There's a FastCGI package for PHP5 available on OpenSUSE, php5-fastcgi, which we install like this:

yast2 -i php5-fastcgi

5 Configuring Lighttpd And PHP5

To enable PHP5 in Lighttpd, we must modify three files, /etc/php5/fastcgi/php.ini, /etc/lighttpd/modules.conf, and /etc/lighttpd/conf.d/fastcgi.conf. First we open /etc/php5/fastcgi/php.ini and uncomment the line cgi.fix_pathinfo=1 somewhere in the middle of the file:

vi /etc/php5/fastcgi/php.ini

[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix it's paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
cgi.fix_pathinfo=1
[...]

Then we open /etc/lighttpd/modules.conf and uncomment the line include "conf.d/fastcgi.conf":

vi /etc/lighttpd/modules.conf

[...]
##
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"
[...]

Finally we open /etc/lighttpd/conf.d/fastcgi.conf and make sure that it contains the line server.modules += ( "mod_fastcgi" ); then we comment out the fastcgi.server stanza:

vi /etc/lighttpd/conf.d/fastcgi.conf

[...]
server.modules += ( "mod_fastcgi" )
[...]
## PHP Example
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
##
## The number of php processes you will get can be easily calculated:
##
## num-procs = max-procs * ( 1 + PHP_FCGI_CHILDREN )
##
## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)
##
fastcgi.server = ( ".php" =>
( "php-local" =>
(
"socket" => socket_dir + "/php-fastcgi-1.socket",
"bin-path" => server_root + "/cgi-bin/php5",
"max-procs" => 1,
"broken-scriptfilename" => "enable",
)
),
( "php-tcp" =>
(
"host" => "127.0.0.1",
"port" => 9999,
"check-local" => "disable",
"broken-scriptfilename" => "enable",
)
),

( "php-num-procs" =>
(
"socket" => socket_dir + "/php-fastcgi-2.socket",
"bin-path" => server_root + "/cgi-bin/php5",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000",
),
"max-procs" => 5,
"broken-scriptfilename" => "enable",
)
),
)
[...]

Then we restart Lighttpd:

/etc/init.d/lighttpd restart

6 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /srv/www/htdocs. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /srv/www/htdocs/info.php

    

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, PHP5 is working, and it's working through FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

7 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications:

yast2 -i php5-mysql php5-bcmath php5-bz2 php5-calendar php5-ctype php5-curl php5-dbase php5-dom php5-ftp php5-gd php5-gettext php5-gmp php5-iconv php5-imap php5-ldap php5-mbstring php5-mcrypt php5-mhash php5-ncurses php5-odbc php5-openssl php5-pcntl php5-pgsql php5-posix php5-shmop php5-snmp php5-soap php5-sockets php5-sqlite php5-sysvsem php5-tokenizer php5-wddx php5-xmlrpc php5-xsl php5-zlib php5-exif php5-pear php5-sysvmsg php5-sysvshm

Now restart Lighttpd:

/etc/init.d/lighttpd restart

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

8 Links