mirror of
https://github.com/php/doc-en.git
synced 2026-03-23 23:32:18 +01:00
This moves things around to make it more binary-install-forward like the Unix/macOS documentation, and generally cleans it all up to read better.
210 lines
6.1 KiB
XML
210 lines
6.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 xml:id="install.windows.commandline" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>Running PHP on the command line on Windows systems</title>
|
|
<para>
|
|
This section contains notes and hints specific to getting PHP running
|
|
from the command line for Windows.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Read the <link linkend="install.windows.manual">manual
|
|
installation steps</link> first!
|
|
</para>
|
|
</note>
|
|
<para>
|
|
Getting PHP to run from the command line can be performed without making
|
|
any changes to Windows.
|
|
<screen>
|
|
<![CDATA[
|
|
C:\php\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
|
|
<para>
|
|
But there are some easy steps that can be followed to make this simpler.
|
|
Some of these steps should already have been taken, but are repeated here
|
|
to be able to provide a complete step-by-step sequence.
|
|
|
|
<itemizedlist>
|
|
<note>
|
|
<para>
|
|
Both <envar>PATH</envar> and <envar>PATHEXT</envar> are important
|
|
pre-existing system variables in Windows,
|
|
and care should be taken to not overwrite either variable,
|
|
only to add to them.
|
|
</para>
|
|
</note>
|
|
|
|
<listitem>
|
|
<para>
|
|
Append the location of the PHP executable (<filename>php.exe</filename>,
|
|
<filename>php-win.exe</filename> or <filename>php-cli.exe</filename>
|
|
depending upon the PHP version and display preferences) to the
|
|
<envar>PATH</envar> environment variable. Read more about how to
|
|
add the appropriate directory to <envar>PATH</envar> in the <link
|
|
linkend="faq.installation.addtopath">corresponding FAQ entry</link>.
|
|
</para>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<para>
|
|
Append the <literal>.PHP</literal> extension to the
|
|
<varname>PATHEXT</varname> environment variable. This can be done
|
|
at the same time as amending the <envar>PATH</envar> environment
|
|
variable. Follow the same steps as described in the <link
|
|
linkend="faq.installation.addtopath">FAQ</link> but amend the
|
|
<varname>PATHEXT</varname> environment variable rather than the
|
|
<envar>PATH</envar> environment variable.
|
|
<note>
|
|
<para>
|
|
The position in which the <literal>.PHP</literal> is placed will
|
|
determine which script or program is executed when there are matching
|
|
filenames. For example, placing <literal>.PHP</literal> before
|
|
<literal>.BAT</literal> will cause the script to run, rather than
|
|
the batch file, if there is a batch file with the same name.
|
|
</para>
|
|
</note>
|
|
</para>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<para>
|
|
Associate the <literal>.PHP</literal> extension with a file type. This
|
|
is done by running the following command:
|
|
<screen>
|
|
<![CDATA[
|
|
assoc .php=phpfile
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</listitem>
|
|
|
|
<listitem>
|
|
<para>
|
|
Associate the <literal>phpfile</literal> file type with the appropriate
|
|
PHP executable. This is done by running the following command:
|
|
<screen>
|
|
<![CDATA[
|
|
ftype phpfile="C:\php\php.exe" -f "%1" -- %~2
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
</para>
|
|
|
|
<para>
|
|
Following these steps will allow PHP scripts to be run from any directory
|
|
without the need to type the PHP executable or the <literal>.PHP</literal>
|
|
extension and all parameters will be supplied to the script for processing.
|
|
</para>
|
|
|
|
<para>
|
|
The example below details some of the registry changes that can be made manually.
|
|
<example>
|
|
<title>Registry changes</title>
|
|
<screen>
|
|
<![CDATA[
|
|
Windows Registry Editor Version 5.00
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.php]
|
|
@="phpfile"
|
|
"Content Type"="application/php"
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile]
|
|
@="PHP Script"
|
|
"EditFlags"=dword:00000000
|
|
"BrowserFlags"=dword:00000008
|
|
"AlwaysShowExt"=""
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\DefaultIcon]
|
|
@="C:\\php\\php-win.exe,0"
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell]
|
|
@="Open"
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open]
|
|
@="&Open"
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open\command]
|
|
@="\"C:\\php\\php.exe\" -f \"%1\" -- %~2"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
With these changes the same command can be written as:
|
|
<screen>
|
|
<![CDATA[
|
|
"C:\PHP Scripts\script" -arg1 -arg2 -arg3
|
|
]]>
|
|
</screen>
|
|
or, if the <literal>"C:\PHP Scripts"</literal> directory is in the
|
|
<envar>PATH</envar> environment variable:
|
|
<screen>
|
|
<![CDATA[
|
|
script -arg1 -arg2 -arg3
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
|
|
<note>
|
|
<para>
|
|
There is a small problem when intending to use this technique to run
|
|
PHP scripts as a command line filter, like the example below:
|
|
<screen>
|
|
<![CDATA[
|
|
dir | "C:\PHP Scripts\script" -arg1 -arg2 -arg3
|
|
]]>
|
|
</screen>
|
|
or
|
|
<screen>
|
|
<![CDATA[
|
|
dir | script -arg1 -arg2 -arg3
|
|
]]>
|
|
</screen>
|
|
The script may simply hang and nothing is output.
|
|
To get this operational, another registry change needs to be made:
|
|
<screen>
|
|
<![CDATA[
|
|
Windows Registry Editor Version 5.00
|
|
|
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer]
|
|
"InheritConsoleHandles"=dword:00000001
|
|
]]>
|
|
</screen>
|
|
Further information regarding this issue can be found in this <link
|
|
xlink:href="http://support.microsoft.com/default.aspx?scid=kb;en-us;321788">Microsoft
|
|
Knowledgebase Article : 321788</link>.
|
|
As of Windows 10, this setting seems to be reversed, making the default install of
|
|
Windows 10 support inherited console handles automatically. This <link
|
|
xlink:href="https://social.msdn.microsoft.com/Forums/en-US/f19d740d-21c8-4dc2-a9ab-d5c0527e932b/nasty-file-association-regression-bug-in-windows-10-console?forum=windowssdk">
|
|
Microsoft forum post</link> provides the explanation.
|
|
</para>
|
|
</note>
|
|
</sect1>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|