Welcome To myPHPNuke.com

  Create An Account Home  ·  Topics  ·  Stats  ·  Your Account  ·  Submit News  ·  Top 10 May 20, 2013  

  Main Menu

  Just SOME MPN Driven Sites!!

  What Is myPHPNuke?
myPHPNuke Introduction
Would you like to contribute to our website or software?

Just Click Here and tell us about yourself.
Printer Friendly Page   Printer Friendly Page Send this Story to a Friend  Send this story to a friend

Installing PHP on windows
Swingdancer, 11 December 2002

PHP Installation and Configuration on Windows Systems, Part I

Melvin Hendrix
USA Educated.Com

The popularity and usage of PHP as a server-side Web-oriented language is growing, as is its ever-expanding functionality. In general, PHP is browser independent and cross-platform capable. PHP was designed from the start for embedded HTML scripting on Linux platforms. Consequently, there are some inherent issues associated with porting applications for use on Windows platforms. These issues are, however, more human than programming based.

The development community involved with PHP is largely a Linux community and most PHP development occurs on Linux first, then on to other platforms as people find the time to port their work. This can often lead to a disparity in functionality between various operating systems.

Programmers will, no doubt, address most of these issues in the near term. In the meantime, how does this affect Windows users who wish to install PHP in their server environments and utilize the myriad of Open Source applications, tools, and utilities that are accessible via the Web?

The PHP world is an Open Source Community. You can obtain the latest stable release of PHP at php.net downloads or here at no cost. I recommend you start with v. 4.2.2 binary to be up and running in minutes. Currently, v. 4.2.3 has a bug affecting phyMyAdmin, a MySQL GUI client that you should also install to manage your MySQL databases. You can read more about phpMyAdmin below and download it here. If you are interested in development versions of the next PHP Windows release, go to snaps.php.net. If you are looking for past release builds for Windows go to proventum.net.

Online documentation for installation on Windows, with user comments, is available from php.net. The file install.txt that comes with the distribution also explains PHP installation on Windows. Other references are listed at the end of this article.

In Part II of the series, we will examine the differences between Linux (Unix) and Windows operating systems.


PHP Installation and Configuration on Windows Systems, Part II

Melvin Hendrix
USA Educated.Com

Getting the PHP binary up and running on Windows systems is generally without complications. But, can the same be said of PHP written applications in the industry? Part II of this series looks at the inherent differences between Windows and Unix systems, for which PHP was initially written.

Configuring PHP to work in Windows 2000 using IIS 4.0 and 5.0 can be reasonably pain-free. I'm usually up and running within a few minutes; the reboot sometimes takes longer than the installation process itself. I wish the same could be said of some PHP applications I've attempted to install on Windows platforms.

Most PHP programmers are Web-based on UNIX or some flavor of it, such as Linux, and, originally, many were programming in Perl. Both of these fine languages have until recently not been available to Windows users. More recently, Perl and PHP programmers have begun to write not only stable code for Windows, but also have created installers to assist users in automatically configuring their applications on Windows platforms. When you can find a PHP or Perl application with an install feature designed with Windows in mind, there is a good chance that these programmers have given a great deal of thought to the interface between their application and the Windows environment. I know these applications usually work for me.

What are the primary issues involved in installing PHP in Windows? Well, they fall into only two categories for me. I have learned that the primary issues are path and text case related. Certainly, some of the code could be written differently and there is still too many anti-Microsoft and anti-Windows comments for constructive synergy to occur more quickly between the Windows and UNIX professionals. Users can afford to be cynical. Programmers, developers, and consultants should be problem-solvers, rather than problem-causers.

What do we mean by path? Path is the location and name of a file on the server. In Web programming, we need to know where within the file system we are or where a file will be located if we choose to "call" it? A file path specifies the route that one must take in order to find a file within the file tree much like a map directs you from one geographical location to another. Both UNIX and Windows have an address system based upon file paths. That's the good news. The bad news is that the file path specification in Windows is different by design than Unix.

In UNIX, all paths start from the "root" directory. The root directory is specified by a single slash "/" character. From there, slash characters separate successive steps along the path. In Windows, all paths start from the "drive letter" or "root" specified by a single slash character also, except, surprise, it's the back slash or "". Furthermore, as we mentioned, all files in Linux are rooted at '/', but Windows has the locally mounted drives (denoted with '[A-Z]:') and network accessible drives (i.e., \servernamesharepointdir).

PHP understands the use of either backward or forward slashes on Windows platforms, and can even handle paths that mix the use of the two slashes. However, as of version 4.0.5, when accessing Windows UNC paths, PHP will only recognize the forward slash in the path (i.e. //machine_name/path/to/file).

The first thing to correct in any program is any reference to hard-coded file paths. These are commonly used to find initialization or configuration files. One frequently made mistake when doing initial cross-platform work in UNIX is to refer to a Windows file in native form. The problem is that the Windows slash "" is also the common escape character in UNIX, and specifying a path like "C:dirtext.txt" will be translated by UFS as C:dir ext.txt; (the white space is a single tab character).

Fortunately, in most instances, Web developers who can "work-around" this difference if they understand the logic that a programmer has embedded into his or her code.

The second area of concern with PHP configuration in Windows is text case format. NTFS is a case preserving, but largely case-insensitive, file system, except in areas of security. That is, the case of file names is remembered, but access to file names with varying case will yield the same file, and file names that vary only in case are not allowed in the same directory. Typical UNIX file systems (UFS) are, in contrast, case-sensitive. For example, "file2.asc" and "FILE2.asc" are read by UFS as two different files and can be stored in the same directory.

So, where does all this get us? All else being equal, that is, if you feel secure with the knowledge that the PHP application already works extremely well in the UNIX environment, then porting it into a Windows environment is possible with some tweaking but, all too often, with a bit of hacking of the code.

In Part III of this series, we will focus on some of the specifics of PHP/Windows configuration.


PHP Installation and Configuration on Windows Systems, Part III

Melvin Hendrix
USA Educated.Com

PHP can be installed on the Windows OS as either a CGI executable or as an Apache module. A module takes advantage of the Web server's native Server API, or SAPI. PHP as a module runs faster than PHP as a stand-alone CGI script, but on Windows it has been said that SAPI support is not as stable. My experience is that the Win32 Windows Installer version of PHP is very stable. I have chosen to work with the Win32 binary (with Windows Installer) and IIS using CGI to avoid the ton of downloading and server configuration that the amalgam of Apache, Windows, MySQL, and PHP produces. In either case, install the files to C:PHP. Why? Because that's where PHP wants to be. Most importantly, do NOT install PHP into directories with spaces in the filename. Those readers who are old enough to remember eight character filenames and what havoc spaces can make in programming know enough to go with the default.

The PHP binary, the SAPI modules, and some extensions rely on external DLLs for execution. Make sure that these DLLs in the distribution exist in a directory that is in the Windows PATH. Copy the file php4ts.dll from C:php into C:WINNTsystem32 on WinNT/2000/XP systems. PHP dll's work best from the Windows system directory (System32), so copy all that you are using into this directory.

The PHP.ini File

The recommended configuration settings for PHP are given in the file php.ini file. For the Apache module, this file will be name php.ini-recommended. For the Windows binary install, it's called php.ini, and is located in the php root directory. To create the actual PHP configuration file that you will be using, you can copy php.ini-recommended, edit it, and re-name it to php.ini. You can also download this file here

Also, it's best to use and write scripts that do not require register_globals to be ON, as using form variables as globals can easily lead to possible security problems, if the code is not very well thought out.

The php.ini file must be located in the C:WINNT root directory. The Windows Installer version of PHP will automatically create the PHP.ini file based on your system. Copy it to the appropriate directory. This is the single most important file communicating between your PHP applications, the PHP script engine, and the Windows operating system. Setting the appropriate PHP.ini directives for your environment is therefore critical. Here are some directives that you should have in your php.ini file at time of installation. The file will be commented to assist you in understanding what each one contributes to the stability of your system.

Table 1. Paths and Directories Configuration Options

Name Default Changeable
include_path PHP_INCLUDE_PATH PHP_INI_ALL
doc_root PHP_INCLUDE_PATH PHP_INI_SYSTEM
user_dir NULL PHP_INI_SYSTEM
extension_dir PHP_EXTENSION_DIR PHP_INI_SYSTEM
cgi.force_redirect "0" PHP_INI_SYSTEM
cgi.redirect_status_env "" PHP_INI_SYSTEM
fastcgi.impersonate "0" PHP_INI_SYSTEM
UNIX include_path include_path=".:/php/includes"
Windows include_path include_path=".;c:phpincludes"

Using a "." in the include path allows for relative includes, since the period refers to the current directory. According to the Windows users community, when using Windows 2000 Advanced Server, you must use back slashes in php.ini when specifying the path to the PHP extensions directory, e.g., extension_dir = E:/php/extensions. This may indicate that double forward slashes could be used, as in C:\php\extensions, and the path would be read correctly; but until you prove it in your environment, trust in the user community.

Handling Paths Across Platforms

If you are sharing or writing PHP, you need to be able to help your users determine what path to take. PHP provides this functionality in the constant variable PHP_OS. Place this snippet of code at the top of your config.php file.

!!! QUOTE !!!

// Determining platform
if (PHP_OS == "WIN32" || PHP_OS == "WINNT") {
define("BASE_PATH","c:\inetpub\wwwroot\nuke\html");
} else if (PHP_OS == "Linux") {
define("BASE_PATH","/usr/local/myapps");
} else {
// some other platform
}
define("INCLUDE_DIR",BASE_PATH."/include");

Place this code snippet in your PHP application's configuration file. This script takes global namespace $HTTP_*_VARS variables from input and, if they exist, registers them as a global variable so that scripts can use them. The first argument signifies where to pull the variable names from, and should be that of GET, POST, COOKIE, ENV, or SERVER.

!!! QUOTE !!!

if (!empty($_GET)) {
extract($_GET);
} else if (!empty($HTTP_GET_VARS)) {
extract($HTTP_GET_VARS);
}
if (!empty($_POST)) {
extract($_POST);
} else if (!empty($HTTP_POST_VARS)) {
extract($HTTP_POST_VARS);
}

Next, download the latest version of the Microsoft Data Access Components (MDAC) for your platform, especially if you use Microsoft Windows 9x/NT4. MDAC is available at Microsoft.com/data.

Next, install MySQL if you have not already done so. Configure the my.ini file using WinMySQLadmin, a GUI MySQL client that is contained in the MySQL installation. A sample my.ini file is provided. Be sure to set a password, even if you are just using MySQL for development or learning purposes. It's good to get in the habit of doing this. WinMySQLadmin doesn't do much, but it does this well.

After you have installed MySQL, you can now begin installing applications that will connect to MySQL, beginning with an excellent PHP application, phpMyAdmin. If you use MySQL seriously, or want to use it seriously, you will find phpMyAdmin to be indispensable in MySQL database administration.

phpMyAdmin is a browser-based database management tool written in PHP and was specifically designed to facilitate administration of MySQL over the Web. Currently, users can create and drop databases, create/alter/drop tables, search databases, import and export data, execute any SQL statement, and much more. This application can be downloaded here.

phpMyAdmin should be installed in a directory in your Web root that you create for all your PHP apps, such as C:inetpubwwwroot or D:www, etc. You can call the directory phpApps. In so doing, you will be able to create a DOC_ROOT path directive in php.ini for your PHP files for those applications which work best under this type of configuration in the Windows 2000 environment.


PHP Installation and Configuration on Windows Systems, Part III

Melvin Hendrix
USA Educated.Com

Finally, we can set up your Windows server. You have now installed MySQL, the Win32 MyODBC driver, PHP, and your PHP Web apps. Let begin configuring Internet Information Services (IIS) or the Personal Web Server. Version 4.0 or higher is best for each of these.

  • Step 1: You begin by opening IIS from the Microsoft Management Console, by navigating from Start-Setting-Control Panel-Administrative Tools- Internet Service Manager or through the Control Panel (Administrative Tools) in Windows Explorer. Highlight "Default Web Site", right-click and select "Properties". See the image below.

    Microsoft IIS permissions configuration

    There are just two panels that we need to set the properties on. The image is on the next page will help you identify them. The first is "Home Directory" or "Directory", and the other is "Documents". The Directory Tab should be open by default. If not, click on it. Here, you want to make sure that Execute Permissions are set to "Scripts and Executables" and "Application Protection" is set to Medium.

    Microsoft IIS permissions configuration

    Next, we need to map the PHP extension, so that the files can be read and executed in your Web server when called. To do this, click on the "Configuration" button on the right. The "App Mappings" panel should be pre-selected. Click "Add".

    Then, click "Browse" to navigate to C:php directory and select the php.exe executable, or, now that you know, just type it in. In the box beneath it, type .php. Make sure that "All Verbs" is selected and that "Script engine" is checked. In the Extension box, type the file name extension you want associated with PHP scripts. Leave 'Method exclusions' blank, and check the Script engine checkbox. You may also like to check the 'check that file exists' box - for a small performance penalty, IIS (or PWS) will check that the script file exists and sort out authentication before firing up PHP. This means that you will get sensible 404 style error messages instead of CGI errors complaining that PHP did not output any data.

    For each extension you want associated with PHP scripts, you must start over from the previous step. Common extensions are .php and .phtml, although .php3 may be required for legacy applications. All will be linked to the same PHP executable, however. Click "OK", and you have completed the extension mapping.

    Now, let's test our PHP connectivity. Open your favorite text or html editor and create a text file with the following tags

    !!! QUOTE !!!

    phpinfo() is a PHP function which outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment, the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.

    Save this file as phptest.php in C:INETPUBWWWROOT (or your IIS Web Root Folder). Open your browser and type http://localhost/phptest.php in the address bar, click Go to see if you see output like the screen below to make sure PHP in configured and running properly.

    IIS PHP Mapping Configuration Test

    If the source code appears in the browser and not the output we are expecting, then PHP has not been properly installed or IIS does not recognizes PHP files, please make sure you have followed the instructions properly.

  • Step 2: For each of the PHP Web applications that you have installed, you must create a virtual directory. Once again, highlight "Default Web Site", right-click, select "New | Virtual Directory", and follow instructions from the IIS Virtual Directory Creation Wizard. Basically, you are going to give your virtual directory a name and set the path to its directory.
  • Step 3: Once the virtual directory has been created, you will highlight the directory, right-click to "Properties" where the "Virtual Directory" panel will be pre-selected. Here, you will make sure that the Directory has read permission only, that the Execute Permissions are set as "Scripts and Executables" and "Application Protection" is set to Medium. Then, click on the "Documents" tab. Make sure that the "Enable Default Document" is checked. Remove all file names in the dialogue box, and add "index.php". Click OK. Repeat these steps for each virtual directory that you wish to create.
  • Microsoft IIS permissions configuration

  • Step 4: Once you have created your virtual directories, go to your WWW root directory. Here, you want to highlight one or more of the directories that you have designated as virtual so that we can set access permissions on them. Those users who are familiar with CHMOD in UNIX will recognize this step as similar though different. It amounts to the same thing, however.

    IIS permissions configuration

    There is only one Tab that we need to configure, and that's the "Security" tab. Click on the tab to open the panel, and see if the IUSR_YOURCOMPUTERNAME user (Internet Guest Account) is there. If not, please add it by clicking on the "ADD" button, and scrolling down to select it in the dialogue box. Once it has been added, give it "Read & Execute, List Folder Contents, and Read" permissions. Although it's not checked in the image above, also select "Write" for the Internet Guest Account as well. The Administrator account has all the Permission's enabled. If this is not true, then just click on the "Full Control" checkbox and all the others will be checked. Click OK and you are done.

  • Step 5: While each step is important to implement properly, this next step is the most important, ultimately, because it involves the configuration of your PHP Web application. If you have configured the other components successfully, then your success in configuring your PHP app is greatly enhanced and you should be able to get your application up and running in a very short period of time.
  • Step 6: Reboot. Windows loves to reboot. Keep the system happy.
  • Step 7: Test your connectivity. To test the connectivity of MySQL from your browser, create a PHP file in one of your PHP virtual directories and name it "ConnectTest.php"; run it from the root directory that contains the config.php file for your application. Most applications have this file, but if yours does not, make the necessary changes to this script to permit a test of your PHP/MySQL interface.
  • !!! QUOTE !!!

    require_once("config.php"); 
    $dbcheck = mysql_connect("$dbhost", "$dbuname", "$dbpass");
    if (!$dbcheck) {
    die("

    Connection Test Script was unable to connect to MySQL server!

    ");
    }else{
    echo "

    Connection Test Script connected to your MySQL server successfully!

    ";
    }
    mysql_close($dbcheck);

    PHP References

    Congratulations! This completes our exploration of PHP installations on Windows platforms. Hopefully, you learned something about making PHP work for you, and that it will help more Windows developers in discovering the fantastic capability of PHP.


Back to Main


[ Back to Developers Corner | Sections Index ]



  ChatBox II
smartvicky >  
sailwell >  hi
sailwell >  any body in?
sailwell >  i have instalation problem
sailwell >  any one help me
duke-leto >  kiril are you on here?
santeriablooms29 >  hello good day....



Click here to open the chatbox...
0 people chatting right now.