Sunday, September 16, 2012

IIS and PHP

It is quite handy to have PHP hook up with IIS server that I can develop PHP applications on a window platform. In this article, I am going to share the integration process and some useful tutorials.

The Specs of my computer

  • Window 7 Ultimate Service Pack 1
  • IIS (Internet Information Service) Version 7.5
  • PHP Version 5.3.17 VC9 x86 Non Thread Safe

1. Download/Install IIS and PHP

If you haven't had IIS server and PHP installed in your computer, ( The way I found I didn't have IIS in my computer is when I search  "iis", "Internet Information Services (IIS) Manager" is not on the list. )
The most handy way is go to http://php.iis.net/ , click on "Install PHP Now",
you will be prompted to download Microsoft Web Platform Installer. Using this installer, as it says, you are able to download "Internet Information Services (IIS), SQL Server Express, .NET Framework and Visual Web Developer" in a easier way.

If you already have IIS ( for example, you had installed ASP.NET development framework in your computer, then it is very likely that you already have IIS), you only need to install PHP
Download/Install PHP for Windows
http://windows.php.net/download/
Download PHP 5.3 VC9 x86 Non Thread Safe Installer is recommended.

2. Enable FastCGI Support in IIS

Start --> Control Panel --> Programs--> Turn Windows features on or off (under Programs and Features)
check CGI (under Internet Information Service --> World Wide Web Services)
























3. Change PHP Settings

After installation of PHP, edit the php.ini file. This file, in my case, is in c:\Program Files (x86)\PHP\

fastcgi.impersonate = 1
fastcgi.logging = 0
cgi.fix_pathinfo=1
cgi.force_redirect = 0

4. Create a handler mapping for PHP

Open IIS Manager (you can search "iis" and select Internet Information Services Manager),
and click on "Handler Mappings"
























Click on Add Module Mapping in the left action panel and filled in the following properties:
  • Request path: *.php
  • Module: FastCgiModule
  • Executable: C:\[Path to PHP installation]\php-cgi.exe
  • Name: PHP_via_FastCGI
Click on Request Restrictions, choose the Mapping tab, check "Invoke handler only if request is mapped to:", and select "File or folder".

  

5.  Launch/Test Web application

So far, the settings for IIS and PHP are finished. If you already has developed some web applications in PHP and you want to test it.

Add Web Application
Open IIS Manager --> right click on "Default web site" in the right connections panel --> choose "Add application" -->type in Alias and choose the Physical path, the directory in which your web pages reside --> click "OK"

Launch Web App
In IIS Manager, click on "Start" in the right actions panel (under the Manager Web Site section)
Then click on "Browse *:80 (http) in the right actions panel (under the Browse Web Site section)
The IIS welcome page appear, type in localhost/your_app_name/*.php

If You don't have web pages to test ......
You can fabricate a phpinfo.php page in the physical directory you set up for the application or 
in the C:\inetpub\wwwroot folder

[Notice] you might not have write permission to the directory C:\inetpub\wwwroot\ , to save a file in that folder, you have to change security properties of it.
The content of phpinfo.php

<?php
phpinfo();
?>

Type in the link to browse the PHP information 
localhost/phpinfo.php or localhost/your_app_name/phpinfo.php


Useful Tools / Tutorials

One tool that you can easily manage your PHP settings (instead of manually editing php.ini) is download PHP Manager for IIS
Which provides an easy way to manage PHP version, settings and install extensions in IIS.

Basically, I follow this tutorial 
"PHP, Microsoft IIS 7.0 and later" as the most important guideline.
http://www.php.net/manual/en/install.windows.iis7.php





----------------------------------
Add notes 2013/6/17
1. You might encounter error messages like "you do not have permissions to view this page" when you try to browse your webpage. Then, you need to change the permission of the folder where your web pages reside.
Right click on the folder, in the "Security" tab, Edit permission and add "IUSR", grant it Read, Execute rights.

2. In installing the PHP, when it asks you "Select the web server you wish to setup", choose "IIS FastCGI"















 

Sunday, February 12, 2012

Linsanity

This article has nothing to do with web technology. It is only a summary of what I read in a latest article about Jeremy Lin from Forbes. The original article is here

Jeremy Lin is an Asian-American, whose parents came from Taiwan. He was born in California and being educated in the USA all his life. His latest performance in NBA arouses a huge attention recently. Watching those video clips, I could not believe my eyes at all. It has been rooted in my heart that Asians is no way compatible with African-American or other America basketball players because of physical conditions. He is really an outlier but he is still shorter compared to other basketball players. To express my admiration for his outstanding basketball skills, and to remind me some of the most important things when odds are not in our side, I take notes from this Forbes article. Though success can not be replicated, but his story still can give us some hints about success.

1. "You've got to believe in yourself, even when no one else does"
2. "You never know when opportunities are going to arise in life. Often, they're when you least expect them"
3. "Before that (got his contract guaranteed by the Knicks), he could have been cut at any time"
4. "You've got to do your best to understand what your strengths are and then ensure that you're in a system( a job or organization or industry) that is a good fit for those strengths"
5. "We put people around us in boxes.....Do you know what your people (or even yourself) is really capable of?"
6. "...you find what your're good at and do it". "Always be a first-rate version of yourself. Instead of a second-rate version of somebody else"
7. "Stay humble"
8. "When you make others around you look good, they will love you forever. ...They (the Knicks players) are all working harder to share the ball with others. And it's beautiful to watch".
9. "Never forget about the importance of luck or fate in life."
10 ."There are not short cuts to hard work. Success is a by product of that. ....You can only control what you control".

All these words are extracted from the article "Just Lin, Baby! 10 Lessons Jeremy Lin can teach us......."

Monday, February 6, 2012

work recently

Recently I have been working on a customized production / inventory management system, utilizing techniques such as PHP, MySQL and JavaScript. By working on this project, accumulates my knowledge and skills in web development. There is nothing fancy here. Since this is an internal website, users are employees inside the company, which provide me a good chance to work closely with them and get immediate feedback. Most of the time, users come with their need and their thoughts about the platform. I am very glad to see that, a very small change to the page can greatly improve their work efficiency. It is also not uncommon that we need to fix bugs reported, to add a supervisor's sign off before processing further,... etc maintenance work.

For example, users are asking a features on a daily-use list to add on a check box for each item they are working on, which flags the item as problematic or not. This simple job facilitates the work around the co-workers in that team and supervisors can review the list to take the next step. We utilize an ajax request and make changes to the HTML DOM element using javascript, to give users an immediate response upon users checking the box.

Or we create a dashboard for information sharing among different teams. For example, different teams need to take actions after the ball entering into their court. Earlier, they are using emails to communicate the current status, which is less efficient and a waste of man power. We keep track of the status every time a critical action is taken and update the status on the dashboard and sending out system notifications to related teams.

These plain tasks streamline the process, cut off unnecessary work and increase people's performance.

Wednesday, July 13, 2011

A reading summary of Android Dev Fundamentals

A reading summary of Android Dev Fundamentals
Android -- Linux, multi-user OS and middleware, key applications
support : 2D, 3D graphics, SQLite, webkit browser

A application is composed of one or more different components.
Components: Service, Activity, Content Provider, Broadcast Receiver
Manifest file: must declare all components in the application, minimun version of Android required, hardware required.
Non-code application resources (images, layout files, strings) should include alternatives for different device configuration (such as different layout files for different size of screen)

Activity: a single screen with a user interface

A example to illustrate activities

Service: work in the background, perform long-running operations or fetch data over the network ex: playing music in the background, doesn't provide an interface


Content Providers: manage a shared data for applications, Ex: a content provider which manage user's contact information


Broadcast Receivers: a component that responds to system-wide broadcast announcements.
announcements can be originated from system or application. it doesn't display a user interface, but may
create a status bar notification. Broadcast receivers are activated by an asynchronous message called Intent

Activation of components

Intent: An asynchronous message defines an action for a specific (or specific type ) of components to perform.
bind individual components to each other at run time. Ex: convey a request to show an image or to open a web page.



The Content Resolver handles all direct transactions with the content provider






Resources
images, audio files anything related to the visual presentation of the application. Define animations, menus, styles, colors and the layout of activity user interface with XML. Provide resource separate from your code and provide alternative resources for different device configurations. qualifier for alternative resource: a short string that you include in the name of your resource directories in order to define the device configuration.








Saturday, July 9, 2011

HTML5

A reading summary of "HTML5: Up and Running" by Mark Pilgrim
New HTML5 features:
(1) new semantic elements
<section> <nav> <article> <aside> <hgroup> <header> <footer> <time> <mark>
<nav> for navigation, <hgroup> for h1,h2,...
<time datetime="2009-10-29" pubdate>Oct 29,2009 </time>
if you want to include time
<time datetime="2009-10-29T13:59:59-04:00">
04:00 -- time zone offset
pubdate means one of two thigns if the time is in an article, it means the publication date of the article,
else it's the publication date of the entire document

(2) Canvas
(3) Video
"there is no single combination of containers and codecs that work with all HTML5 browsers, (this situation) is not likely to change recently". "You may need to encode your video more than once to make your video watchable across all browsers"
containers means the formats of the video, such as MPEG,... codec = coder + decoder,
Fireogg -- a firefox extension for encoding video to ogg format, ogg is a one kind of container which is acceptable in many browsers.
(5) geolocation API
which lets you to share your location with trusted website
(6) local storage
provides a way for wesites to store information in your local side computer. the concept is similar to cookies, but cookies is much smaller in size."cookies are limited in size and browsers send them back to the web server every time it requests a new page". Web sites can only access its own values which are stored in the local storage.
(7)Add many Input types 
<input type="password" ...>
there are many other types like:
"search" -- search box
"number" -- spin box
"range" -- sliders
"color" -- for color pickers
"tel" -- for telephone numbers
"url" -- for www address
"email", "week", "day", "month", "time"(time stamps), "datetime", "dateitmelocal"
Automatic validation of input files for email, numbers and www address
(8)Web workers
provide a way for javascripts to run in background as like multiple threads
(9)Offline web applications
such as using google doc offline, cashed the updated results in the local side and update with the server side when connect to the remote server. the web application need to have a cache ability.
(10) placeholder text
"when the input box is not in focus, put the place holder text in the input field, as soon as you click on the input field, the placeholder text disappears"
(11) Auto focus
Browser support auto focus to a text field ('input') which was supported by javascript, it moves focus to a particular input field using mark-up instead of script


Modernizr: A HTML5 detection javascript library that detects support for HTML5 and CSS3 feature
Ex: Modernizr.canvas -- if the browser support canvas
Modernizr.canvastext -- if the browser support canvas text
Modernizr.localstorage -- if the browser support local storage
Modernizr.inputtypes.date -- if the browser support date as an input type

without Moderizer:
if(!!document.createElement('canvas').getContext()) return;
when you create element like canvas, if your browser support canvas then the DOM object will have a canvas element and the element will have 'getContext()' method, else the element will only have common properties.

i = document.createElement("input")
i.setAttribute("type","date")
return i.type != text

check the browser's support for placeholder text
i = document.createElement("input")
return 'placeholder' in 'i'
or Modernizr.input.placeholder

if(Modernizr.geolocation){
navigator.geolocation.getCurrentPosition(show_map);
}else{
}
navigator is a javascript global object
show_map: call back function

Other resources: HTML5 Demos and Examples

Tuesday, May 17, 2011

Project Notepad



I found myself keep having an impulse to take notes on whatever little tricks or
usage of important commands when I was developing applications. However, I didn't know if there is a good way to keep track of the developing process. Of course, writing a blog or a twit may help me to some extent. But, after all, they are not designed for the purpose. I want a simple application, which can record a small piece of command or code, some description for that command, and allow me to search quickly after. I often got into a problem that I was looking for same piece of information over and over again. And don't know if I have taken notes for it somewhere (in my notebook? or in some small piece of paper?) I didn't try to find a killer application to solve my problem, since I think this application is so easy that I can make by myself.

Therefore, I created a small application called "Project Notepad" using PHP+MySQL.
In order to practice Ajax and Javascript, so I used much of them as well.
In "Project Notepad", I can create, delete projects, create, delete, search memos by tags. Each memo is comprised of three elements: command, description and tags.
Tagging facilitate the searching afterwards.
The reason why I used PHP is because I want to use it in my computer and so far as I know the PHP interpreter can hook on the IIS server of Window7, so I can execute the application in my local host. Secondly, PHP is handy in developing such a small applications.

I spend some time in layout and design. I found a very handy tool in arranging colors:
ColorSchemeDesigner
It provides me a set of primary, secondary and complementary colors based on the hue,saturation,brightness and contrast I selected. I used colors from the suggested set of colors and build a nice-looking website quickly.

Here is my application:
Project Notepad

Some work still needs to be done. For example, providing a log-on/in mechanism, then more people can use it and export the memos in xml,text file then users can make a backup in their local machine. At the current moment, it meets my needs well :)

Update

The registration system was done! Now it allows multiple users :)
Give it a try and give feedback or report bugs at the bottom link of "report bugs" :)

Tuesday, April 5, 2011

Rails3 + GeoKit (part I)

GeoKit is a great plugin by Andrew Lewis, which can calculate distance between two points on the earth, search points in your database within a specified distance from an origin, geocoding from multiple providers (convert address to (lat,lng) or vice versa),and find the city,lat,lng of an IP address. Clear explanations: here
Since I am using Rails3, I can not use the old plugin of Geokit. I found many tutorials on how to install Geokit, but most are for the previous version.
Here is page of the new version of Geokit for Rails3. this, However, not all the functions in the old version of Geokit has been updated.

Follow the installation guide

1. put this line gem 'geokit-rails3' in the Gemfile
2. execute bundle install

Then the installation is done

In the code, add acts_as_mappable to an ActiveRecord::Base

class Location < ActiveRecord::Base
acts_as_mappable
end

Then in a controller, you can play with it.
geoencoing example:

@res=MultiGeocoder.geocode('6224 5th Ave. Pittsburgh, PA')
@rev=GoogleGeocoder.reverse_geocode([40.4527037, -79.9219421])

In the view
The (lat,lng) of 6224 5th Ave. Pittsburgh, PA
lat : <%=@res.lat%>
lng : <%=@res.lng%>
The address of
(lat,lng) = (40.4527037, -79.9219421)
<%=@rev.full_address%>


GeoKit for Rails3
GeoKit for previous Rails