Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 8232

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Command Line PHP on Microsoft Windows</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="install.windows.extensions.html">Installation of extensions on Windows</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="install.cloud.html">Installation on Cloud Computing platforms</a></div>
 <div class="up"><a href="install.windows.html">Installation on Windows systems</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="install.windows.commandline" class="sect1">
    <h2 class="title">Command Line PHP on Microsoft Windows</h2>
    <p class="para">
     This section contains notes and hints specific to getting PHP running
     from the command line for Windows.
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      You should read the <a href="install.windows.manual.html" class="link">manual
      installation steps</a> first!
     </p>
    </p></blockquote>
    <p class="para">
     Getting PHP to run from the command line can be performed without making
     any changes to Windows.
     <div class="example-contents screen">
<div class="cdata"><pre>
C:\PHP5\php.exe -f &quot;C:\PHP Scripts\script.php&quot; -- -arg1 -arg2 -arg3
</pre></div>     
     </div>
    </p>

    <p class="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.
      
     
     <ul class="itemizedlist">
      
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Both <var class="varname"><var class="varname">PATH</var></var> and <var class="varname"><var class="varname">PATHEXT</var></var> are important pre-existing system variables in Windows, and care should be taken to not overwrite either variable, only to add to them.
       </p>
      </p></blockquote>

      <li class="listitem">
       <p class="para">
        Append the location of the PHP executable (<var class="filename">php.exe</var>,
        <var class="filename">php-win.exe</var> or <var class="filename">php-cli.exe</var>
        depending upon your PHP version and display preferences) to the
        <var class="varname"><var class="varname">PATH</var></var> environment variable. Read more about how to
        add your PHP directory to <var class="varname"><var class="varname">PATH</var></var> in the <a href="faq.installation.html#faq.installation.addtopath" class="link">corresponding FAQ entry</a>.
       </p>
      </li>

      <li class="listitem">
       <p class="para">
        Append the <em>.PHP</em> extension to the
        <var class="varname"><var class="varname">PATHEXT</var></var> environment variable. This can be done
        at the same time as amending the <var class="varname"><var class="varname">PATH</var></var> environment
        variable. Follow the same steps as described in the <a href="faq.installation.html#faq.installation.addtopath" class="link">FAQ</a> but amend the
        <var class="varname"><var class="varname">PATHEXT</var></var> environment variable rather than the
        <var class="varname"><var class="varname">PATH</var></var> environment variable.
        <blockquote class="note"><p><strong class="note">Note</strong>: 
         <p class="para">
          The position in which you place the <em>.PHP</em> will
          determine which script or program is executed when there are matching
          filenames. For example, placing <em>.PHP</em> before
          <em>.BAT</em> will cause your script to run, rather than
          the batch file, if there is a batch file with the same name.
         </p>
        </p></blockquote>
       </p>
      </li>

      <li class="listitem">
       <p class="para">
        Associate the <em>.PHP</em> extension with a file type. This
        is done by running the following command:
        <div class="example-contents screen">
<div class="cdata"><pre>
assoc .php=phpfile
</pre></div>     
        </div>
       </p>
      </li>

      <li class="listitem">
       <p class="para">
        Associate the <em>phpfile</em> file type with the appropriate
        PHP executable. This is done by running the following command:
        <div class="example-contents screen">
<div class="cdata"><pre>
ftype phpfile=&quot;C:\PHP5\php.exe&quot; -f &quot;%1&quot; -- %~2
</pre></div>     
        </div>
       </p>
      </li>

     </ul>
    </p>

    <p class="para">
     Following these steps will allow PHP scripts to be run from any directory
     without the need to type the PHP executable or the <em>.PHP</em>
     extension and all parameters will be supplied to the script for processing.
    </p>

    <p class="para">
     The example below details some of the registry changes that can be made manually.
     <div class="example" id="example-59">
      <p><strong>Example #1 Registry changes</strong></p>
      <div class="example-contents screen">
<div class="cdata"><pre>
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.php]
@=&quot;phpfile&quot;
&quot;Content Type&quot;=&quot;application/php&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile]
@=&quot;PHP Script&quot;
&quot;EditFlags&quot;=dword:00000000
&quot;BrowserFlags&quot;=dword:00000008
&quot;AlwaysShowExt&quot;=&quot;&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\DefaultIcon]
@=&quot;C:\\PHP5\\php-win.exe,0&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell]
@=&quot;Open&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open]
@=&quot;&amp;Open&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open\command]
@=&quot;\&quot;C:\\PHP5\\php.exe\&quot; -f \&quot;%1\&quot; -- %~2&quot;
</pre></div>
      </div>
     </div>
    </p>

    <p class="para">
     With these changes the same command can be written as:
     <div class="example-contents screen">
<div class="cdata"><pre>
&quot;C:\PHP Scripts\script&quot; -arg1 -arg2 -arg3
</pre></div>
     </div>
     or, if your <em>&quot;C:\PHP Scripts&quot;</em> path is in the
     <em>PATH</em> environment variable:
     <div class="example-contents screen">
<div class="cdata"><pre>
script -arg1 -arg2 -arg3
</pre></div>
     </div>
    </p>

    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      There is a small problem if you intend to use this technique and use your
      PHP scripts as a command line filter, like the example below:
      <div class="example-contents screen">
<div class="cdata"><pre>
dir | &quot;C:\PHP Scripts\script&quot; -arg1 -arg2 -arg3
</pre></div>
      </div>
      or
      <div class="example-contents screen">
<div class="cdata"><pre>
dir | script -arg1 -arg2 -arg3
</pre></div>
      </div>
      You may find that the script simply hangs and nothing is output.
      To get this operational, you need to make another registry change.
      <div class="example-contents screen">
<div class="cdata"><pre>
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer]
&quot;InheritConsoleHandles&quot;=dword:00000001
</pre></div>
      </div>
      Further information regarding this issue can be found in this <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;321788" class="link external">&raquo;&nbsp;Microsoft
      Knowledgebase Article : 321788</a>.
     </p>
    </p></blockquote>
   </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="install.windows.extensions.html">Installation of extensions on Windows</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="install.cloud.html">Installation on Cloud Computing platforms</a></div>
 <div class="up"><a href="install.windows.html">Installation on Windows systems</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>