Tag Archive: php


与 UNIX 构建系统交互: config.m4

扩展的 config.m4 文件告诉 UNIX 构建系统哪些扩展 configure 选项是支持的,你需要哪些扩展库,以及哪些源文件要编译成它的一部分。对所有经常使用的 autoconf 宏,包括 PHP 特定的及 autoconf 内建的,请查看 Zend Engine 2 API 参考 章节。

Tip当开发 PHP 扩展时,强烈建议安装 autoconf 2.13 版,尽管用更新的版本可使用。2.13 版被认为是在 autoconf 中可用性,适用性及用户基础等方面最好的版本。使用最新版本有时会与所期望的 configure 输出在样式上有所不同。

Example #1 config.m4 文件举例

dnl $Id$
dnl config.m4 for extension example
PHP_ARG_WITH(example, for example support,
[  --with-example[=FILE]       Include example support. File is the optional path to example-config])
PHP_ARG_ENABLE(example-debug, whether to enable debugging support in example,
[  --enable-example-debug        example: Enable debugging support in example], no, no)
PHP_ARG_WITH(example-extra, for extra libraries for example,
[  --with-example-extra=DIR      example: Location of extra libraries for example], no, no)

dnl 检测扩展是否已启用
if test "$PHP_EXAMPLE" != "no"; then

  dnl 检测 example-config。首先尝试所给出的路径,然后在 $PATH 中寻找
  AC_MSG_CHECKING([for example-config])
  EXAMPLE_CONFIG="example-config"
  if test "$PHP_EXAMPLE" != "yes"; then
    EXAMPLE_PATH=$PHP_EXAMPLE
  else
    EXAMPLE_PATH=`$php_shtool path $EXAMPLE_CONFIG`
  fi

  dnl 如果找到可用的 example-config,就使用它
  if test -f "$EXAMPLE_PATH" && test -x "$EXAMPLE_PATH" && $EXAMPLE_PATH --version > /dev/null 2>&1; then
    AC_MSG_RESULT([$EXAMPLE_PATH])
    EXAMPLE_LIB_NAME=`$EXAMPLE_PATH --libname`
    EXAMPLE_INCDIRS=`$EXAMPLE_PATH --incdirs`
    EXAMPLE_LIBS=`$EXAMPLE_PATH --libs`

    dnl 检测扩展库是否工作正常
    PHP_CHECK_LIBRARY($EXAMPLE_LIB_NAME, example_critical_function,
    [
      dnl 添加所需的 include 目录
      PHP_EVAL_INCLINE($EXAMPLE_INCDIRS)
      dnl 添加所需的扩展库及扩展库所在目录
      PHP_EVAL_LIBLINE($EXAMPLE_LIBS, EXAMPLE_SHARED_LIBADD)
    ],[
      dnl 跳出
      AC_MSG_ERROR([example library not found. Check config.log for more information.])
    ],[$EXAMPLE_LIBS]
    )
  else
    dnl 没有可用的 example-config,跳出
    AC_MSG_RESULT([not found])
    AC_MSG_ERROR([Please check your example installation.])
  fi

  dnl 检测是否启用调试
  if test "$PHP_EXAMPLE_DEBUG" != "no"; then
    dnl 是,则设置 C 语言宏指令
    AC_DEFINE(USE_EXAMPLE_DEBUG,1,[Include debugging support in example])
  fi

  dnl 检测额外的支持
  if test "$PHP_EXAMPLE_EXTRA" != "no"; then
    if test "$PHP_EXAMPLE_EXTRA" == "yes"; then
      AC_MSG_ERROR([You must specify a path when using --with-example-extra])
    fi

    PHP_CHECK_LIBRARY(example-extra, example_critical_extra_function,
    [
      dnl 添加所需路径
      PHP_ADD_INCLUDE($PHP_EXAMPLE_EXTRA/include)
      PHP_ADD_LIBRARY_WITH_PATH(example-extra, $PHP_EXAMPLE_EXTRA/lib, EXAMPLE_SHARED_LIBADD)
      AC_DEFINE(HAVE_EXAMPLEEXTRALIB,1,[Whether example-extra support is present and requested])
      EXAMPLE_SOURCES="$EXAMPLE_SOURCES example_extra.c"
    ],[
      AC_MSG_ERROR([example-extra lib not found. See config.log for more information.])
    ],[-L$PHP_EXAMPLE_EXTRA/lib]
    )
  fi

  dnl 最后,将扩展及其所需文件等信息传给构建系统
  PHP_NEW_EXTENSION(example, example.c $EXAMPLE_SOURCES, $ext_shared)
  PHP_SUBST(EXAMPLE_SHARED_LIBADD)
fi

autoconf 语法简介

config.m4 文件使用 GNU autoconf 语法编写。简而言之,就是用强大的宏语言增强的 shell 脚本。注释用字符串 dnl 分隔,字符串则放在左右方括号中间(例如,[])。字符串可按需要多次嵌套引用。完整的语法参考可参见位于 » http://www.gnu.org/software/autoconf/manual/autoconf 手册。

PHP_ARG_*: 赋予用户可选项

在以上的 config.m4 例子中,两条注释后,最先见到的 3 行代码,使用了 PHP_ARG_WITH()PHP_ARG_ENABLE()。这些给 configure 提供了可选项,和在运行 ./configure –help 时显示的帮助文本。就象名称所暗示的,其两者的不同点在于是创建 –with-* 选项还是 –enable-* 选项。每个扩展应提供至少一个以上的选项以及扩展名称,以便用户可选择是否将扩展构建至 PHP 中。按惯例,PHP_ARG_WITH() 用于取得参数的选项,例如扩展所需库或程序的位置;而 PHP_ARG_ENABLE() 用于代表简单标志的选项。

Example #2 configure 输出举例

$ ./configure --help
...
  --with-example[=FILE]       Include example support. FILE is the optional path to example-config
  --enable-example-debug        example: Enable debugging support in example
  --with-example-extra=DIR      example: Location of extra libraries for example
...

$ ./configure --with-example=/some/library/path/example-config --disable-example-debug --with-example-extra=/another/library/path
...
checking for example support... yes
checking whether to enable debugging support in example... no
checking for extra libraries for example... /another/library/path
...

Note:

在调用 configure 时,不管选项在命令行中的顺序如何,都会按在 config.m4 中指定的顺序进行检测。

处理用户选择

config.m4 可给用户提供一些做什么的选择,现在就是做出选择的时候了。在上例中,三个选项在未指定时显然默认为 “no”。习惯上,最好用此值作为用于启用扩展的选项的默认值,为了扩展与 PHP 分开构建则用 phpize 覆盖此值,而要构建在 PHP 中时则不应被默认值将扩展空间弄乱。处理这三个选项的代码要复杂得多。

处理 –with-example[=FILE] 选项

首先检测是否设置了 –with-example[=FILE] 选项。如此选项未被指定,或使用否定的格式(–without-example ),或赋值为 “no” 时,它会控制整个扩展的含有物其他任何事情都不会发生。在上面的例子中所指定的值为 /some/library/path/example-config,所以第一个 test 成功了。

接下来,代码调用 AC_MSG_CHECKING(),这是一个 autoconf 宏,输出一行标准的如 “checking for …” 的信息,并检测用户假定的 example-config 是否是一个明确的路径。在这个例子中,PHP_EXAMPLE 所取到的值为 /some/library/path/example-config,现已复制到 EXAMPLE_PATH 变量中了。只有用户指定了 –with-example ,才会执行代码 $php_shtool path $EXAMPLE_CONFIG,尝试使用用户当前的 PATH 环境变量推测 example-config 的位置。无论如何,下一步都是检测所选的 EXAMPLE_PATH 是否是正常文件,是否可执行,及是否执行成功。如成功,则调用 AC_MSG_RESULT(),结束由 AC_MSG_CHECKING() 开始的输出行。否则,调用 AC_MSG_ERROR(),打印所给的信息并立即中断执行 configure

代码现在执行几次 example-config 以确定一些站点特定的配置信息。下一步调用的是 PHP_CHECK_LIBRARY(),这是 PHP 构建系统提供的一个宏,包装了 autoconfAC_CHECK_LIB() 函数。PHP_CHECK_LIBRARY() 尝试编译、链接和执行程序,在第一个参数指定的库中调用由第二个参数指定的符号,使用第五个参数给出的字符串作为额外的链接选项。如果尝试成功了,则运行第三个参数所给出的脚本。此脚本从 example-config 所提供的原始的选项字符串中取出头文件路径、库文件路径和库名称,告诉 PHP 构建系统。如果尝试失败,脚本则运行第四个参数中的脚本。此时调用 AC_MSG_ERROR() 来中断程序执行。

处理 –enable-example-debug 选项

处理 –enable-example-debug 很简单。只简单地检测其真实值。如果检测成功,则调用 AC_DEFINE() 使 C 语言宏指令 USE_EXAMPLE_DEBUG 可用于扩展的源代码。第三个参数是给 config.h 的注释字符串,通常可放心的留空。

处理 –with-example-extra=DIR 选项

对于此例子来说,由 –with-example-extra=DIR 选项所请求的假定的“额外”功能操作不会与假定的 example-config 程序共享,也没有默认的搜索路径。因此,用户需要在所需的库之前提供设置程序。有点不象现实中的扩展,在这里的设置仅仅起说明性的作用。

代码开始用已熟知的方式来检测 PHP_EXAMPLE_EXTRA 的真实值。如果所提供的为否定形式,则不会进行其他处理,用户也不会请求额外的功能。如果所提供的为未提供参数的肯定形式,则调用 AC_MSG_ERROR() 中止处理。下一步则再次调用 PHP_CHECK_LIBRARY()。这一次,因为没有提供预定义编译选项,PHP_ADD_INCLUDE()PHP_ADD_LIBRARY_WITH_PATH() 用于构建额外功能所需的头文件路径、库文件路径和库标志。也调用 AC_DEFINE() 来指示所请求的额外功能代码是可用的,设置变量来告诉以后的代码,有额外的源代码要构建。如果检测失败,则调用所熟悉的 AC_MSG_ERROR()。另一种不同的处理失败的方式是更换为调用 AC_MSG_WARNING(),例如:

AC_MSG_WARNING([example-extra lib not found. example will be built without extra functionality.])

上例中,configure 会打印一段警告信息而不是错误,且继续处理。用哪种方式处理失败留给扩展开发人员在设计时决定。

告诉构建系统要做什么

有了所需的头文件和特定的库,有了全部选项处理代码及宏定义,还有一件事要做:必须告诉构建系统去构建扩展本身和被其用到的文件。为了做这些,则要调用 PHP_NEW_EXTENSION() 宏。第一个参数是扩展的名称,和包含它的目录同名。第二个参数是做为扩展的一部分的所有源文件的列表。参见 PHP_ADD_BUILD_DIR() 以获取将在子目录中源文件添加到构建过程的相关信息。第三个参数总是 $ext_shared, 当为了 –with-example[=FILE] 而调用 PHP_ARG_WITH()时,由 configure 决定参数的值。第四个参数指定一个“SAPI 类”,仅用于专门需要 CGI 或 CLI SAPI 的扩展。其他情况下应留空。第五个参数指定了构建时要加入 CFLAGS 的标志列表。第六个参数是一个布尔值,为 “yes” 时会强迫整个扩展使用 $CXX 代替 $CC 来构建。第三个以后的所有参数都是可选的。最后,调用 PHP_SUBST() 来启用扩展的共享构建。参见 扩展相关 FAQ 以获取更多有关禁用共享方式下构建扩展的信息。

counter 扩展的 config.m4 文件

以前编写的 counter 扩展有一个比上面所述更简单的 config.m4 文件,它不使用很多构建系统的特性。对不使用外部的或绑定的库的扩展来说,这是一个比较好的操作方式。

Example #3 counter 的 config.m4 文件

dnl
$
Id$
dnl config.m4 for extension counter

PHP_ARG_ENABLE(counter, for counter support,
[  --enable-counter            Include counter support])

dnl Check whether the extension is enabled at all
if test "$PHP_COUNTER" != "no"; then
  dnl Finally, tell the build system about the extension and what files are needed
  PHP_NEW_EXTENSION(counter, counter.c counter_util.c, $ext_shared)
  PHP_SUBST(COUNTER_SHARED_LIBADD)
fi



If you try to install 5.3.6 on by patching sources you will most likely see a lot of error messages similar to the following:

$ ./configure
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
./configure: 490: 5: Bad file descriptor
./configure: 490: :: checking for pthreads_cflags: not found
./configure: 490: 6: Bad file descriptor
./configure: 490: checking for pthreads_cflags… : not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
./configure: 492: 5: Bad file descriptor
./configure: 492: :: result: : not found
./configure: 492: 6: Bad file descriptor
./configure: 492: : Permission denied
./configure: 495: 5: Bad file descriptor
./configure: 495: :: checking for pthreads_lib: not found
./configure: 495: 6: Bad file descriptor
./configure: 495: checking for pthreads_lib… : not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
./configure: 557: 5: Bad file descriptor
./configure: 557: :: result: : not found
./configure: 557: 6: Bad file descriptor
./configure: 557: : Permission denied
./configure: 633: 5: Bad file descriptor
./configure: 633: :: result: : not found
./configure: 633: 6: Bad file descriptor
./configure: 633: : Permission denied
./configure: 635: 5: Bad file descriptor
./configure: 635: :: result: Configuring SAPI modules: not found
./configure: 635: 6: Bad file descriptor
./configure: 635: Configuring SAPI modules: not found
./configure: 666: 5: Bad file descriptor

See what happened when using buildconf earlier..

$ ./buildconf –force
Forcing buildconf
buildconf: checking installation…
buildconf: autoconf version 2.64 (ok)
buildconf: Your version of autoconf likely contains buggy cache code.
Running vcsclean for you.
To avoid this, install autoconf-2.13.
Can’t figure out your VCS, not cleaning.

This is not a regular warning and it cannot be neglected. You have to use autoconf-2.13. This is because the newer version of autoconf cannot process scripts which are meant for autoconf 2.13. So just install autoconf-2.13 and then do the compilation again..

sudo apt-get install autoconf2.13

Also if you have a low memory machine, then you might get error such as:

[lots of compile output]

/bin/sh /home/ibb_admin/temp/php-5.3.0/libtool –silent –preserve-dup-deps –mode=compile gcc -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic -Iext/fileinfo/ -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/ -DPHP_ATOM_INC -I/home/ibb_admin/temp/php-5.3.0/include -I/home/ibb_admin/temp/php-5.3.0/main -I/home/ibb_admin/temp/php-5.3.0 -I/home/ibb_admin/temp/php-5.3.0/ext/date/lib -I/home/ibb_admin/temp/php-5.3.0/ext/ereg/regex -I/usr/include/libxml2 -I/opt/include -I/opt/include/freetype2 -I/usr/include/imap -I/usr/kerberos/include -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/oniguruma -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl/mbfl -I/opt/include/mysql -I/usr/include/mysql -I/home/ibb_admin/temp/php-5.3.0/ext/sqlite3/libsqlite -I/home/ibb_admin/temp/php-5.3.0/TSRM -I/home/ibb_admin/temp/php-5.3.0/Zend    -I/usr/include -g -O2  -c /home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

So just upgrade the gcc compiler to its latest version and also add –disable-fileinfo to ./configure

Hence full installation procedure would be similar to:

sudo apt-get install autoconf2.13
wget http://us.php.net/get/php-5.3.6.tar.bz2/from/us.php.net/mirror
tar -xjf php-5.3.6.tar.bz2
cd php-5.3.6/
./buildconf –force
./configure –disable-fileinfo –enable-fpm –with-zlib –enable-pdo –with-pdo-mysql –enable-sockets –with-mysql –enable-calendar –with-iconv –enable-exif –enable-soap –enable-ftp –enable-wddx –with-zlib –with-bz2 –with-gettext –with-xmlrpc –enable-pcntl –enable-soap –enable-bcmath –enable-mbstring –enable-dba –with-openssl –with-mhash –with-mcrypt –with-xsl –with-curl –with-pcre-regex –with-gd –enable-gd-native-ttf –with-ldap –enable-pdo –with-pdo-mysql –with-mysql –with-sqlite –with-pdo-sqlite –enable-zip–enable-sqlite-utf8 –with-pear

Of course, your php configure options can be different.



php默认会输出header信息:
Date: Tue, 15 Apr 2008 13:58:46 GMT
Server: Apache/2.2.8
X-Powered-By: PHP/5.2.3
这样一下子php信息就全曝光了。怎样解决呢。

网上一搜中文,还真找不到相关信息。用英文一搜搜到了(下面是原文)

If you have read my previous tip, “Hide apache software version“, you have seen how you can configure apache to provide only a minimal amount of information about the installed software versions in its banner. But if you are using the PHP module in your web server (as most of us are), then there is one additional step that need to be completed, and this is what I will show you in this tip.

After implementing the apache directives ServerTokens and ServerSignature as shown in “Hide apache software version“, we test its functionality against a regular html file and we get the following response:

HEAD http://remote_server.com/index.html
200 OK
Connection: close
Date: Fri, 16 Jun 2006 01:13:23 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
Client-Date: Fri, 16 Jun 2006 21:42:53 GMT
Client-Peer: 192.168.0.102:80
Client-Response-Num: 1

This looks good. But if we do the same thing against an URL that is a PHP file:

HEAD http://remote_server.com/index.php 200 OK Connection: close Date: Fri, 16 Jun 2006 01:16:30 GMT Server: Apache Content-Type: text/html; charset=UTF-8 Client-Date: Fri, 16 Jun 2006 21:48:13 GMT Client-Peer: 192.168.0.102:80 Client-Response-Num: 1 X-Powered-By: PHP/5.1.2-1+b1

Ups… As we can see PHP adds its own banner:

X-Powered-By: PHP/5.1.2-1+b1…

Let’s see how we can disable it. In order to prevent PHP from exposing the fact that it is installed on the server, by adding its signature to the web server header we need to locate in php.ini the variable expose_php and turn it off.

By default expose_php is set to On.

In your php.ini (based on your Linux distribution this can be found in various places, like /etc/php.ini, /etc/php5/apache2/php.ini, etc.) locate the line containing “expose_php On” and set it to Off:

expose_php = Off

After making this change PHP will no longer add it’s signature to the web server header. Doing this, will not make your server more secure… it will just prevent remote hosts to easily see that you have PHP installed on the system and what version you are running.

结果简单的让人吃惊,只是需要修改php.ini 的 expose_php 把默认的 On改成 Off 就行了。

Problem:

Get following prompt in command line while run a php application,

“zend_mm_heap corrupted”

Solution:

A.while do complie for php, use the –enable-debug option

B. Before run a php application, set following environment, USE_ZEND_ALLOC=0, however, it seems this only works for PHP CLI mode, doesn’t work for Apache Module, such as in php.ini or httpd.conf. There is an lucky scenarios for nginx, he fix the problem via: set the environment in bash_profile, and then restart the php-fpm

Note:

zend_mm means Zend Memory Manager

   在 php 命令行中有两个参数 $argc 和 $argv 分别代表 参数的个数 和 全部参数组成的数组。

<?php

# testvar.php
var_dump ($argc);
var_dump ($argv)
?>
 

php testvar.php 3gcomet

int(2)    //这个表示有两个参数,下面的是列出全部参数,注意参数包括文件名 testvar.php
array(2) {
  [0]=>
  string(5) “testvar.php”
  [1]=>
  string(7) “3gcomet”
}

To detect if php run from CLI

To detect if php run from CLI:

if (defined(‘STDIN’)) or: if (isset($argc))

The Issue:

While I am install the PEAR for PHP 5.3.2 version with display_errors settings on, I get following error,

===========================================================
Warning: date(): It is not safe to rely on the system’s timezone settings. You a
re *required* to use the date.timezone setting or the date_default_timezone_set(
) function. In case you used any of those methods and you are still getting this

How to installing PHPUnit 3.4

PHPUnit 3.4 requires PHP 5.1.4 (or later) but PHP 5.3.2 (or later) is highly recommended. It should be installed using the PEAR Installer. This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.

The PEAR channel (pear.phpunit.de) that is used to distribute PHPUnit needs to be registered with the local PEAR environment. Furthermore, a component that PHPUnit depends upon is hosted on the Symfony Components PEAR channel (pear.symfony-project.com).

pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com

This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:

pear install phpunit/PHPUnit

After the installation you can find the PHPUnit source files inside your local PEAR directory; the path is usually /usr/lib/php/PHPUnit.

Although using the PEAR Installer is the only supported way to install PHPUnit, you can install PHPUnit manually. For manual installation, do the following:

  1. Download a release archive from http://pear.phpunit.de/get/ and extract it to a directory that is listed in the include_path of your php.ini configuration file.

  2. Prepare the phpunit script:

    1. Rename the phpunit.php script to phpunit.

    2. Replace the @php_bin@ string in it with the path to your PHP command-line interpreter (usually /usr/bin/php).

    3. Copy it to a directory that is in your path and make it executable (chmod +x phpunit).

  3. Prepare the PHPUnit/Util/PHP.php script:

    1. Replace the @php_bin@ string in it with the path to your PHP command-line interpreter (usually /usr/bin/php).

How to Install and Configure PHP 5 to Run with Apache on Windows

How to Install and Configure PHP 5 to Run with Apache on Windows

by Christopher Heng, thesitewizard.com

Many web developers want to run Apache and PHP on their own computer since it allows them to easily test their scripts and programs before they put them “live” on the Internet. This article gives a step by step guide on how you can install and configure PHP5 to work together with the Apache HTTP Server on Windows. The procedure has been tested to work on both Windows XP and Vista.

If you have not already installed Apache on your machine, check out one of the guides listed below. This “How To” guide assumes that you have already completed installing Apache.

Note: those planning to install PHP 4 on Apache 1.x should read my article How to Install and Configure PHP4 to Run with Apache on Windows instead.

Steps to Setting Up PHP 5

  1. Download PHP 5

    Before you begin, get a copy of PHP 5 from the PHP download page. In particular, download the VC6 thread-safe zip package from the “Windows Binaries” section — that is, don’t get the installer. For example, select the package labelled “PHP 5.2.5 zip package” if 5.2.5 is the current version.

    [Update: note that I have not tested the procedure below with any of the PHP 5.3 versions, only with 5.2.5, which was the latest version at the time I originally wrote this. In theory, the procedure should work with later 5.2 versions as well. I'm not sure about 5.3 though. A version jump from 5.2 to 5.3 usually means bigger changes than simple bug fixes. If you want to be sure the procedure below will work, just get the latest of the 5.2 series.]

  2. Install PHP 5

    Create a folder on your hard disk for PHP. I suggest “c:php” although you can use other names if you wish. Personally though, I prefer to avoid names with spaces in it, like “c:Program Filesphp” to avoid potential problems with programs that cannot handle such things. I will assume that you used c:php in this tutorial.

    Extract all the files from the zip package into that folder. To do that simply double-click the zip file to open it, and drag all the files and folders to c:php.

  3. Upgraders: Remove the Old PHP.INI File from Your Windows Directory

    If you are upgrading to PHP 5 from an older version, go to your windows directory, typically c:windows, and delete any php.ini file that you have previously placed there.

  4. Configuring PHP

    Go to the c:php folder and make a copy of the file “php.ini-recommended”. Name the new file “php.ini”. That is, you should now have a file “c:phpphp.ini”, identical in content with “c:phpphp.ini-recommended”.

    Note: if you are using Apache 1, you should either move the php.ini file to your windows directory, “C:Windows” on most systems, or configure your PATH environment variable to include “c:php”. If you don’t know how to do the latter, just move the php.ini file to the “c:windows” folder. You do not have to do this if you are using Apache 2, since we will include a directive later in the Apache 2 configuration file to specify the location of the php.ini file.

    Use an ASCII text editor (such as Notepad, which can be found in the Accessories folder of your Start menu) to open “php.ini”. You may need to make the following changes to the file, depending on your requirements:

    1. Enable Short Open Tags

      Search for the line that reads:

      short_open_tag = Off

      If short_open_tag is set to “off”, tags like “commercial web hosts that support PHP have no issues with your scripts using “

      short_open_tag = On
    2. Magic Quotes

      By default, input data is not escaped with backslashes. That is, if your visitors enter an inverted comma (single quote) into your web form, the script will receive that unadorned inverted comma (single quote). This is for the most part desirable unless you special requirements. If you want your input data to have the backslash (“”) prefix, such as, for example, to mimic your web host’s settings, search for the following:

      magic_quotes_gpc = Off

      and replace it with:

      magic_quotes_gpc = On

      Do not do this unless your web host has this setting as well. Even with the setting of “Off”, you can still use the addslashes() function in PHP to add the slashes for the specific pieces of data that need them.

    3. Register Globals

      A number of older scripts assume that all data sent by a form will automatically have a PHP variable of the same name. For example, if your form has an input field with a name of “something”, older PHP scripts assume that the PHP processor will automatically create a variable called $something that contains the value set in that field.

      If you are running such scripts, you will need to look for the following field:

      register_globals = Off

      and change it to the following:

      register_globals = On

      WARNING: Do NOT do this unless you have third party scripts that need it. When writing new scripts, it’s best to always code with the assumption that the register_globals item is set to “Off”.

    4. Display Errors

      On a “live” website, you typically want errors in your script to be silently logged to a PHP error file. On your own local machine, however, while you are testing and debugging a PHP script, it is probably more convenient to have error messages sent to the browser window when they appear. This way, you won’t miss errors if you forget to check the error log file.

      If you want PHP to display error messages in your browser window, look for the following:

      display_errors = Off

      And change it to:

      display_errors = On

      This value should always be set to “Off” for a “live” website.

    5. Session Path

      If your script uses sessions, look for the following line:

      ;session.save_path = “/tmp”

      The session.save_path sets the folder where PHP saves its session files. Since “/tmp” does not exist on Windows, you will need to set it to a directory that does. One way is to create a folder called (say) “c:tmp” (the way you created c:php earlier), and point this setting to that folder. If you do that, change the line to the following:

      session.save_path = “c:tmp”

      Notice that in addition to changing the path, I also removed the semi-colon (“;”) prefix from the line.

      Alternatively, you can find out the current TEMP folder on your computer and use that. Or create a “tmp” folder in your PHP directory, like “c:phptmp” and set the configuration file accordingly. The possibilities are endless. If you can’t decide, just create “c:tmp” and do as I said above.

    6. SMTP Server

      If your script uses the mail() function, and you want the function to successfully send mail on your local machine, look for the following section:

      [mail function]
      ; For Win32 only.
      SMTP = localhost
      smtp_port = 25

      ; For Win32 only.
      ;sendmail_from = me@example.com

      Change it to point to your SMTP server and email account. For example, if your SMTP server is “mail.example.com” and your email address is “youremail@example.com”, change the code to:

      [mail function]
      SMTP = mail.example.com
      smtp_port = 25
      sendmail_from = youremail@example.com

      Note that after you do this, when your script tries to use the mail() function, you will need to be connected to your ISP for the function to succeed. If you do not modify the above lines and attempt to use mail() in your script, the function will return a fail code, and display (or log) the error (depending on how you configure php.ini to handle errors).

      (Note that in Apache 1.x, the smtp_port line may not be present. If so, don’t include it.)

How to Configure Apache for PHP 5

There are two ways to set up Apache to use PHP: the first is to configure it to load the PHP interpreter as an Apache module. The second is to configure it to run the interpreter as a CGI binary. I will supply information for how you can accomplish both, but you should only implement one of these methods. Choose the module method if your web host also installed PHP as an Apache module, and use the CGI method if they have implemented it to run as a CGI binary.

  1. Running PHP 5 as an Apache Module

    To configure Apache to load PHP as a module to parse your PHP scripts, use an ASCII text editor to open the Apache configuration file, “httpd.conf”. If you use Apache 1.x, the file is found in “c:Program FilesApache GroupApacheconf”. Apache 2.0.x users can find it in “C:Program FilesApache GroupApache2conf” while Apache 2.2.x users can find it in “C:Program FilesApache Software FoundationApache2.2conf”. Basically, it’s in the “conf” folder of wherever you installed Apache.

    Search for the section of the file that has a series of “LoadModule” statements. Statements prefixed by the hash “#” sign are regarded as having been commented out.

    If you are using Apache 1.x, add the following line after all the LoadModule statements:

    LoadModule php5_module “c:/php/php5apache.dll”

    If you are using Apache 2.0.x, add the following line after all the LoadModule statements:

    LoadModule php5_module “c:/php/php5apache2.dll”

    If you are using Apache 2.2.x, add the following line instead:

    LoadModule php5_module “c:/php/php5apache2_2.dll”

    Note carefully the use of the forward slash character (“/”) instead of the traditional Windows backslash (“”). This is not a typographical error.

    If you are using Apache 1.x, search for the series of “AddModule” statements, and add the following line after all of them. You do not have to do this in any of the Apache 2 series of web servers.

    AddModule mod_php5.c

    Next, search for “AddType” in the file, and add the following line after the last “AddType” statement. Do this no matter which version of Apache you are using. For Apache 2.2.x, you can find the “AddType” lines in the section. Add the line just before the closing for that section.

    AddType application/x-httpd-php .php

    If you need to support other file types, like “.phtml”, simply add them to the list, like this:

    AddType application/x-httpd-php .phtml

    Finally, for those using one of the Apache 2 versions, you will need to indicate the location of your PHP ini file. Add the following line to the end of your httpd.conf file.

    PHPIniDir “c:/php”

    Of course if you used a different directory for your PHP installation, you will need to change “c:/php” to that path. Remember to use the forward slash (“/”) here again.

    If you are using Apache 1, you will have already placed your php.ini file in either the Windows directory or somewhere in your PATH, so PHP should be able to find it by itself. You can of course do the same if you are using Apache 2, but I find modifying the Apache configuration file a better solution than cluttering your c:windows directory or your PATH variable.

  2. Running PHP 5 as a CGI Binary

    If you have configured PHP 5 to run as an Apache module, skip forward to the next section. This section is for those who want to configure PHP to run as a CGI binary.

    The procedure is the same whether you are using the Apache 1.x series or one of the 2.x series.

    Search for the portion of your Apache configuration file which has the ScriptAlias section. Add the line from the box below immediately after the ScriptAlias line for “cgi-bin”. If you use Apache 2.2.x, make sure that the line goes before the closing for that section.

    Note that if you installed PHP elsewhere, such as “c:Program Filesphp”, you should substitute the appropriate path in place of “c:/php/” (for example, “c:/Program Files/php/”). Observe carefully that I used forward slashes (“/”) instead of the usual Windows backslashes (“”) below. You will need to do the same.

    ScriptAlias /php/ “c:/php/”

    Apache needs to be configured for the PHP MIME type. Search for the “AddType” comment block explaining its use, and add the AddType line in the box below after it. For Apache 2.2.x, you can find the AddType lines in the section. Add the following line just before the closing for that section.

    AddType application/x-httpd-php .php

    As in the case of running PHP as an Apache module, you can add whatever extensions you want Apache to recognise as PHP scripts, such as:

    AddType application/x-httpd-php .phtml

    Next, you will need to tell the server to execute the PHP executable each time it encounters a PHP script. Add the following somewhere in the file, such as after the comment block explaining “Action”. If you use Apache 2.2.x, you can simply add it immediately after your “AddType” statement above; there’s no “Action” comment block in Apache 2.2.x.

    Action application/x-httpd-php “/php/php-cgi.exe”

    Note: the “/php/” portion will be recognised as a ScriptAlias, a sort of macro which will be expanded to “c:/php/” (or “c:/Program Files/php/” if you installed PHP there) by Apache. In other words, don’t put “c:/php/php.exe” or “c:/Program Files/php/php.exe” in that directive, put “/php/php-cgi.exe”.

    If you are using Apache 2.2.x, look for the following section in the httpd.conf file:


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

    Add the following lines immediately after the section you just found.


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
  3. Configuring the Default Index Page

    This section applies to all users, whether you are using PHP as a module or as a CGI binary.

    If you create a file index.php, and want Apache to load it as the directory index page for your website, you will have to add another line to the “httpd.conf” file. To do this, look for the line in the file that begins with “DirectoryIndex” and add “index.php” to the list of files on that line. For example, if the line used to be:

    DirectoryIndex index.html

    change it to:

    DirectoryIndex index.php index.html

    The next time you access your web server with just a directory name, like “localhost” or “localhost/directory/”, Apache will send whatever your index.php script outputs, or if index.php is not available, the contents of index.html.

Restart the Apache Web Server

Restart your Apache server. This is needed because Apache needs to read the new configuration directives for PHP that you have placed into the httpd.conf file. The Apache 2.2 server can be restarted by doubleclicking the Apache Service Monitor system tray icon, and when the window appears, clicking the “Restart” button.

Testing Your PHP Installation

Create a PHP file with the following line:

Save the file as “test.php” or any other name that you fancy, but with the “.php” extension, into your Apache htdocs directory. If you are using Notepad, remember to save as “test.php” with the quotes, or the software will add a “.txt” extension behind your back.

Open your browser and access the file by typing “localhost/test.php” into your browser’s address bar. Do not open the file directly on the hard disk – you’ll only see the words you typed in earlier. You need to use the above URL so that the browser will try to access your Apache web server, which in turn runs PHP to interpret your script.

If all goes well, you should see a pageful of information about your PHP setup. Congratulations – you have successfully installed PHP and configured Apache to work with it. You can upload this same file, test.php, to your web host and run it there to see how your web host has set up his PHP, so that you can mimic it on your own machine.

If for some reason it does not work, check to see whether your PHP setup or your Apache setup is causing the problem. To do this, open a Command Prompt window (found in the “Accessories” folder of your “Start” menu) and run php-cgi.exe on test.php with a command line like “c:phpphp-cgi test.php” (without the quotes).

If invoking PHP from the command line causes a large HTML file with all the PHP configuration information to be displayed, then your PHP set up is fine. The problem probably lies with your Apache configuration. Make sure that you have restarted the Apache server after making configuration changes. Verify that you have configured Apache correctly by looking over, again, the instructions on this page and the steps given in How to Install and Configure Apache 1.x for Windows (for Apache 1.x users) or How to Install and Configure Apache 2 on Windows (for Apache 2.x users).

Learning PHP

The complete PHP reference manual can be obtained from the php website. You can refer to it online or download the entire set of HTML files for reference offline. As its name implies, it is a reference manual only. For tutorials, check out the PHP tutorials at thesitewizard.com. If you are new to writing PHP scripts, the following chapters may interest you:

Have fun!

What is LAMP and Why LAMP

Why LAMP

LAMP can significantly reduce or eliminate traditional IT costs for hardware acquisition and software license and applications maintenance costs. Very little infrastructure is required; LAMP is accessed through the internet from any web browser or web-enabled phone. As a service subscriber rather than software licensee, costly software upgrades that are generally required by the traditional ERP vendors every 2 to 3 years, are eliminated. There are no business disruptions during the no-cost LAMP upgrades. Subscribers can realize significant savings from LAMP. First time ERP clients avoid costly software and implementation costs, both initially and recurring, and can realize full benefits from an accelerated installation without having any infrastructure other than access to the internet from a web browser. Traditional legacy ERP customers can realize significant cost savings by reducing infrastructure, licenses, maintenance and application support within 12 months of implementation, an ROI that can be measured in months, not years. No ongoing expensive consulting and systems integration support is required. IMPART provides configuration and conversion on a fixed fee basis. IMPART doesn’t leave those other consulting, partners, behind that seemingly never goes away.

History and Pedigree

LAMP is among a select few enterprise software products developed entirely with open source software and protocols, resulting in lower costs to IMPART and customers alike. Built from the ground-up for SaaS delivery with multi-tenant (MT) architecture – it is not a rewrite or revamp of a single tenant (ST) system. LAMP has over 100 man-years of development during its five years of development effort to-date. Our software and services are built on over 30 years of experience in software design, development and delivery. The MT architecture allows IMPART to achieve an improved cost structure while maximizing the value to our customers by including improved and new business logic through rapid deployment of LAMP upgrades to the entire user base without upgrade cost or business interruption.

L A M P
The acronym LAMP refers to a solution stack of software programs, commonly free software programs, used together to run dynamic Web sites or servers:

Linux, (referring to OS kernel)
Apache, the Web server
MySQL, the database management system (or database server)
PHP (Sometimes Perl or Python), the programming language
L A M P Advantages
A Culture of Cooperation
The open source community and its culture of knowledge- and resource-sharing accelerates problem-solving. Community knowledgebases and libraries of sample application code help compress development time by enabling convenient reuse and adaptation.

Low Overhead
The compact LAMP component stack simplifies deployment and reduces processing overhead. Very tight integration between PHP and Apache, for instance, eliminates the need for application server software and in many instances eliminates an entire physical server tier.
Platform Portability
Because LAMP runs on a wide range of hardware platforms, users have maximum flexibility in deployment and server infrastructure design decisions. Of particular value is the option to deploy on clusters or grids of affordable x86-based servers. These utility computing architectures provide an optimized combination of efficient resource utilization, high availability, versatility and instant scalability.

Security and Stability
The LAMP server stack has a lower bug density — the number of bugs per thousand lines of code — than a baseline of 32 open source projects analyzed, according to a 2006 study by Coverity, a maker of code — analysis tools.

Over the years Saturn has developed standards, frameworks and reusable components for LAMP development. This helps Saturn to deliver economic and efficient solutions based on the LAMP stack.

Powered by WordPress | Theme: Motion by 85ideas.