PHP PORTABLE IDE: PHP extensions

Revision as of 11:31, 2 December 2010 by Ric (talk | contribs) (New page: {{Uc nav PHP PORTABLE IDE}} '''''PHP configuration file and extensions''''' Previous three pages covered creating a simple portable self-contained PHP IDE. It avoided loading PHP extensio...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

 

MPG UniCenter

Uniform Server Portable PHP IDE.

PHP configuration file and extensions

Previous three pages covered creating a simple portable self-contained PHP IDE. It avoided loading PHP extensions and use of a configuration file however the structure was put into place to provide this functionality.

Extension/s you use are dictated by the application you are designing.

This page covers enabling extensions and shows how to check the correct PHP configuration file is being used.

PHP configuration file - php_cli_ide.ini

We currently have a configuration file located in folder C:\us_portable_ide\unicode\php named php_cli_ide.ini with the following content:

[PHP]
;extension=php_curl.dll
;extension=php_mysql.dll
;extension=php_openssl.dll
;extension=php_winbinder.dll
;extension=php_gd2.dll

extension_dir = "./extensions"
;error_reporting = E_ALL | E_STRICT
error_reporting = E_ALL 
date.timezone = "Europe/London"


  • All extensions have been commented out - disabled.
  • Folder path to extensions is defined. "./extensions"
  • Error reporting enabled - error_reporting = E_ALL
  • A time zone is set. - "Europe/London"

Content of the above file is not unique. To ensure we are using the correct file while configuring our development environment add a unique line as shown.

[PHP]
extension=fred.dll
;extension=php_curl.dll
;extension=php_mysql.dll
;extension=php_openssl.dll
;extension=php_winbinder.dll
;extension=php_gd2.dll

extension_dir = "./extensions"
;error_reporting = E_ALL | E_STRICT
error_reporting = E_ALL 
date.timezone = "Europe/London"


  • Edit file C:\us_portable_ide\unicode\php\php_cli_ide.ini
  • Add line as shown. Save and close file
  • fred.dll Is unique. A error is produced when this configuration file is used.

Note: We will delete this line after testing.

Top

New NppExec command script

Currently our command script has the following content:

NPP_SAVE
cls
$(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH)

- Save current file
- Clear console window
- Run currently displayed PHP script

  • Parameter -n informs the PHP interpreter not to use a configuration file.
  • This needs to be replaced with parameter -c (use configuration) followed by full path to php_cli_ide.ini

Modified script shown below:

NPP_SAVE
cls
$(NPP_DIRECTORY)\php\php.exe -c $(NPP_DIRECTORY)\php\php_cli_ide.ini $(FULL_CURRENT_PATH)

- Save current file
- Clear console window
- Run currently displayed PHP script

Top

Update NppExec command script

First create a new test script named test3.php with the following content:

  • Save to folder C:\us_portable_ide\php_scripts
  • Press right arrow key. Check it runs with no errors
<?php
print "Test 3\n";
?>

Update command script

  • Press key F6 (Opens execute window)
  • (A) Edit line as shown
  • (B) Click OK saves and runs commands

 

Warning produced in console window confirming correct configuration file picked up.

C:\us_portable_ide\unicode\php\php.exe -c C:\us_portable_ide\unicode\php\php_cli_ide.ini C:\us_portable_ide\php_scripts\test3.php
Process started >>>
Test 3
PHP Warning:  PHP Startup: Unable to load dynamic library './extensions\fred.dll' - The specified module could not be found.
 in Unknown on line 0
<<< Process finished.
================ READY ================

Update config file

Having confirmed correct configuration file is being picked test line can be removed.

  • Edit file C:\us_portable_ide\unicode\php\php_cli_ide.ini
  • Remove line: extension=fred.dll save file
  • With test3.php displayed run command script (press right arrow key)

Console window displays:

C:\us_portable_ide\unicode\php\php.exe -c C:\us_portable_ide\unicode\php\php_cli_ide.ini C:\us_portable_ide\php_scripts\test3.php
Process started >>>
Test 3
<<< Process finished.
================ READY ================

Top

PHP INFO

An alternative method of determining configuration file loaded by PHP interpreter is to use the inbuilt function phpinfo(). It generates a long list of information a few lines from the top you will find all configuration files loaded.

  • To display PHP information edit script test3.php as shown:
  • Press right arrow key

A long list of information is displayed in console window.

Navigate to top, you will see something similar to this:

<?php
print "Test 3\n";
phpinfo();
?>
C:\us_portable_ide\unicode\php\php.exe -c C:\us_portable_ide\unicode\php\php_cli_ide.ini C:\us_portable_ide\php_scripts\test3.php
Process started >>>
Test 3
phpinfo()
PHP Version => 5.3.3

System => Windows NT MPG2 5.1 build 2600 (Windows XP Home Edition Service Pack 3) i586
Build Date => Jul 21 2010 20:25:38
Compiler => MSVC9 (Visual C++ 2008)
Architecture => x86
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => C:\WINDOWS
Loaded Configuration File => C:\us_portable_ide\unicode\php\php_cli_ide.ini   <----- Note path to config
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)

Important point to note is the configuration file loaded.

Top

Enabling extensions

This section covers enabling PHP extensions for this test we will enable only the WinBinder extension.

For testing use function wb_exec() one of WinBinders many functions.

Enable WinBinder extension

Enabling an extension is nothing more than removing the semicolon
from the appropriate line in the configuration file.

  • Edit file C:\us_portable_ide\unicode\php\php_cli_ide.ini
  • Remove semicolon from from line extension=php_winbinder.dll
  • Save and close file

When PHP CLI is run the WinBinder extension is loaded and its functions
accessible see example below.

[PHP]
;extension=php_curl.dll
;extension=php_mysql.dll
;extension=php_openssl.dll
extension=php_winbinder.dll
;extension=php_gd2.dll

extension_dir = "./extensions"
;error_reporting = E_ALL | E_STRICT
error_reporting = E_ALL 
date.timezone = "Europe/London"
short_open_tag = Off

Double clicking PHP file problem

Windows has a pre-configured set of file associations for example .exe, .bat and .html when a file with one of these file extensions is double clicked its associated executable program runs that file.

  • If we have a file named redirect.html double clicking it will run a default browser and display that page.

Problem

Similarly if a file has a file extension .php double clicking on it will run its associated application.

  • This application is generally a PHP editor such as Dreamweaver.

To run a file for example index.php on a development web serer double clicking on it will not produce the desired results.

Solution

A solution is to use an intermediary HTML script. We know when double clicked this will open in a default browser. Use this HTML script to redirect browser to appropriate PHP page (index.php) on development server.

Redirect HTML page

  • Using Nptepad++ create a new text file with content shown on right.
  • Save to folder C:\us_portable_ide\php_scripts with name redirect.html

Test

  • Navigate to folder C:\us_portable_ide\php_scripts
  • Double click on file redirect.html

Assuming a local web-server is not running browser will open displaying “Unable to connect”.

Note: Browser address bar displays http://localhost/index.php


<html>
<head>
<meta http-equiv="refresh" content="1;url=http://localhost/index.php">
<title>Uniform Server Redirect</title>
</head>
<body>
</body>
</html>


If a local web-server is running and it contains index.php that page is displayed in the browser.

Top

PHP CLI redirect script

Using above page we can write a small test script for testing the WinBinder extension and function wb_exec().

  • Using Notepad++ create a new file content shown on right
  • Save to folder C:\us_portable_ide\php_scripts with name redirect.php

Run script

  • Press right arrow key
<?php
print "Test redirect\n";
chdir(dirname(__FILE__));       // Change wd to this files location
$a=getcwd();                    // Get absolte path
wb_exec($a.'\redirect.html');   // Absolute path to page
?>

Again assuming a local web-server not running browser will open displaying Unable to connect

If a web-server is running and contains index.php in its root folder that page is displayed.

Top

Summary

The above has shown how to enable PHP extensions and check correct PHP configuration file is being picked up.

Redirection example is a precursor to adding more automation to our portable PHP IDE.

Next page looks at running a page displayed in Notepad++ on a local web server using a run menu item.

Top