0

I need to run a php script from the command line. The problem is, this script will be in a different location on different PCs.

So I want to be able to enter something like this:

php myscript.php

where myscript.php will be in a folder which is in the windows path, but not in the current folder.

Is it possible to do something like this?

1 Answer 1

1

Please refer to this link in the php manual.

http://php.net/manual/en/install.windows.commandline.php

On any pc you have to setup the PATH and PATHEXT variable.

  1. 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 corresponding FAQ entry.
  2. 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 FAQ but amend the PATHEXT environment variable rather than the PATH environment variable.
  3. Associate the .PHP extension with a file type. This is done by running the following command: assoc .php=phpfile
  4. Associate the phpfile file type with the appropriate PHP executable. This is done by running the following command: ftype phpfile="C:\PHP5\php.exe" -f "%1" -- %~2

This will allow your script to run as normal shell command, like a batch file.

You will run it as :

myscript.php

and not

php myscript.php
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.