Install PHP

Updated at:
Copy as MD

Install PHP on Windows, Linux, or macOS before using the Alibaba Cloud PHP SDK.

Windows

  1. Go to the PHP for Windows website, select a version (for example, PHP 8.3.8), and download the x64 Thread Safe ZIP file.

  2. Extract the ZIP file and add PHP to your system PATH.

    1. Right-click This PC and select Properties.

    2. Click Advanced system settings.

    3. On the Advanced tab, click Environment Variables.

    4. Under System variables, select Path and click Edit.

    5. Click New and add the PHP installation directory (for example, D:\php) and the PHP extension directory (for example, D:\php\ext).

  3. Configure php.ini.

    In the extracted folder, rename php.ini-development to php.ini. This file controls PHP interpreter behavior and is suitable for development environments.

  4. Verify the installation. Open Command Prompt (press Win+R, type cmd, and press Enter), then run php -v. A successful installation outputs something similar to:

    PHP 8.3.8 (cli) (built: Jun  4 2024 18:52:30) (ZTS Visual C++ 2019 x64)
    Copyright (c) The PHP Group
    Zend Engine v4.3.8, Copyright (c) Zend Technologies

Linux

  1. Install PHP using your distribution's package manager:

    • Alibaba Cloud Linux/CentOS

      sudo yum install epel-release
      sudo yum install php
      
    • Ubuntu/Debian

      sudo apt update
      sudo apt install -y php
      
  2. Verify the installation.

    Run php -v. A successful installation outputs something similar to:

    PHP 8.4.10 (cli) (built: Jul  3 2025 12:41:53) (NTS)
    Copyright (c) The PHP Group

macOS

On macOS, use Homebrew to install PHP.

Note

If you have network issues with Homebrew or PHP, use a mainland China mirror. For example, use the University of Science and Technology of China (USTC) open source mirror:

Set the Homebrew installation source to the USTC mirror

Note

Configure the Homebrew installation source by setting environment variables. This also speeds up downloads when you install Homebrew for the first time.

export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
brew update
  1. Install the latest version of PHP:

    brew install php
    
  2. Verify the installation:

    php -v
    

Next steps

Composer is the standard dependency manager for PHP projects. To install and configure it for use with the Alibaba Cloud PHP SDK, see Install and use Composer.