02 April 2012

Continued... PHP and nginx

Tonight I try to resume what I left yesterday: setting up php with nginx. I try to follow http://wiki.nginx.org/PHPFastCGIOnWindows, but since I have single exe php-cgi I would just copy it and php.ini into nginx folder. Thus use non-hardcoded path configuration:

Before that I have to comment about the RunHiddenConsole thing, in PE thingy this is just a matter of using -mwindows or -mconsole during compile. And there is a better tool called postw32 (from freepascal project, I included this in my mingw build) which could turn any console application into consoleless a.k.a "click and nothing seems to happened" (because it was already windowless) or vice versa (back to console again).

so inside conf\nginx.conf instead of:

root c:/www;

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


I just need (merely replace /scripts with  $document_root  from stocked config):

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


Both configuration assumed we have virgin php.ini (doc_root has empty value, do not confuse with nginx's   $document_root  above which translate root declaration before it that is "html" which refer to html folder relative to where nginx.exe located). In short we have portable configuration.

Now talk about respawning thingy... in the bottom part of the wiki before describe how to make it run under SYSTEM account. Well let me tell you something:
AFAIK we (as admin) could impersonate to SYSTEM using "at" (scheduler) command then kill "explorer.exe" just before launched and bang Windows P4WN3D and CHR00T3D! no no not that old trick, actually the proper way is to use "sc" command see below:

C:\Users\Administrator>sc create --help
Creates a service entry in the registry and Service Database.
SYNTAX:
sc create [service name] [binPath= ] ...
CREATE OPTIONS:
NOTE: The option name includes the equal sign.
type= (default = own)
start= (default = demand)
error= (default = normal)
binPath=
group= 
tag=  
depend=
obj= (default = LocalSystem)
DisplayName=
password=


Extra Extremely Important Note: That is an empty space right after equal sign and before the actual value.

Now we could even make php as service too that depends on nginx service, or run them under different credential (a hidden user preferably, you know like postgresql way). Nginx already have respawning (parent - child) facility adding it to relaunching service will increase its reliability more too.

Hmm.. I will make my own stack installer one day maybe came up with tagline: "Install and run in 5 seconds yet takes only 10MB of space" Yeah whatever, but I really hope this will become a fine release and get it's own page in the main menu of my blog. Certainly need more testing


No comments:

Post a Comment