Saturday, February 10, 2007

Step-by-Step Creation of Vmware images

Sometimes a different OS (other than the one you are running on your machine) is needed for testing purpose. Vmware technology provides a convenient way (not so convenient, but it's easier than getting another machine and install, or install another OS on local machine) to do this.
For example, by using vmware, there are 2 steps to use a Linux system like Suse, on Windows OS:
(1) Making an image of the target Linux system (guest OS).
(2) Use vmware player (which is available in vmware.com) to run the image.

But how to make the image of the guest OS? Here are several steps:
(1) You must ensure that you have enough space required by the guest OS. You should get VMWare Disk Image (a VMDK file) and a VMX file in order to describe the virtual machine.
(2) These files are downloadable in Forever For Now Blog .
(3) Put these 2 files in a directory and edit the vmx file to set up the guest OS description and installation image.
(4) Use vmplayer to run the image.
(5) The installation of the guest OS will automatically starts......
The detailed installation guide can be found at vmplayer documentation site.

Friday, February 09, 2007

Problems when installing pear

I got the following error when I first tried to install PEAR components:
Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)

.......
I googled this error, every expert says there's a configuration error. Yes, there must be a configuration issue. That is so obvious! But, WHERE? Where does this fucking configuration issue reside?
I checked the php.ini file, but I didn't get many clues at first. After a while, I recalled that the php.ini file is created by renaming the default "php.ini-dist" file. There are some unnecessary entries in the end of the file which led to the above error. After deleting all of them, everything works fine.
However, another problem appeared, which was like:
PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar/PEAR/Command.php on line 268
......
This was also a strange error. But still, not much information in the documentation related to this! The solution was:
(1) go to the site: http://go-pear.org/ , read the instructions;
(2) you'll find the following command for windows:
C:\php5>php -r "readfile('http://pear.php.net/go-pear');">go-pear
C:\php5>php go-pear

The it's all solved! It took me almost one hour due to lack of documentation.

Thursday, February 08, 2007

PHP parameter passing

PHP seems to adopt some Java concepts/rules, especially in OOP, such as handling objects/instances.
Normally, php data is passed by value. In PHP5, php data of primitive data types like int, float, etc is still passed by value. But the object is passed by reference. Saying that "the object is passed by reference" is not totally true. Actually, the object handle is still passed by value.
This is exactly the same case as that in Java.
PHP also has features like method pointer, which is introduced by C/C++.
Hope php keep its good performance while using some advanced programming ideas.

Wednesday, February 07, 2007

Usage of register_globals in php

The option register_globals is used to register session variables as regular global variables in the current page as soon as the sessionis discovered. By default, this option is turned off for php 4.2 and later versions.

Several safety issues in php

(1) In PHP there is now a very easy mechanism to disable the capabilityto file-write. This is a great idea especially if your site is entirely database-driven, inwhich case you don’t have any legitimate need to write to the filesystem with PHP anyway.To disable file writing, simply add fwrite to the list of disabled functions in php.ini:
disabled_functions = “fwrite”
If you don’t use php.ini and need to set this value in Apache httpd.conf, remember that it requires a php_admin_value flag (rather than php_value):
php_admin_value disabled_functions=”fwrite”

(2) Many of functions related to file operations are dangerous. Because they duplicate functions that can and should be performed from the local system, they can be a cracker’s bonanza without providing much value to legitimate users. Strongly consider disabling them using PHP’s disable_functions directive!

(3) Remember that although the Web server (and client-side languages such as JavaScript) canonly act on files located under the document root, PHP can access files at any location in the file system—including those above or entirely outside the Web server document root—aslong as the file permissions and include_path are set correctly. For instance, if your Webserver document root is located at /usr/local/apache/htdocs, Apache will be able toserve only files from this directory and its subdirectories, but PHP can open, read, and writeto files in /usr/local, /home/php, /export/home/httpd, or any other directory thatyou make readable and includable by the PHP and/or Web server user.

Monday, February 05, 2007

Difference between $PHP_SELF and $_SERVER['PHP_SELF']

Just got a good article about this:
Understanding $_SERVER[’PHP_SELF’], $PHP_SELF, $_SERVER[’REQUEST_URI’] and $_SERVER[’SCRIPT_NAME’] in PHP and when to use what .
Basically, $PHP_SELF is deprecated and should not be used because it will not work without register_globals being enabled. As of PHP 4.2.0 the default for the PHP directive register_globalswent from on to off.

Saturday, February 03, 2007

New Blogger sucks

Almost everytime I click buttons in new version blogger to save my settings and publish my posts, it'll display an error.
Now I have to use email to blogging.
I hope this issue be resolved soon.
It really SUCKS!
(This is an email-publishing test)

Thursday, February 01, 2007

PHP Apache tips

(1) How to log errors in PHP instead of displaying them on the page?
Use the following lines in php.ini:
; Print out errors (as a part of the output).
information.display_errors = off
; Even when display_errors is on, errors that occur during PHP's startup; debugging.display_startup_errors = Off
; Log errors into a log file (server-specific log, stderr, or error_log (below));
sites.log_errors = On
; Set maximum length of log_errors.
log_errors_max_len = 1024
; Do not log repeated messages.
ignore_repeated_errors = Off
; Ignore source of message when ignoring repeated messages.
ignore_repeated_source = Off
; Log errors to specified file.
error_log = "logs/errors.log"
(2) How to find backend SQL errors?
Set the following line in php.ini:
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and SQL-Errors will be displayed.
mysql.trace_mode = On

(3) How to avoid exposing index structures for a folder?
Set the following lines in httpd.conf:
## DirectoryIndex: sets the file that Apache will serve if a directory is requested.

DirectoryIndex index.php

In such a way, request for a directory will be redirected to the file "index.php".
(4) How to use logging in Apache server?
Use the following 2 settings:
## ErrorLog: The location of the error log file.
ErrorLog logs/error.log
## LogLevel: Possible values include: debug, info, notice, warn, error, crit, alert, emerg.

LogLevel warn
(5) How to do directory-level access configuration for Apache Http Server?
Here's an example:

Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

Details can be found in http://httpd.apache.org/docs/2.2/mod/core.html#options .