PHP is not an internal or external command

Question

Answers ( 1 )

    0
    2024-01-11T18:05:21+00:00

    This error message typically arises when trying to run PHP from the command line on a system where PHP is either not installed or its path is not included in the system's environment variables.

    Here are potential solutions:

    1. Install PHP: If PHP is not installed on your system, you need to install it. You can download PHP from the official PHP website and follow the installation instructions for your operating system.

    2. Add PHP to Your System Path:

      • Windows:
        • Locate your PHP installation folder (e.g., C:\php).
        • Right-click 'This PC' or 'My Computer' on your desktop or in File Explorer.
        • Select 'Properties' and then 'Advanced system settings'.
        • Click 'Environment Variables'. In the 'System variables' section, find the 'Path' variable and select it. Click 'Edit'.
        • Add the path to your PHP installation folder at the end of the list (e.g., ;C:\php).
        • Click 'OK' and restart any open command prompts.
      • Linux/Unix/MacOS:
        • Open a terminal.
        • Use a text editor to open your shell's profile script (e.g., ~/.bashrc, ~/.bash_profile, or ~/.zshrc).
        • Add a line to export the PHP path: export PATH="$PATH:/path/to/php".
        • Save the file and reload the profile (e.g., source ~/.bashrc).
    3. Verify PHP Installation:

      • After installation, you can verify it by opening a command prompt or terminal and typing php -v. This should display the PHP version if it's correctly installed and path is set.
    4. Check for Multiple PHP Versions: If you have multiple versions of PHP installed, ensure that the correct one is referenced in your system path.

    5. Restart Your System: Sometimes, a system restart is required for the changes to take effect.

    6. Check for Typos: Ensure that the command you are entering is correct and there are no typos.

    7. Run as Administrator: If you are on Windows, try running your command prompt as an administrator to avoid permission issues.

    Here's a basic example of how you might update the PATH in a Windows system using a batch file:

    @echo off
    SETX PATH "%PATH%;C:\php"
    

    Remember to replace C:\php with the actual path to your PHP installation. This script appends the PHP path to the existing system PATH variable.

Leave an answer