Cara menggunakan php configure command

This section contains notes and hints specific to getting PHP running from the command line for Windows.

Note:

You should read the manual installation steps first!

Getting PHP to run from the command line can be performed without making any changes to Windows.

C:\php\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3

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.

    Note:

    Both PATH and PATHEXT are important pre-existing system variables in Windows, and care should be taken to not overwrite either variable, only to add to them.

  • Append the location of the PHP executable (php.exe, php-win.exe or php-cli.exe depending upon your PHP version and display preferences) to the PATH environment variable. Read more about how to add your PHP directory to PATH in the .

  • Append the .PHP extension to the PATHEXT environment variable. This can be done at the same time as amending the PATH environment variable. Follow the same steps as described in the but amend the PATHEXT environment variable rather than the PATH environment variable.

    Note:

    The position in which you place the .PHP will determine which script or program is executed when there are matching filenames. For example, placing .PHP before

    ftype phpfile="C:\php\php.exe" -f "%1" -- %~2
    
    0 will cause your script to run, rather than the batch file, if there is a batch file with the same name.

  • Associate the .PHP extension with a file type. This is done by running the following command:

  • Associate the

    ftype phpfile="C:\php\php.exe" -f "%1" -- %~2
    
    2 file type with the appropriate PHP executable. This is done by running the following command:

    ftype phpfile="C:\php\php.exe" -f "%1" -- %~2
    

Following these steps will allow PHP scripts to be run from any directory without the need to type the PHP executable or the .PHP extension and all parameters will be supplied to the script for processing.

The example below details some of the registry changes that can be made manually.

Example #1 Registry changes

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"

With these changes the same command can be written as:

"C:\PHP Scripts\script" -arg1 -arg2 -arg3

or, if your
ftype phpfile="C:\php\php.exe" -f "%1" -- %~2
4 path is in the PATH environment variable:

Note:

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:

This posting is not a php-only problem, but hopefully will save someone a few hours of headaches.  Running on MacOS (although this could happen on any *nix I suppose), I was unable to get the script to execute without specifically envoking php from the command line:

[macg4:valencia/jobs] tim% test.php
./test.php: Command not found.

However, it worked just fine when php was envoked on the command line:

[macg4:valencia/jobs] tim% php test.php
Well, here we are...  Now what?

Was file access mode set for executable?  Yup.

[macg4:valencia/jobs] tim% ls -l
total 16
-rwxr-xr-x  1 tim  staff   242 Feb 24 17:23 test.php

And you did, of course, remember to add the php command as the first line of your script, yeah?  Of course.

#!/usr/bin/php

So why dudn't it work?  Well, like I said... on a Mac.... but I also occasionally edit the files on my Windows portable (i.e. when I'm travelling and don't have my trusty Mac available)...  Using, say, WordPad on Windows... and BBEdit on the Mac...

Aaahhh... in BBEdit check how the file is being saved!  Mac?  Unix?  or Dos?  Bingo.  It had been saved as Dos format.  Change it to Unix:

[macg4:valencia/jobs] tim% test.php
./test.php: Command not found.
0

[macg4:valencia/jobs] tim% test.php
./test.php: Command not found.
1

Apakah kegunaan perintah php V yang dijalankan di command prompt?

Perintah -v sendiri berfungsi untuk menampilkan versi PHP. Jika terlihat versi PHP seperti tampilan di atas, maka berarti file php.exe sudah bisa diakses secara global.

Apa itu command line php?

PHP CLI (Command Line Interface) merupakan PHP yang berjalan di Command Line. PHP CLI memungkinkan kita membangun aplikasi shell dengan PHP. PHP CLI pertama kali diknalkan pada PHP versi 4.2.0 sebagai percobaan (eksperimental). Salah satu contoh aplikasi shell yang berjalan di Command Line adalah Composer.

Langkah langkah Instalasi php?

Cara Instal PHP mengunakan XAMPP.
Siapkan file program file executable Installer Windows berbentuk ektensi .exe, agar mudah kalian bisa melakukan download di halaman sourceforge.net atau jika kesulitan bisa klik langsung kesini pilih versi 8 yang terbaru. ... .
Menentukan folder program installer..

Dimana letak file php ini?

Dapat kita ketahui bersama, bahwa lokasi direktori file php.ini telah ditemukan yaitu di c:\xampp\php\php.ini, maka selanjutnya adalah membuka file tersebut menggunakan text editor.