https://wiki.uniformserver.com/index.php?title=PHP_PORTABLE_IDE:_PHP_extensions&feed=atom&action=historyPHP PORTABLE IDE: PHP extensions - Revision history2024-03-29T01:57:04ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=PHP_PORTABLE_IDE:_PHP_extensions&diff=4992&oldid=prevRic: 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...2010-12-02T11:31:34Z<p>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...</p>
<p><b>New page</b></p><div>{{Uc nav PHP PORTABLE IDE}}<br />
'''''PHP configuration file and extensions'''''<br />
<br />
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.<br />
<br />
Extension/s you use are dictated by the application you are designing.<br />
<br />
This page covers enabling extensions and shows how to check the correct PHP configuration file is being used.<br />
<br />
== PHP configuration file - php_cli_ide.ini ==<br />
<br />
We currently have a configuration file located in folder '''C:\us_portable_ide\unicode\php''' named '''php_cli_ide.ini''' with the following content:<br />
{|<br />
|-valign="top"<br />
|<br />
<pre><br />
[PHP]<br />
;extension=php_curl.dll<br />
;extension=php_mysql.dll<br />
;extension=php_openssl.dll<br />
;extension=php_winbinder.dll<br />
;extension=php_gd2.dll<br />
<br />
extension_dir = "./extensions"<br />
;error_reporting = E_ALL | E_STRICT<br />
error_reporting = E_ALL <br />
date.timezone = "Europe/London"<br />
</pre><br />
|<br />
<br><br />
* All extensions have been commented out - disabled. <br />
* Folder path to extensions is defined. "./extensions"<br />
* Error reporting enabled - error_reporting = E_ALL<br />
* A time zone is set. - "Europe/London"<br />
|}<br />
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. <br />
{|<br />
|-valign="top"<br />
|<br />
<pre><br />
[PHP]<br />
extension=fred.dll<br />
;extension=php_curl.dll<br />
;extension=php_mysql.dll<br />
;extension=php_openssl.dll<br />
;extension=php_winbinder.dll<br />
;extension=php_gd2.dll<br />
<br />
extension_dir = "./extensions"<br />
;error_reporting = E_ALL | E_STRICT<br />
error_reporting = E_ALL <br />
date.timezone = "Europe/London"<br />
</pre><br />
|<br />
<br><br />
* Edit file C:\us_portable_ide\unicode\php\'''php_cli_ide.ini'''<br />
* Add line as shown. Save and close file<br />
* '''fred.dll''' Is unique. A error is produced when this configuration file is used. <br />
'''''Note'':''' We will delete this line after testing.<br />
|}<br />
'''''[[#top | Top]]'''''<br />
=== New NppExec command script ===<br />
Currently our command script has the following content:<br />
{|<br />
|-<br />
|<br />
<pre><br />
NPP_SAVE<br />
cls<br />
$(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH)<br />
</pre><br />
|<br />
- Save current file<br>- Clear console window<br>- Run currently displayed PHP script<br />
|} <br />
<br />
* Parameter '''-n''' informs the PHP interpreter not to use a configuration file.<br />
* This needs to be replaced with parameter '''-c''' (use configuration) followed by full path to '''php_cli_ide.ini''' <br />
<br />
'''''Modified script shown below'':'''<br />
{|<br />
|-<br />
|<br />
<pre><br />
NPP_SAVE<br />
cls<br />
$(NPP_DIRECTORY)\php\php.exe -c $(NPP_DIRECTORY)\php\php_cli_ide.ini $(FULL_CURRENT_PATH)<br />
</pre><br />
|<br />
- Save current file<br>- Clear console window<br>- Run currently displayed PHP script<br />
|} <br />
'''''[[#top | Top]]'''''<br />
<br />
=== Update NppExec command script ===<br />
{|<br />
|-<br />
|<br />
First create a new test script named '''test3.php''' with the following content:<br />
* Save to folder C:\us_portable_ide\php_scripts<br />
* Press right arrow key. Check it runs with no errors <br />
|<br />
<pre><br />
<?php<br />
print "Test 3\n";<br />
?><br />
</pre><br />
|}<br />
<br />
{|<br />
|-valign="top"<br />
|<br />
'''Update command script'''<br />
* Press key '''F6''' (Opens execute window)<br />
* (A) Edit line as shown<br />
* (B) Click '''OK''' saves and runs commands <br />
|<br />
[[Image:Ide_php_cli_ini_1.gif]] <br />
|}<br />
Warning produced in console window confirming correct configuration file picked up.<br />
<pre><br />
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<br />
Process started >>><br />
Test 3<br />
PHP Warning: PHP Startup: Unable to load dynamic library './extensions\fred.dll' - The specified module could not be found.<br />
in Unknown on line 0<br />
<<< Process finished.<br />
================ READY ================<br />
</pre> <br />
'''Update config file'''<br />
<br />
Having confirmed correct configuration file is being picked test line can be removed.<br />
* Edit file C:\us_portable_ide\unicode\php\php_cli_ide.ini<br />
* Remove line: '''extension=fred.dll''' save file<br />
* With '''test3.php''' displayed run command script (press right arrow key)<br />
'''''Console window displays'':'''<br />
<pre><br />
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<br />
Process started >>><br />
Test 3<br />
<<< Process finished.<br />
================ READY ================<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
<br />
=== PHP INFO ===<br />
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.<br />
{|<br />
|-valign="top"<br />
|<br />
* To display PHP information edit script '''test3.php''' as shown:<br />
* Press '''right arrow''' key<br />
<br />
A long list of information is displayed in console window.<br />
<br />
Navigate to top, you will see something similar to this:<br />
|<br />
<pre><br />
<?php<br />
print "Test 3\n";<br />
phpinfo();<br />
?><br />
</pre><br />
|}<br />
<pre><br />
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<br />
Process started >>><br />
Test 3<br />
phpinfo()<br />
PHP Version => 5.3.3<br />
<br />
System => Windows NT MPG2 5.1 build 2600 (Windows XP Home Edition Service Pack 3) i586<br />
Build Date => Jul 21 2010 20:25:38<br />
Compiler => MSVC9 (Visual C++ 2008)<br />
Architecture => x86<br />
Server API => Command Line Interface<br />
Virtual Directory Support => enabled<br />
Configuration File (php.ini) Path => C:\WINDOWS<br />
Loaded Configuration File => C:\us_portable_ide\unicode\php\php_cli_ide.ini <----- Note path to config<br />
Scan this dir for additional .ini files => (none)<br />
Additional .ini files parsed => (none)<br />
</pre><br />
Important point to note is the configuration file loaded.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Enabling extensions ==<br />
This section covers enabling PHP extensions for this test we will enable only the WinBinder extension.<br />
<br />
For testing use function '''wb_exec()''' one of WinBinders many functions.<br />
<br />
=== Enable WinBinder extension ===<br />
{|<br />
|-<br />
|<br />
Enabling an extension is nothing more than removing the semicolon<br> from the appropriate line in the configuration file.<br />
<br />
* Edit file C:\us_portable_ide\unicode\php\'''php_cli_ide.ini'''<br />
* Remove semicolon from from line extension=php_winbinder.dll<br />
* Save and close file<br />
<br />
When PHP CLI is run the WinBinder extension is loaded and its functions <br>accessible see example below.<br />
|<br />
<pre><br />
[PHP]<br />
;extension=php_curl.dll<br />
;extension=php_mysql.dll<br />
;extension=php_openssl.dll<br />
extension=php_winbinder.dll<br />
;extension=php_gd2.dll<br />
<br />
extension_dir = "./extensions"<br />
;error_reporting = E_ALL | E_STRICT<br />
error_reporting = E_ALL <br />
date.timezone = "Europe/London"<br />
short_open_tag = Off<br />
</pre><br />
|}<br />
<br />
== Double clicking PHP file problem ==<br />
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.<br />
* If we have a file named '''redirect.html''' double clicking it will run a '''default browser''' and display that page.<br />
<br />
=== Problem ===<br />
<br />
Similarly if a file has a file extension '''.php''' double clicking on it will run its associated application.<br />
* This application is generally a '''PHP editor''' such as Dreamweaver.<br />
To run a file for example '''index.php''' on a development web serer double clicking on it will not produce the desired results.<br />
<br />
=== Solution ===<br />
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.<br />
==== Redirect HTML page ====<br />
{|<br />
|-valign="top"<br />
|<br />
*Using Nptepad++ create a new text file with content shown on right.<br />
* Save to folder C:\us_portable_ide\php_scripts with name '''redirect.html'''<br />
'''Test'''<br />
* Navigate to folder C:\us_portable_ide\'''php_scripts'''<br />
* Double click on file '''redirect.html'''<br />
Assuming a local web-server is not running browser will open displaying “Unable to connect”.<br />
<br />
'''''Note'':''' Browser address bar displays '''<nowiki>http://localhost/index.php</nowiki>''' <br />
|<br />
<pre><br />
<br />
<html><br />
<head><br />
<meta http-equiv="refresh" content="1;url=http://localhost/index.php"><br />
<title>Uniform Server Redirect</title><br />
</head><br />
<body><br />
</body><br />
</html><br />
<br />
<br />
</pre><br />
|}<br />
If a local web-server is running and it contains index.php that page is displayed in the browser.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
=== PHP CLI redirect script ===<br />
Using above page we can write a small test script for testing the WinBinder extension and function wb_exec(). <br />
{|<br />
|-<br />
|<br />
*Using Notepad++ create a new file content shown on right<br />
* Save to folder '''C:\us_portable_ide\php_scripts''' with name '''redirect.php'''<br />
Run script<br />
* Press '''right arrow''' key <br />
|<br />
<pre><br />
<?php<br />
print "Test redirect\n";<br />
chdir(dirname(__FILE__)); // Change wd to this files location<br />
$a=getcwd(); // Get absolte path<br />
wb_exec($a.'\redirect.html'); // Absolute path to page<br />
?><br />
</pre><br />
|}<br />
Again assuming a local web-server not running browser will open displaying '''Unable to connect'''<br />
<br />
If a web-server is running and contains index.php in its root folder that page is displayed.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
The above has shown how to enable PHP extensions and check correct PHP configuration file is being picked up.<br />
<br />
Redirection example is a precursor to adding more automation to our portable PHP IDE. <br />
<br />
[[PHP PORTABLE IDE: Run Menu | Next page]] looks at running a page displayed in Notepad++ on a local web server using a run menu item.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric