Home > Backend Development > PHP Tutorial > How Do I Run PHP Scripts from the Windows Command Line Using WAMPServer?

How Do I Run PHP Scripts from the Windows Command Line Using WAMPServer?

Patricia Arquette
Release: 2024-12-20 10:54:10
Original
373 people have browsed it

How Do I Run PHP Scripts from the Windows Command Line Using WAMPServer?

Running PHP on Windows Command Line in WAMPServer

If you're new to PHP and wish to execute it from the command line, WAMPServer can assist you. However, configuring the system variables to the PHP folder may not always provide the desired outcome. Here's a comprehensive guide to help you resolve this issue:

Identifying the PHP CLI

The PHP CLI (Command Line Interface) is known as php.exe and resides in the following path:

c:\wamp\bin\php\phpx.y.z\php.exe
Copy after login

(where x and y represent the version numbers of your installed PHP)

Creating a PHP Script

To write PHP scripts for execution from the command line:

  1. Create a batch file (e.g., phppath.cmd) with the following content:
PATH=%PATH%;c:\wamp\bin\php\phpx.y.z
php -v
Copy after login

(Replace x.y.z with your PHP version)

  1. Save the file to a directory included in your PATH, allowing you to run it from any location.

Executing the Script

  1. Navigate to the desired source folder in a command window.
  2. Run the following command:
>phppath
Copy after login
  1. Subsequently, execute the script:
php your_script.php
Copy after login

This method should provide you with the desired output.

Additional Configuration

For enhanced functionality, consider the following additional configuration:

  1. Configuring PEAR (if available)
set PHP_PEAR_SYSCONF_DIR=%baseWamp%\bin\php\phpx.y.z
set PHP_PEAR_INSTALL_DIR=%baseWamp%\bin\php\phpx.y.z\pear
set PHP_PEAR_DOC_DIR=%baseWamp%\bin\php\phpx.y.z\docs
set PHP_PEAR_BIN_DIR=%baseWamp%\bin\php\phpx.y.z
set PHP_PEAR_DATA_DIR=%baseWamp%\bin\php\phpx.y.z\data
set PHP_PEAR_PHP_BIN=%baseWamp%\bin\php\phpx.y.z\php.exe
set PHP_PEAR_TEST_DIR=%baseWamp%\bin\php\phpx.y.z\tests
Copy after login
  1. Integrating Composer (if installed)
set COMPOSER_HOME=%baseWamp%\composer
set COMPOSER_CACHE_DIR=%baseWamp%\composer\cache
PATH=%PATH%;%baseWamp%\composer
Copy after login

This enhanced configuration allows you to utilize PEAR and Composer functionalities, expanding your PHP development capabilities.

In summary, understanding the PHP CLI location and utilizing batch files for script execution ensures a seamless PHP experience from the Windows command line in WAMPServer.

The above is the detailed content of How Do I Run PHP Scripts from the Windows Command Line Using WAMPServer?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template